但我想使用一种方法,它还可以保存相机中的所有相框(我已经有功能了)。在
问题是,一旦我启动了Flask应用程序,我最多只能存储在localhost中打开web页面时捕获的帧。我希望能够在应用程序运行时执行其他代码(保存图片),以便保存所有图片,并在浏览器上打开页面时显示到localhost。在
我该怎么做才能同时完成这些任务?在
烧瓶应用:app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)
#want to be able to run code while localhost webpage is closed
在开始时,index()被调用一次,如果我在任何时候打开网页,video_feed()都会调用gen()。如果我关闭该网页,我会得到error: [Errno 10053] An established connection was aborted by the software in your host machine并且.py文件崩溃,可能是因为我已经停止了向客户机传输。我需要能够在客户端关闭连接后运行代码,并且仍然为下一个客户端运行应用程序。在
我希望能够在应用程序仍在运行但没有打开本地主机网页时执行代码。因此,有人打开网页将是一种中断,从正常的代码,直到网页关闭。在