Skip to content

Latest commit

 

History

History

opencv-qr-decoder-python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Copyright (C) 2021, Axis Communications AB, Lund, Sweden. All Rights Reserved.

OpenCV QR Decoder

This example shows a minimal QR code detector and decoder application written in Python. It composes two different container images into an application that performs an inference using a deep learning model.

The first container contains the actual program built in this example. It then uses gRPC/protobuf to call the second container, that is used to capture images from the camera.

NumPy is used to preprocess the images and OpenCV to detect and decode any QR codes within the image.

Application layout

opencv-qr-decoder-python
├── app
│   └── qr.py
├── docker-compose.yml
├── Dockerfile
└── README.md
  • qr.py - The application's main script
  • Dockerfile - Dockerfile specifying how the application runtime is built
  • docker-compose.yml - docker-compose file specifying how/with what settings the application is started

Requirements

Meet the following requirements to ensure compatibility with the example:

  • Axis device
    • Chip: ARTPEC-8 DLPU devices (e.g., Q1656)
    • Firmware: 11.10 or higher
    • Docker ACAP version 3.0 installed and started, using TLS with TCP and IPC socket and SD card as storage
  • Computer
    • Either Docker Desktop version 4.11.1 or higher,
    • or Docker Engine version 20.10.17 or higher with BuildKit enabled using Docker Compose version 1.29.2 or higher

How to run the code

Build the Docker image

Define and export the application image name in APP_NAME for use in the Docker Compose file.

export APP_NAME=acap-opencv-qr-decoder-python

# Install qemu to allow build for a different architecture
docker run --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes

docker build --tag $APP_NAME .

Set your device IP address and clear Docker memory

DEVICE_IP=<actual camera IP address>
DOCKER_PORT=2376

docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT system prune --all --force

If you encounter any TLS related issues, please see the TLS setup chapter regarding the DOCKER_CERT_PATH environment variable in the Docker ACAP repository.

Install the image

Browse to the application page of the Axis device:

http://<AXIS_DEVICE_IP>/index.html#apps

Click on the tab Apps in the device GUI and enable Allow unsigned apps toggle.

Next, the built images needs to be uploaded to the device. This can be done through a registry or directly. In this case, the direct transfer is used by piping the compressed application directly to the device's Docker client:

docker save $APP_NAME | docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT load

Run the container

With the application image on the device, it can be started. As the example uses OpenCV, the OpenCV requirements will be included in docker-compose.yml, which is used to run the application:

docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT compose up

# Terminate with Ctrl-C and cleanup
docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT compose down --volumes

License

Apache License 2.0

References