Detect and decode QR codes and 1D barcodes from a Viam camera using pyzbar and OpenCV.
This module provides the following model(s):
viam-soleng:qr-barcode-scanner:pyzbar— vision service returning one detection per decoded symbol, with the payload as the detection's class name.
Note
Before configuring the service you must create a machine and configure a camera on it.
- Navigate to the CONFIGURE tab of your machine in the Viam app.
- Click +, select Service, then search for
qr-barcode-scanner. - Select the
viam-soleng:qr-barcode-scanner:pyzbarmodel and name the service. - Set
camera_nameto the name of the camera you want to scan.
{
"camera_name": "orbbec-1",
"cooldown_period": 5
}camera_name is required — see the
model documentation for why, and for
the full attribute reference.
pyzbar loads the libzbar shared library at import time and it is not
available on PyPI. setup.sh installs it automatically on
Debian/Ubuntu (libzbar0) and macOS (brew install zbar). Install it yourself
on other platforms.
The module ships as a source tarball; the target machine builds its own virtualenv on first start.
./build.sh # produces dist/archive.tar.gz
viam module reload --part-id <your-part-id> # build, upload, and restart on a machineTagging a release (v1.2.3) triggers
.github/workflows/deploy.yml, which publishes
to the registry via viamrobotics/build-action.
It requires the viam_key_id and viam_key_value repository secrets.
| Path | Purpose |
|---|---|
src/main.py |
Module entrypoint |
src/models/qr_barcode_scanner.py |
The vision service implementation |
run.sh / setup.sh / build.sh |
Entrypoint, environment bootstrap, packaging |
examples/ |
Standalone scripts, not part of the module |
examples/ holds standalone scripts that talk to a machine over
the network rather than running as a module. They are not packaged into the
tarball.
| Script | Purpose |
|---|---|
process.py |
Poll the vision service and open the decoded URL in a browser |
script.py |
Show a live camera feed with detections drawn on it |
decode.py |
Decode a single image file from disk |
batch_upload.py |
Upload a directory of images to Viam data management |
python3 -m venv .venv && source .venv/bin/activate
pip install -r examples/requirements.txt
cp examples/.env.template examples/.env # then fill in your credentials
python examples/process.pyCredentials come from an .env file next to the scripts; get the values from
your machine's CONNECT tab in the Viam app.
The original walkthrough for this module is at
Use a QR code scanner.
It predates the rename and still refers to the joyce:vision:pyzbar model.