Created
May 10, 2021 21:38
-
-
Save CoutinhoElias/b00d185f55177e431f583f6eceb31ee4 to your computer and use it in GitHub Desktop.
Barcode cap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from pyzbar import pyzbar | |
def read_barcodes(frame): | |
barcodes = pyzbar.decode(frame) | |
for barcode in barcodes: | |
x, y , w, h = barcode.rect | |
print(barcode.rect) | |
print('X={}, Y={}, W={}, H={}'.format(x, y, w, h)) | |
barcode_text = barcode.data.decode('utf-8') | |
print(barcode_text) | |
cv2.rectangle(frame, (x, y),(x+w, y+h), (0, 255, 0), 2) | |
return frame | |
def main(): | |
camera = cv2.VideoCapture(0) | |
ret, frame = camera.read() | |
while ret: | |
ret, frame = camera.read() | |
frame = read_barcodes(frame) | |
cv2.imshow('Barcode reader', frame) | |
if cv2.waitKey(1) & 0xFF == 27: | |
break | |
camera.release() | |
cv2.destroyAllWindows() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment