-1

I want to create a face recognition app with Flask that will be accessible over the local network so other devices can access, the frames from the video stream will be sent to Flask server via socket io connection but the problem is camera access is given to HTTPS connection.

I tried tweaking the browser to allow HTTP connection for camera on chrome and firefox but no use. I also tried to make SSL certificate and attach to the application but the browser shows invalid certificate.

Does anyone know other ways to make it work

1 Answers1

0

I have to use something alike for an AI thing I'm doing, and this is pretty much how I stream my camera feed to the local 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()))
Mohit Reddy
  • 133
  • 8