-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrReader.py
52 lines (41 loc) · 1.15 KB
/
qrReader.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
43
44
45
46
47
48
49
50
51
52
import cv2
import numpy as np
import pyzbar.pyzbar as pyzbar
from collections import Counter
import operator
def checkData(list):
dataValues = Counter(list)
cv2.destroyAllWindows()
return max(dataValues, key=dataValues.get)
def getQR(cameraID):
qrData=[]
try:
video = cv2.VideoCapture(cameraID, cv2.CAP_DSHOW)
except:
raise NameError("Could not access the camera, for some weird reason")
while True:
_, frame = video.read()
decodedObjects = pyzbar.decode(frame)
for obj in decodedObjects:
qrData.append(obj.data)
cv2.imshow("QR Code Scanner, press ESC to exit", frame)
if len(qrData)>=10:
video.release()
return checkData(qrData)
key=cv2.waitKey(1)
if key == 27:
video.release()
cv2.destroyAllWindows()
break
def getCameras():
index = 0
cameraArray = []
while True:
test = cv2.VideoCapture(index)
if not test.read()[0]:
break
else:
cameraArray.append(index)
test.release()
index +=1
return cameraArray