0

I got a problem with open cv real-time video capturing from camera. I have tried many solutions/suggestions which are available out there but not working for me. Following are the problems:

cap = cv2.VideoCapture(0)

when I tried to get video with this following error comes up:

[ WARN:0] VIDEOIO ERROR: V4L: can't open camera by index 0
Could not open video device
<VideoCapture 0x7fd99e6b5330>

Even though it is reading the video reference. And from one solution by https://github.com/skvark/opencv-python/issues/124 I tried with

cap = cv2.VideoCapture(-1)

But this does not worked for me as it gives the error:

Video device not found

By trying sudo modprobe bcm2835-v4l2 command I got modprobe: FATAL: Module bcm2835-v4l2 not found in directory /lib/modules/4.15.0-66-generic this error. I'm not finding a way to get out of it. It is working fine on my MacBook locally but when I tried to deploy on Ubuntu server I'm facing these errors in loop. Can anyone help me on it? Thanks in advance.

Awais
  • 1,157
  • 9
  • 15
  • Is camera connected to your pc or is it a USB camera? – Ahmet Aug 18 '20 at 16:39
  • I wanted to use default camera connected with laptop not the external camera. – Awais Aug 18 '20 at 17:23
  • 1
    One possibility is the program may not reach the default camera because of the administrator restrictions. Could you please try `sudo chown username:groupname directory`. You can find username by typing `whoami` and groupname by `groups username` – Ahmet Aug 18 '20 at 17:35
  • @Awais have you tried to initialize VideoCapture without argument? – Sergei Nikulov Aug 18 '20 at 17:51
  • @Awais As stated [here](https://stackoverflow.com/questions/59371075/opencv-error-cant-open-camera-through-video-capture) Changing 0 to 1 might work, `VideoCapture(1)` – Ahmet Aug 18 '20 at 20:14
  • First is your camera a webcam or not? Second did you install necessary operating system libraries before installing opencv ? – Yunus Temurlenk Aug 19 '20 at 04:47
  • @Ahmet for `groups username groups: ‘username’: no such user` can not run the command – Awais Aug 19 '20 at 05:35
  • @SergeiNikulov yes I tried without argument but `Could not open video device` – Awais Aug 19 '20 at 05:41
  • @Ahmet with `VideoCapture(1)` getting error with `[ WARN:0] VIDEOIO ERROR: V4L: can't open camera by index 1` – Awais Aug 19 '20 at 05:48
  • @YunusTemurlenk yes camera is webcam and I installed the required libraries as well. – Awais Aug 19 '20 at 05:50
  • As `https://askubuntu.com/questions/348838/how-to-check-available-webcams-from-the-command-line` here I tried to get webcam and reinstall the driver. The lib is installed but getting error `ls: cannot access '/dev/video*': No such file or directory` – Awais Aug 19 '20 at 06:15
  • Install the `sudo apt-get install guvcview` but by running `guvcview` getting error `Guvcview error: no video device found`. It might help to understand my problem. – Awais Aug 19 '20 at 06:30
  • 1
    Can you manuanlly check the /dev/ folder inside, is there any file named by "video0" or not? – Yunus Temurlenk Aug 19 '20 at 06:49
  • 1
    Yes I checked there is no folder named `video0` – Awais Aug 19 '20 at 07:17
  • I think ubuntu don't have the camera access – Awais Aug 19 '20 at 12:11

2 Answers2

0

Can you open your webcam through other apps? If not firslty try to reinstall webcam driver. if you can do it, either some app is using webcam so cv2 can't get access to it or you did not install 3rdparty libraries to work with cameras/videos. You need to install them properly before building OpenCV Python bindings. ( you can find some info there: https://github.com/opencv/opencv/issues/8471 )

icecube
  • 111
  • 2
  • 16
  • Yes I believe the problem is with webcam access. I tried `https://askubuntu.com/questions/348838/how-to-check-available-webcams-from-the-command-line` link and reinstalled the driver but still getting the error `ls: cannot access '/dev/video*': No such file or directory` – Awais Aug 19 '20 at 06:17
  • Use " lsusb" in terminal and look for webcam device (and then tell me if it is there) – icecube Aug 20 '20 at 10:21
  • Actually I had same issue, but I am running this app on live aws server. I want user camera access to take photo selfie. but `/dev/video* : No such file or directory` – Shurvir Mori Nov 09 '21 at 18:27
0

Following is the response from hosting server:

"The directory video0 would not exist because our droplets do not have any peripherals attached to them. The function cv2.VideoCapture() attempts to obtain the video capture from a webcam which a droplet would not have.

If you are wanting to stream a remote feed you should be able to do this via RTSP: https://stackoverflow.com/questions/29099839/opencv-stream-from-a-camera-connected-to-a-remote-machine"

The problem is with droplet which don't have that functionality which we are trying to achieve.

Thanks to all for your love, support and help. Really appreciated. It might help someone else as well.

Awais
  • 1,157
  • 9
  • 15