-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
44 lines (37 loc) · 1.21 KB
/
main.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
import time
import cv2
import imutils
import serial
import ringHelper
import qrutils
import prettyPrint as pp
def main():
log = pp.Log("Main")
cap = cv2.VideoCapture(0)
# ser = serial.Serial(ringHelper.get_serial(), 115200)
qr = qrutils.QRCode()
while True:
_, img = cap.read()
data = qrutils.ImgHelper.find_qr_code(img) # check if there is a QRCode in the image
# time.sleep(.5)
cv2.imshow("FrameOrig", imutils.resize(img, width=300))
if data is not None:
matrix = qr.np_to_matrix(data)
read_data = qr.decode(matrix)
cv2.imshow("Frame", imutils.resize(data, width=300))
if read_data == -1:
qrutils.QREvents.play_sound_qr('wrong.mp3')
# qrutils.QREvents.ring_fail(ser)
log.print("Matrix not valid")
else:
qrutils.QREvents.play_sound_qr('Sound.mp3')
log.print(f"Data:{read_data}")
# qrutils.QREvents.ring_pass_async(ser)
time.sleep(.5)
if cv2.waitKey(1) == ord("q"):
break
# ser.close()
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()