Forums

Camera not found trying to use cv2.videocapture(-1)

I am using a python script that imports cv2 first and then runs the code using opencv library to activate the webcam but when i execute the file through bash console, instead of running it says

open VIDEOIO(V4L2): can't find camera device

FYI this script works perfect on my localserver but not when hosted on pythonanywhere

Please help me or suggest me some solution as I am a rookie in Python

The code that you run on PythonAnywhere is running on a different machine than your local one, so it has no way of connecting to the camera on your local machine. You can use browser APIs to access the camera and then send that data to PythonAnywhere using Javascript.

Hi @glenn Can i have some links or any other useful resources to deal with that. it would be really helpful of you.

@glenn Yes please I agree with @evapp

possibly something like this?

hi, you can use opencv.js for getting input from webcam. (cv2 tries to capture from pythonanywhere's server which doesn't have camera).

how to fix it?

There is nothing to fix about that. See this forum post.