Skip to content

Instantly share code, notes, and snippets.

@CoutinhoElias
Created May 10, 2021 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoutinhoElias/b00d185f55177e431f583f6eceb31ee4 to your computer and use it in GitHub Desktop.
Save CoutinhoElias/b00d185f55177e431f583f6eceb31ee4 to your computer and use it in GitHub Desktop.
Barcode cap
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