At this moment I have with the code that I am using, I create a web service with Flask with which I access the webcam of my laptop.
Python code:
from flask import Flask, render_template, Response
import cv2
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def gen():
i = 1
while i < 10:
yield (b'--frame\r\n'
b'Content-Type: text/plain\r\n\r\n' + str(i) + b'\r\n')
i += 1
def get_frame():
camera_port = 0
ramp_frames = 100
camera = cv2.VideoCapture(camera_port) # this makes a web cam object
i = 1
while True:
retval, im = camera.read()
imgencode = cv2.imencode('.jpg', im)[1]
stringData = imgencode.tostring()
yield (b'--frame\r\n'
b'Content-Type: text/plain\r\n\r\n' + stringData + b'\r\n')
i += 1
del (camera)
@app.route('/calc')
def calc():
return Response(get_frame(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False, threaded=True)
HTML Code:
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="{{ url_for('calc') }}">
<!-- <h1>{{ url_for('calc') }}</h1> -->
</body>
</html>
The problem is that when I add the service to the local server and access from another device on the same network (such as my smartphone), I still access the camera on my laptop. My question is: Is there any way of doing a service that accesses the camera of the external device from which I am consuming it (client)?
Thank you.