-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33 - Barcode and QR code Reader with Python.py
More file actions
74 lines (57 loc) · 1.99 KB
/
33 - Barcode and QR code Reader with Python.py
File metadata and controls
74 lines (57 loc) · 1.99 KB
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
import cv2 as cv
import datetime
qr = cv.QRCodeDetector()
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("❌ Cannot open webcam")
exit()
scanned_data = set()
print("📷 Stylish QR Scanner | Press ESC to exit")
while True:
ret, frame = cap.read()
if not ret:
break
h, w, _ = frame.shape
# Top banner
cv.rectangle(frame, (0, 0), (w, 60), (30, 30, 30), -1)
cv.putText(frame, "QR Code Scanner",
(20, 40), cv.FONT_HERSHEY_SIMPLEX,
1, (0, 255, 255), 2)
data, bbox, _ = qr.detectAndDecode(frame)
if bbox is not None and data:
bbox = bbox.astype(int)
# Draw glowing box
for i in range(len(bbox)):
cv.line(frame,
tuple(bbox[i][0]),
tuple(bbox[(i + 1) % len(bbox)][0]),
(0, 255, 0), 3)
# Status box
cv.rectangle(frame, (0, h - 60), (w, h), (0, 120, 0), -1)
cv.putText(frame, "QR Detected",
(20, h - 20),
cv.FONT_HERSHEY_SIMPLEX, 0.9,
(255, 255, 255), 2)
# Show data
cv.putText(frame, data,
(20, h - 90),
cv.FONT_HERSHEY_SIMPLEX, 0.8,
(0, 255, 0), 2)
# Save unique scans
if data not in scanned_data:
scanned_data.add(data)
with open("qr_scans.txt", "a") as f:
time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"{time} | {data}\n")
else:
# Scanning mode
cv.rectangle(frame, (0, h - 60), (w, h), (60, 60, 60), -1)
cv.putText(frame, "Scanning...",
(20, h - 20),
cv.FONT_HERSHEY_SIMPLEX, 0.9,
(200, 200, 200), 2)
cv.imshow("Attractive QR Scanner", frame)
if cv.waitKey(1) & 0xFF == 27:
break
cap.release()
cv.destroyAllWindows()