QR Barcode Detection with Python
- Tuan Nguyen
- Jul 6, 2020
- 1 min read

import cv2
import numpy as np
from pyzbar.pyzbar import decode
with open('idData.txt', 'r') as f:
myDataList = f.read().splitlines()
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
if myData in myDataList:
outPut = 'Autherized'
authColor = (255, 255, 0)
else:
outPut = 'UnAutherized'
authColor = (0, 0, 255)
pts = np.array([barcode.polygon], np.int32)
pts = pts.reshape(-1, 1, 2)
pts2 = barcode.rect
cv2.polylines(img, [pts], True, authColor, 2)
cv2.putText(img, outPut, (pts2[0], pts2[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.9, authColor, 4)
cv2.imshow('Webcam', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Comments