所以我想用imutils VideoStream创建一个视频流,并把它放在网上。这是代码:
camera_web.py
from flask import Flask, render_template, Response
from imutils.video import VideoStream
from imutils.video import FPS
import cv2
app = Flask(__name__)
vs = VideoStream(src=0).start()
@app.route('/')
def index():
""" Video streaming home page """
return render_template('index.html')
def gen():
rval, frame = vs.read()
cv2.imwrite('t.jpg', frame)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + open('t.jpg', 'rb').read() + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug = True, port = 80)
index.html
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vehicle Counter Web</title>
</head>
<body>
<h1>Vehicle Counter Demo</h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
现在当我运行它时,它返回错误:
[ WARN:0] videoio(MSMF):调用OnReadSample()时,状态为错误:-1072875772 [ WARN:0] videoio(MSMF):async ReadSample()调用失败,错误状态为:-1072875772 [ WARN:1] videoio(MSMF):无法抓取帧。联系电话:021 - 88888888
它不会返回任何我的视频流,就像这张图片一样:
是我的代码出错了,还是flask不支持imutils VideoStream?先谢谢你了。
1条答案
按热度按时间3phpmpom1#
好吧,我就是那个愚蠢的人。代码应该是这样的:
camera_web.py
好了我们现在应该看到视频流。Link to the image