def gen(camera):
while True:
res = camera.get_frame()
if res is None:
continue
# 使用generator函数输出视频流, 每次请求输出的content类型是image/jpeg
frame, _, _, person_count = res
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n' + b'Person Count: ' + str(
person_count).encode() + b'\r\n\r\n')
@app.route('/video_feed') # 现场画面界面
def video_feed():
return Response(gen(VideoCamera(_camera=True)),
mimetype='multipart/x-mixed-replace; boundary=frame')
请问,这个写法对吗?不对该怎么写,前端这么接收呢?
