Forums

Problem playing realtime video

Hi everyone, I made a site that, landing on the page, opens the webcam and in real time makes red objects invisible (I use cv2). Locally it works but on pythonanywhere it doesn't ask me if I want to give permission to access the cam. Even if I force the permissions, the cam doesn't start. Can you tell me why, in case I can also share the code

Are there any errors in your browser's developer tools console when you visit the site?

hi! No, it doesn't give me any errors.

https://mantelloinvisibilita.pythonanywhere.com/

The html is very simple: title and body with <img src="{{ url_for('video_feed') }}" width="640" height="480">

screenshoot

Can you see anything in your error log?

unfortunately nothing

I'm making some changes to the code, but I don't see any improvements

Now I have this error [ WARN:0@0.196] global

/io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

in the code i added

cap = cv2.VideoCapture(0)

To be able to activate the cam by pressing a button (and not by accessing the index page) I tried changing the 0 to 1 but same result

JS in html

    $("#startButton").click(function() {
        $.get("/start_video", function(date, status) {
            if (status === "success") {
                $("#videoFeed").attr("src", "{{ url_for('video_feed') }}");
            }
        });
    });

But I get the error back

[ WARN:0@0.196] global /io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

Update, i used Javascrit's getUserMedia and now i have access to the cam. I just have to convince him to show the video I create in real time and not the cam video

ok, i'm freaking out. Since I had to use the client-side video to edit it in realtime on the server side. I thought of using JS's getUserMedia to use the webcam and using sockets via pusher.com to connect FE and BE but i failed.

I'm a self-taught newbie, so if you want to help me out, I'm here. In case I can share all the code!

Now I'm going to cry in a corner!

Hmm, are you trying to stream the video back to a website running on PythonAnywhere so that it can modify it? If so, what protocol are you using for that?

I use HTTP along with the concept of "multipart/x-mixed-replace" and that's the problem, they suggested sockets but I don't know how to use them

1.Capturing the video stream from the webcam using OpenCV and the cv2.VideoCapture(0) object and this is already a problem, not working on the client side

2.background definition

3.takes a frame captured by the webcam and applies a filter to remove the red color from the image.

4.Return the processed frames as a multipart HTTP response to render the video stream in the browser.

I tried to use getUserMedia and thus access the client side cam but I can't take advantage of the video to remove the background

Capturing the video stream from the webcam requires code running on the same machine that camera is connected to, so not on PythonAnywhere. You need to do it in the browser.

This is true. I've tried using Javascript's getUserMedia and that gives me access to the webcam. But once done I can't use this video for the program and send the edited realtime video to FE

I'm afraid that's not something that we can help with.

ok :(, however if someone wants to give support by seeing the code I'm available! Thanks anyway

I solved it by moving everything to the client side via JS. Now works

Happy to hear that!