QRScanner

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 opens the user’s webcam in a new window, 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 document and the output of the program in the Terminal when it is scanned and 'q’ is clicked on the keyboard. The user will know that the QR code has been successfully scanned when a red box is drawn around the QR code as shown in the first image above.

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