40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from flask import Flask, render_template, Response
|
|
import asyncio
|
|
|
|
from indication_driver import IndicationDriver
|
|
from camera_driver import CameraDriver
|
|
import config
|
|
|
|
app = Flask(__name__)
|
|
|
|
indication_driver = IndicationDriver()
|
|
camera_driver = CameraDriver()
|
|
|
|
def stream():
|
|
global indication_driver
|
|
global camera_driver
|
|
indication_task = None
|
|
while True:
|
|
jpg, codes = camera_driver.get_decoded_frame(400, 800)
|
|
trash_category = None
|
|
if codes:
|
|
if indication_task is not None:
|
|
indication_driver.stop_loop()
|
|
if codes[0] in config.BARCODE_LOOKUP_TABLE.keys():
|
|
trash_category = config.BARCODE_LOOKUP_TABLE[codes[0]]
|
|
indication_task = asyncio.create_task(indication_driver.indicate_async(trash_category))
|
|
else:
|
|
indication_driver.stop_loop()
|
|
yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + jpg + b'\r\n\r\n'
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/stream_feed')
|
|
def stream_feed():
|
|
return Response(stream(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=False, port=5000, host='0.0.0.0')
|