-
Notifications
You must be signed in to change notification settings - Fork 0
/
QR_Code_Detection.py
42 lines (38 loc) · 1.19 KB
/
QR_Code_Detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import cv2
from PIL import Image
from pyzbar.pyzbar import decode
import numpy as np
# img = cv2.imread('3.jpg')
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
########### for data checking ##############
with open('Data.txt') as f:
myDataList = f.read().splitlines()
# print(myDataList)
# mycolor = (0,0,255)
while True:
success,img = cap.read()
for barcode in decode(img):
# print("im in loop")
# print(barcode.data)
myData = barcode.data.decode('utf-8')
print(myData)
if myData in myDataList:
myOutput = 'in Data'
mycolor = (0,255,0)
else:
myOutput = 'not in Data'
mycolor = (0,0,255)
pts = np.array([barcode.polygon],np.int32)
# print(pts)
pts = pts.reshape((-1,1,2))
# print(pts)
cv2.polylines(img,[pts],True,mycolor,5)
pts2 = barcode.rect
msg = myData + " - " + myOutput
cv2.putText(img,msg,(pts2[0],pts2[1]),cv2.QT_FONT_NORMAL,0.9,mycolor,2)
cv2.putText(img,msg,(pts2[0],pts2[1]),cv2.QT_FONT_NORMAL,0.9,mycolor,2)
cv2.imshow("QR",img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break