forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_barcode_reader.py
More file actions
Latest commit
40 lines (34 loc) · 1.26 KB
/
Copy pathlive_barcode_reader.py
File metadata and controls
40 lines (34 loc) · 1.26 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
frompyzbarimportpyzbar
importcv2
defdraw_barcode(decoded, image):
# n_points = len(decoded.polygon)
# for i in range(n_points):
# image = cv2.line(image, decoded.polygon[i], decoded.polygon[(i+1) % n_points], color=(0, 255, 0), thickness=5)
image=cv2.rectangle(image, (decoded.rect.left, decoded.rect.top),
(decoded.rect.left+decoded.rect.width, decoded.rect.top+decoded.rect.height),
color=(0, 255, 0),
thickness=5)
returnimage
defdecode(image):
# decodes all barcodes from an image
decoded_objects=pyzbar.decode(image)
forobjindecoded_objects:
# draw the barcode
image=draw_barcode(obj, image)
# print barcode type & data
print("Type:", obj.type)
print("Data:", obj.data)
print()
returnimage
if__name__=="__main__":
cap=cv2.VideoCapture(0)
whileTrue:
# read the frame from the camera
_, frame=cap.read()
# decode detected barcodes & get the image
# that is drawn
frame, decoded_objects=decode(frame)
# show the image in the window
cv2.imshow("frame", frame)
ifcv2.waitKey(1) ==ord("q"):
break