DataMatrix, QR and barcodes on a Raspberry Pi: installation and speed
A Raspberry Pi is often installed right at the line or in the warehouse: a camera, a board, and codes are read without a separate computer. Below is what you need to read DataMatrix, QR and barcodes on a Raspberry Pi and other ARM boards, how to install the library with one command, and how long reading takes on a Raspberry Pi 4.
What is supported
| Board and OS | Supported |
|---|---|
| Raspberry Pi 3, 4, 5 and other ARM64 (aarch64) boards with Raspberry Pi OS Bookworm (Debian 12) or newer | yes |
| 32-bit Raspberry Pi OS (ARMv7, armhf) Bookworm or newer — Raspberry Pi 2, 3, 4, Zero 2 W | yes |
| Ubuntu 24.04 or newer on ARM | yes |
| Raspberry Pi OS Bullseye (Debian 11), Ubuntu 22.04 and older | no: glibc 2.36 or newer is required |
| Raspberry Pi 1 and the original Zero (ARMv6) | no |
ldd --version shows the glibc version, cat /etc/os-release the OS version. If glibc is older than 2.36, pip reports that no matching package exists: upgrade the OS or write to us and we will build for yours.
Installation
The PyPI packages are built for ARM64 and ARMv7 and include NEON kernels — nothing is compiled on the board. Python 3.9 or newer:
python3 -m venv ~/scanner
~/scanner/bin/pip install libscanner-unir # DataMatrix, QR, barcodes
# or libscanner-dmr — DataMatrix only
~/scanner/bin/unir --versionReading a code from Python:
import unir
result = unir.scan_file("label.jpg")
if result.ok:
print(result.codes[0].symbology_name, result.text) # text is bytes, GS keptOr with no code of your own, using the command-line tool: unir label.jpg. For C++, the Downloads section of your account has Linux ARM64 and ARMv7 archives with the library, headers and the tool.
For the first month the library works on the board without a license and without internet. After that a key is needed; for boards without network access the license can be activated through another computer, as described in the documentation.
Reading time on a Raspberry Pi 4
Raspberry Pi 4 Model B, unir 1.2.15 from PyPI, industrial camera frames, median per frame:
| Task | 1 thread | 4 threads |
|---|---|---|
| One DataMatrix code in a 5 MP frame (2416×2024) | 0.25 s | — |
| All 20 DataMatrix codes of an A4 sheet in a 5 MP frame | 6.2 s | 1.9 s |
| All codes of a sheet with EAN-13, SSCC and QR, 8.5 MP frame (3456×2458) | 3.3 s | — |
The takeaway: a Raspberry Pi 4 reads one code from a camera frame in a fraction of a second, while dozens of codes in a large frame take seconds. To go faster:
- Capture only what you need. A frame cropped to the area where codes appear reads noticeably faster: the work scales roughly with the area.
- Do not oversize the resolution. 2–3 pixels per code module is enough; how to calculate it is in the article on camera resolution.
- Set the symbologies. If the line has only DataMatrix, do not look for barcodes:
--sym dmorSettings.symbologies. - Limit time per frame. The
budget_mssetting (the--budget-msoption) stops the search at the deadline and returns what has been read, so a heavy frame does not break the line rhythm. - Use a more powerful board. A Raspberry Pi 5 is noticeably faster than a Pi 4 (we have not measured it yet); for dozens of codes per frame, use an x86 mini PC (on 8 x86 cores a 12 MP image with 16 codes reads in 0.45 s, see the article on multiple codes in one image).
Try it
Documentation: unir and dmr; packages: libscanner-unir and libscanner-dmr on PyPI. Test your own image without installing anything in the online decoder. Need a build for your board or OS? Write to us.
Chestny ZNAK is a trademark of CRPT LLC (ООО «Оператор-ЦРПТ»); GS1 is a trademark of GS1 AISBL. The product is not affiliated with or certified by their owners.