Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Last active January 10, 2024 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srkiNZ84/a0a634f69584f964b8226bb452e8a034 to your computer and use it in GitHub Desktop.
Save srkiNZ84/a0a634f69584f964b8226bb452e8a034 to your computer and use it in GitHub Desktop.
Python script to decode a QR code using OpenCV
import cv2
filename = "/path/to/some_image.png"
image = cv2.imread(filename)
# Docs are here: https://docs.opencv.org/3.4/de/dc3/classcv_1_1QRCodeDetector.html
detector = cv2.QRCodeDetector()
data, vertices_array, binary_qrcode = detector.detectAndDecode(image)
if vertices_array is not None:
print("QRCode data:")
print(data)
else:
print("error no data")
# Sample output:
# QRCode data:
# otpauth://totp/Example%20Company%3AJohn.Doe%40example.com?secret=aaaabbbbcccceee1123m&issuer=Google
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment