-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrCode.py
77 lines (63 loc) · 1.78 KB
/
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
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
76
77
import qrcode
import validators
import cv2
import numpy as np
from pyzbar.pyzbar import decode
def validateURL(entry):
if not validators.url(entry):
return False
else:
return True
def createQRcode(value):
img = qrcode.make(value)
# if not validators.url(value):
# filename = value + ".jpg"
# else:
# filename = "link.jpg"
filename = "static/qr.jpg"
img.save(filename)
createQRcode(
"https://www.youtube.com/watch?v=-GmJLI122ZM&ab_channel=codebasicscodebasics"
)
def detectLiveFeed():
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cv2.namedWindow("Result")
cap.set(3, 640)
cap.set(4, 480)
response_list = set()
while True and (cv2.getWindowProperty("Result", 0) >= 0):
success, img = cap.read()
for barcode in decode(img):
myData = barcode.data.decode("utf-8")
print(myData)
response_list.add(myData)
pts = np.array([barcode.polygon], np.int32)
pts = pts.reshape((-1, 1, 2))
cv2.polylines(img, [pts], True, (255, 0, 255), 5)
pts2 = barcode.rect
cv2.putText(
img,
myData,
(pts2[0], pts2[1]),
cv2.FONT_HERSHEY_SIMPLEX,
0.9,
(255, 0, 255),
2,
)
cv2.imshow("Result", img)
cv2.waitKey(1)
cap.release()
cv2.destroyAllWindows()
return response_list
def detectFromImage(path):
img = cv2.imread(path)
if len(decode(img)) < 1:
return False
barcode = decode(img)[0]
myData = barcode.data.decode("utf-8")
# print(myData)
# print(barcode)
return myData
img_path = "Hello.jpg"
# print(detectFromImage(img_path))
# print(detectLiveFeed())