我有一些开放式cv对象检测输出,我需要在网页上。下面是相关的代码块
烧瓶+OpenCV
def gen_frames():
#Main code body was here but removed because irrelevant to the post
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
app = Flask(__name__)
@app.route('/video_feed')
def video_feed():
#Video streaming route. Put this in the src attribute of an img tag
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0',threaded=True)
HTML(index.HTML)
<html>
<body>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
视频输出按预期显示在网页中
然而,当试图通过另一个网页中的iframe查看该输出时,对象检测会出错
[以下是目标检测的外观。][1]
[以下是通过iframe查看后发生的情况。][2]
终端还显示以下错误
Assertion avci->compat_decode_consumed == 0 failed at libavcodec/decode.c:731
如果原始html页面处于打开状态,尝试查看通过iframe运行的输出将运行应用程序的两个实例。这会产生线程问题
因此,如果您只想通过iframe查看它,请保持该网页的一个实例处于打开状态
相关问题 更多 >
编程相关推荐