Skip to content

About

Detect QR and Bar codes on a Viam camera using Pyzbar and OpenCV

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Module qr-barcode-scanner

Detect and decode QR codes and 1D barcodes from a Viam camera using pyzbar and OpenCV.

QR code detections overlaid on a camera stream in the Viam app

Models

This module provides the following model(s):

Configure the service

Note

Before configuring the service you must create a machine and configure a camera on it.

  1. Navigate to the CONFIGURE tab of your machine in the Viam app.
  2. Click +, select Service, then search for qr-barcode-scanner.
  3. Select the viam-soleng:qr-barcode-scanner:pyzbar model and name the service.
  4. Set camera_name to 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.

System requirements

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.

Development

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 machine

Tagging 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.

Layout

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

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.py

Credentials come from an .env file next to the scripts; get the values from your machine's CONNECT tab in the Viam app.

Tutorial

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.

About

Detect QR and Bar codes on a Viam camera using Pyzbar and OpenCV

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages