Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Flask Opencv webcam app

: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() 
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.
(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 ☹️
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


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by еlixirAug 7, 2022 11:43 AM 3 200 Aug 7, 2022 11:43 AM
Last Post: Pat13nt_Zer0
[Python] by Too FarJul 14, 2022 09:00 AM 2 155 Jul 14, 2022 09:00 AM
Last Post: Too Far
[Python] by The Pulp FictionJan 20, 2022 05:26 AM 5 205 Jan 20, 2022 05:26 AM
Last Post: Hackers