-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarCode.py
32 lines (24 loc) · 943 Bytes
/
barCode.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
import cv2
import numpy as np
from pyzbar.pyzbar import decode
def readBarCode():
camera_id = 0
delay = 1
window_name = 'OpenCV pyzbar'
cap = cv2.VideoCapture(camera_id)
while True:
ret, frame = cap.read()
if ret:
for d in decode(frame):
s = d.data.decode()
print(s)
frame = cv2.rectangle(frame, (d.rect.left, d.rect.top),
(d.rect.left + d.rect.width, d.rect.top + d.rect.height), (0, 255, 0), 3)
frame = cv2.putText(frame, s, (d.rect.left, d.rect.top + d.rect.height),
cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imshow(window_name, frame)
if cv2.waitKey(delay) & 0xFF == ord('q'):
break
cv2.destroyWindow(window_name)
if __name__ == "__main__":
readBarCode()