Follow step-by-step instructions in this tutorial: Use a QR code scanner.
This module implements the rdk vision API in a joyce:vision:pyzbar model.
With this model, you can manage a vision service to detect and decode QR codes.
To use this module, follow these instructions to add a module from the Viam Registry and select the joyce:vision:pyzbar model from the pyzbar module.
Note
Before configuring your sensor, you must create a machine.
- Navigate to the CONFIGURE tab of your robot’s page in the Viam app.
- Click on the + icon in the left-hand menu and select Service.
- Select the
visiontype, then select thepyzbarmodule. - Enter a name for your vision service and click Create.
Note
For more information, see Configure a Robot.
This project uses the Viam Python SDK to capture images from a Viam robot camera, detect QR codes in the image using Pyzbar, and display the results using OpenCV.
- Install dependencies using
pip install -r requirements.txt. - Configure environment variables using a
.envfile. - Run the script using
python script.py.
- Python 3.8 or higher installed on your system.
- A working Viam robot with a camera configured.
- Internet access to install required packages.
git clone <repository-url>
cd <repository-directory>Use a virtual environment to manage dependencies. You can create and activate one as follows:
On macOS/Linux:
python3 -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activateOnce the virtual environment is activated, install the required Python packages listed in requirements.txt by running:
pip install -r requirements.txtThe dependencies include:
opencv-pythonfor computer vision taskspyzbarfor QR code detectionviam-sdkfor integrating with Viam robot camera
Create a .env file in the root directory and add the following environment variables:
ROBOT_API_KEY=<your_robot_api_key>
ROBOT_API_KEY_ID=<your_robot_api_key_id>
ROBOT_ADDRESS=<your_robot_address>Replace <your_robot_api_key>, <your_robot_api_key_id>, and <your_robot_address> with the appropriate values for your Viam robot from the Viam app.
Once the dependencies are installed and the environment variables are configured, you can run the script using:
python script.pyThis will connect to your Viam robot camera, capture images, and detect QR codes in the live feed. Then press the q key to exit the live feed window.