To complete this chapter, we are going to learn how to detect QR codes in images. This way, QR codes can also be used as markers for our augmented reality applications. The cv2.detectAndDecode() function both detects and decodes a QR code in the image containing the QR code. The image can be grayscale or color (BGR).
This function returns the following:
- An array of vertices of the found QR code is returned. This array can be empty if the QR code is not found.
- The rectified and binarized QR code is returned.
- The data associated with this QR code is returned.
In the qr_code_scanner.py script, we make use of the aforementioned function to detect and decode QR codes. The key points are commented next.
First, the image is loaded, as follows:
image = cv2.imread("qrcode_rotate_45_image.png")
Next, we create the QR code detector with the following code...