top of page

QR Barcode Detection with Python


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


 

© 2018 by Tuấn Nguyễn

 Liên hệ tôi
  • Facebook - Black Circle
  • Google+ - Black Circle
bottom of page