当将视频输出到html页面,然后将该页面传递到另一个html页面中的iframe时,OpenCV对象检测变得不稳定

2024-04-24 15:44:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些开放式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


1条回答
网友
1楼 · 发布于 2024-04-24 15:44:39

如果原始html页面处于打开状态,尝试查看通过iframe运行的输出将运行应用程序的两个实例。这会产生线程问题

因此,如果您只想通过iframe查看它,请保持该网页的一个实例处于打开状态

相关问题 更多 >