webstream and barcode recognition running in parallel
This commit is contained in:
parent
feeb93650c
commit
3eca8a3b19
@ -1,14 +1,27 @@
|
||||
from flask import Flask, render_template, Response
|
||||
import cv2
|
||||
import imutils
|
||||
from imutils.video import VideoStream
|
||||
from pyzbar import pyzbar
|
||||
import time
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
vs = VideoStream(src=0).start()
|
||||
time.sleep(2)
|
||||
frame = None
|
||||
|
||||
def stream(camera_index):
|
||||
cam = cv2.VideoCapture(camera_index)
|
||||
global frame
|
||||
while True:
|
||||
_, frame = cam.read()
|
||||
frame = cv2.resize(frame,(400, 240))
|
||||
ret, jpg = cv2.imencode('.jpg', frame)
|
||||
raw_frame = vs.read()
|
||||
stream_frame = imutils.resize(raw_frame, width=400)
|
||||
decode_frame = imutils.resize(raw_frame, width=800)
|
||||
barcodes = pyzbar.decode(decode_frame)
|
||||
for barcode in barcodes:
|
||||
barcode_data = barcode.data.decode("utf-8")
|
||||
print(barcode_data)
|
||||
ret, jpg = cv2.imencode('.jpg', stream_frame)
|
||||
jpg2bytes = jpg.tobytes()
|
||||
yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + jpg2bytes + b'\r\n\r\n'
|
||||
|
||||
@ -21,4 +34,4 @@ def stream_fedd():
|
||||
return Response(stream(0), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000, host='0.0.0.0')
|
||||
app.run(debug=False, port=5000, host='0.0.0.0')
|
||||
|
Loading…
x
Reference in New Issue
Block a user