website now shows rectangle around barcode

This commit is contained in:
paul-loedige 2023-01-16 02:34:26 +00:00
parent 3eca8a3b19
commit 83e2cadd9d

View File

@ -19,8 +19,12 @@ def stream(camera_index):
decode_frame = imutils.resize(raw_frame, width=800) decode_frame = imutils.resize(raw_frame, width=800)
barcodes = pyzbar.decode(decode_frame) barcodes = pyzbar.decode(decode_frame)
for barcode in barcodes: for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(decode_frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcode_data = barcode.data.decode("utf-8") barcode_data = barcode.data.decode("utf-8")
print(barcode_data) print(barcode_data)
cv2.putText(decode_frame, barcode_data, (x, y -10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255), 2)
stream_frame = imutils.resize(decode_frame, width=400)
ret, jpg = cv2.imencode('.jpg', stream_frame) ret, jpg = cv2.imencode('.jpg', stream_frame)
jpg2bytes = jpg.tobytes() jpg2bytes = jpg.tobytes()
yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + jpg2bytes + b'\r\n\r\n' yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + jpg2bytes + b'\r\n\r\n'