问题描述
我想用 Flask 创建一个可以通过本地网络访问的人脸识别应用程序,以便其他设备可以访问,视频流中的帧将通过 socket io 连接发送到 Flask 服务器,但问题是相机访问是提供给 HTTPS 连接。
我尝试调整浏览器以允许 chrome 和 firefox 上的相机进行 HTTP 连接,但没有用。我也尝试制作 SSL 证书并附加到应用程序,但浏览器显示无效证书。
有没有人知道其他方法让它工作
解决方法
对于我正在做的 AI 工作,我必须使用类似的东西,这几乎就是我将相机源流式传输到本地 IP 的方式。
from flask import Flask,Response
import cv2,socket
app = Flask(__name__)
#camera = cv2.VideoCapture("rtsp://admin:pass/0.0.0.0:8080") #If you want to use RTSP
camera = cv2.VideoCapture(0)
def gen_frames():
while True:
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('/')
def index():
return '''<img src="/video_feed" width="100%" height="100%">'''
@app.route('/video_feed')
def video_feed():
return Response(gen_frames(),mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == "__main__":
app.run(debug=True,port=8080,host=socket.gethostbyname(socket.gethostname()))