Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

QRWorker.py

The purpose of the QRScanner module is to activate a camera that detects and decodes QR codes. This module uses decklinksrc to access a user’s webcam, and incorporates other QR functions to decode a QR code into a string. pyzbar is also imported in the QRScanner class and is used to read 1-D QR codes. Once the user’s webcam is open in a new window, showing a QR code in front of the camera draws a red box around the QR code, as well as its decoded message above it in red text. An example QR code is shown below, which shows the string “Hello :)".

In main.py, the qrProgram() function calls decklinkSrcWorker_taxi() and qr_worker() in parallel. In this case, decklinkSrcWorker takes frames from the camera and passes them into qr_worker() in a forever loop to create a new video window.

QRWorker.py contains a function called qr_worker() that creates a QRScanner object. qr_worker() also uses opencv and the imshow() method to display the updated frame after the QRScanner object is created. In the QRScanner class, functions are defined that find a QR code in an image, decode the the QR code, set the text above the QR code, and draw bounding boxes on the QR code within the given frame. The QRScanner class imports the pyzbar module that allows the program to read barcodes or QR codes and decode them. The stacked procedures are shown below.

the IntegrationTests.py file works and is currently used to run a QR code. This file contains two tests: one using a PNG image of a QR code in the same folder, and another test using a QR code detected in the user’s webcam. Currently, the IntegrationTests.py file is tested using the video test function, and the other image test function call is commented out. IntegrationTests.py calls the video function that successfully scans only the first QR code detected, saves this message into a variable, and prints the message to the console once the window is closed (when user presses ‘q' on their keyboard). The image below shows the example QR code from CONOPS and the output of the program in the Terminal when it is scanned and 'q’ is clicked.

Note that the logic used to do this was by returning two variables in the QR.py file draw_qr_codes() function. In the forever loop, as soon as the text is not empty, the frame and QR text is returned, then sent to the function in IntegrationTests.py. This function stores the first given text only, and prints it when all windows are destroyed (loop is exited). Keep in mind that the if statement can be changed so that the program stores only the first QR message detected, or so that the program stores the last (most recent) QR message detected.

  • No labels