TREx/website/app.py

38 lines
1.0 KiB
Python

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):
global frame
while True:
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'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/stream_feed')
def stream_fedd():
return Response(stream(0), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(debug=False, port=5000, host='0.0.0.0')