I want to get live streaming from the client in my web to process it (face recognition and so on) and then display it back to his web.
I already manage to do it with my own camera (host), but I didn't find a solution to do it with the clients webcam.
this is my main code right now:
from flask import Flask, render_template, Response
from camera import VideoCamera
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, threaded=True, use_reloader=False)
The VideoCamera class, capture my webcam (cv2.videocapture(0)) reading teh frames (with the ge_frame() func) process it and then return the image with encoding to jpeg to bytes.
The html part:
<html lang="en">
<head>
<title>Face Detector</title>
</head>
<body>
<h1>Face Recognition</h1>
<img
src="http://localhost:5000/video_feed"
alt="loading video stream..."
/>
</body>
</html>
How can I do it with the clients webcam?