Python 在烧瓶中动态显示图像
我必须流式播放视频,在流式播放视频下面,我必须在同一个HTML文件中显示基于脚本动态更改的图像 stream.py index.html 这是我的渲染模板。它动态地采用calc的路径Python 在烧瓶中动态显示图像,python,opencv,flask,jinja2,Python,Opencv,Flask,Jinja2,我必须流式播放视频,在流式播放视频下面,我必须在同一个HTML文件中显示基于脚本动态更改的图像 stream.py index.html 这是我的渲染模板。它动态地采用calc的路径 视频流演示 视频流演示 现在,除了视频显示之外,我还想在同一个HTML中显示在特定时间段后发生变化的图像。那怎么做呢 #!/usr/bin/env python from flask import Flask, render_template, Response import cv2
视频流演示
视频流演示
现在,除了视频显示之外,我还想在同一个HTML中显示在特定时间段后发生变化的图像。那怎么做呢
#!/usr/bin/env python
from flask import Flask, render_template, Response
import cv2
import sys
import numpy
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def get_frame():
camera_port=0
camera=cv2.VideoCapture(camera_port) #this makes a web cam object
while True:
retval, im = camera.read()
imgencode=cv2.imencode('.jpg',im)[1]
stringData=imgencode.tostring()
yield (b'--frame\r\n'
b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n')
del(camera)
@app.route('/calc')
def calc():
return Response(get_frame(),mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='localhost', debug=True, threaded=True)
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="{{ url_for('calc') }}">
</body>
</html>