forked from thomas545/ecommerce_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_qrcode.py
46 lines (40 loc) · 1.23 KB
/
read_qrcode.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
import cv2
def read_qrcode():
# initalize the cam
cap = cv2.VideoCapture(0)
# initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector()
while True:
_, img = cap.read()
# detect and decode
data, bbox, _ = detector.detectAndDecode(img)
# check if there is a QRCode in the image
# if bbox is not None:
# display the image with lines
# for i in range(len(bbox)):
# # draw all lines
# cv2.line(img, tuple(bbox[i][0]), tuple(bbox[(i+1) % len(bbox)][0]), color=(255, 0, 0), thickness=2)
if data:
print("[+] QR Code detected, data:", data)
# display the result
cv2.imshow("img", img)
if cv2.waitKey(1) == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
def video_reader():
cam = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
print(detector)
while cam:
_, img = cam.read()
data, bbox, _ = detector.detectAndDecode(img)
if data:
print("QR Code detected-->", data)
cv2.imshow("img", img)
if cv2.waitKey(1) == ord("Q"):
break
cam.release()
cv2.destroyAllWindows()
# read_qrcode()
# video_reader()