Python 从另一个模块(烧瓶)重定向
所以我有一个opencv烧瓶相机流代码。生成要流式传输的帧的函数位于Python 从另一个模块(烧瓶)重定向,python,opencv,flask,Python,Opencv,Flask,所以我有一个opencv烧瓶相机流代码。生成要流式传输的帧的函数位于app.py之外。我希望能够在事件发生时自动停止流并重定向到page2。我试着在@app.route('/video\u feed')中这样做,如下代码所示。我花了两天没有结果 app.py from flask import Flask, render_template, Response, redirect, url_for, import cv2 from applogic import AppLogic app =
app.py
之外。我希望能够在事件发生时自动停止流并重定向到page2
。我试着在@app.route('/video\u feed')
中这样做,如下代码所示。我花了两天没有结果
app.py
from flask import Flask, render_template, Response, redirect, url_for,
import cv2
from applogic import AppLogic
app = Flask(__name__)
vc = cv2.VideoCapture(0)
applogic = AppLogic()
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
@app.route('/page2')
def page2():
"""the page to be redirected to when event happens."""
return render_template('page2.html')
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
temp = applogic.gen()
if temp != 1
return Response(applogic.gen(),
mimetype='multipart/x-mixed-replace; boundary=frame')
else:
return redirect(url_for('page2'))
if __name__ == '__main__':
app.run(host='127.0.0.1]', debug=True, threaded=True)
applogic.py(请注意缩进):
index.html:
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
视频流演示
视频流演示
html:有一个普通的html“hello world”代码;没什么特别的
多谢各位 您用于重定向(即
重定向(url\u for('page2'))
)的代码似乎正确。@GreyLi无法工作,因为正在从html
调用视频源。当gen()
返回1
;该应用程序冻结似乎真的是一个问题,因为到目前为止还没有解决方案。我们所要做的就是根据在app
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>