我正在做一个项目,在这个项目中,我需要像IP摄像机一样在网络上“远程广播”用户摄像机输入。因此,我有一个变通方法,可以通过python Flask应用程序实现这一点。因为我认为,当我尝试捕获web URL(再次)时,它的工作方式与IP摄像头相同。以思维导图的形式,它会是这样的:
用户摄像机>;cv2.视频捕获(用户摄像头)>;视频源的结果URL>;cv2.视频捕获(视频源的URL)以供进一步使用
在我的本地机器上,代码cv2.VideoCapture(0)
正在从我的网络摄像头返回摄像头输入。因此,我认为当我尝试在Heroku上部署它时,它将以同样的方式工作。但在网络上发生的是,没有来自用户网络摄像头的输入。我如何解决这个问题
这是我的完整app.py代码
from flask import Flask, render_template, Response
import cv2
app = Flask(__name__)
camera = cv2.VideoCapture(0)
def gen_frames():
while True:
# Capture frame-by-frame
success, frame = camera.read()
if not success:
break
else:
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')
@app.route('/video_feed')
def video_feed():
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(threaded=True, port=5000)
尝试此链接,它将有助于通过web https://towardsdatascience.com/video-streaming-in-web-browsers-with-opencv-flask-93a38846fe00捕获用户的网络摄像头
相关问题 更多 >
编程相关推荐