Skip to content

Repository files navigation

To run on Viam

Follow step-by-step instructions in this tutorial: Use a QR code scanner.

Screenshot 2024-10-30 at 11 08 13 AM

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.

Build and Run

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.

Configure your service

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 vision type, then select the pyzbar module.
  • Enter a name for your vision service and click Create.

Note

For more information, see Configure a Robot.


To run locally

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.

Get Started

  • Install dependencies using pip install -r requirements.txt.
  • Configure environment variables using a .env file.
  • Run the script using python script.py.

Prerequisites

  • Python 3.8 or higher installed on your system.
  • A working Viam robot with a camera configured.
  • Internet access to install required packages.

1. Clone the Repository

git clone <repository-url>
cd <repository-directory>

2. Set Up a Python Virtual Environment

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/activate

On Windows:

python -m venv venv
venv\Scripts\activate

3. Install Dependencies

Once the virtual environment is activated, install the required Python packages listed in requirements.txt by running:

pip install -r requirements.txt

The dependencies include:

4. Set Up Environment Variables

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.

5. Run the Script

Once the dependencies are installed and the environment variables are configured, you can run the script using:

python script.py

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

About

Detect QR codes on a Viam camera using Pyzbar and OpenCV

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages