Hack Forums
[Python] Flask Opencv webcam app - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Flask Opencv webcam app (/showthread.php?tid=6094154)



Flask Opencv webcam app - dondeveto - Jul 11, 2020

:blackhat: hello ladies and Gents i am having an issue well a few to be exact 😖 and i would like some assistance.

first my code:
PHP Code

<?php 
from flask import Flask
, render_template, Response
from camera import VideoCamera
from flask_ngrok import run_with_ngrok
import time


app 
= Flask(__name__)

#run_with_ngrok(app)




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')


@
app.route('/')
def index():
    
    return 
render_template('index.html')


@
app.route('/view')
def admin():
    
    return 
render_template('view.html')

if 
__name__ == '__main__':
    
app.run(host='0.0.0.0', port=5000) 

i would like to have 2 pages index.html and view.html where if a user visits the route index.html a video stream of their webcam is sent to view.html which another user can see. also i would like to make it so that if another person goes to index.html their video stream is also sent to view.html and allows a person to be able to view both video streams.



my second issue is that of latency

Code
camera.py
PHP Code

<?php 
import cv2

class VideoCamera(object):
    
    
def __init__(self):
        
        
self.video = cv2.VideoCapture(0)
        
        
self.video.set(3, 320)
        
self.video.set(4, 240)
    
def __del__(self):
        
self.video.release()
    
    
def get_frame(self):
        
success, image = self.video.read()
        

        
ret, jpeg = cv2.imencode('.jpg', image)
        return 
jpeg.tobytes() 



RE: Flask Opencv webcam app - omboml - Jul 11, 2020

the code you show was made to stream a webcam connected to the machine running your server to a user visiting your page, not the other way.
you have to grab the users webcam by javascript, stream it to your server and forward it to the other user.


RE: Flask Opencv webcam app - dondeveto - Jul 11, 2020

(Jul 11, 2020 07:43 AM)omboml Wrote:  the code you show was made to stream a webcam connected to the machine running your server.
you have to grab the users webcam by javascript, stream it to your server and forward it to the other user.

an example would be much appreciated â˜šī¸


RE: Flask Opencv webcam app - dondeveto - Jul 12, 2020

so i found this
PHP Code

<?php 
github
.com/dxue2012/python-webcam-flask/blob/master/app.py 
but i want to send video feed to a different route.

i want to capture it on index.html and stream it to say view.html