Read and Decode QR Code Image in Python
This Python OpenCV tutorial to show how to using opencv-python package to read and decode the data of a QR code image in Python.
Install OpenCV package
Installing the opencv-python package using the following command.
pip install opencv-python
How to decode QR code image in Python
For example, we have a QR code image named qrcode.png as below.
The following Python program to read the QR code image and decode the data from the QR code.
import cv2 qrcode_filename = 'qrcode.png' qrcode_image = cv2.imread(qrcode_filename) qrCodeDetector = cv2.QRCodeDetector() data, bbox, straight_qrcode = qrCodeDetector.detectAndDecode(qrcode_image) print('Data decoded from QR code:') print(data)
Data decoded from QR code: https://toricode.com/
Happy Coding 😊