-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr-code-stream.py
75 lines (57 loc) · 1.7 KB
/
qr-code-stream.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 20 16:54:32 2018
@author: Dejan
"""
import cv2
import pyzbar.pyzbar as pyzbar
import math
from queue import Queue
from threading import Thread
#cap = cv2.VideoCapture(0)
url = "rtsp://admin:admin@192.168.1.119:554/0"
cap = cv2.VideoCapture(url)
fps = math.floor(cap.get(5))
delta_t = 0.5
delay = 2
Qf = Queue(-1) # queue of frames to decode
Qd = Queue(-1) # queue of decoded data
def QR_decoder():
print('decoder started')
skip_frames = math.floor(delay / delta_t)
print(skip_frames)
while True:
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print(Qf.qsize())
i = 0
while i < skip_frames:
Qf.get()
i += 1
frame = cv2.cvtColor(Qf.get(), cv2.COLOR_BGR2GRAY)
decodedQRs = pyzbar.decode(frame)
if decodedQRs:
Qd.put(decodedQRs.data)
print('Type : ', decodedQRs.type)
print('Data : ', decodedQRs.data,'\n')
#return decodedQRs
def get_frames():
print('reader started')
i_lim = fps * delta_t
i = 0
try:
while True:
if cv2.waitKey(1) & 0xFF == ord('q'):
break
frame = cap.read()[1]
i += 1
if i >= i_lim:
Qf.put(frame)
i = 0
print(Qf.qsize())
except Exception as e:
print(e)
cap.release()
cv2.destroyAllWindows()
Thread(target=get_frames, daemon=True).start()
Thread(target=QR_decoder, args=(), daemon=True).start()