18

I am trying to access a Logitech c310 webcam on my beaglebone. It always returns false for any device ID, I am not sure why.

I use the following code.

>>> import cv2, numpy as np
>>> cam = cv2.VideoCapture(0)
>>> cam.open(0)
False

The camera does show up as video0 in dev/ and also in root@arm:~#lsusb, like below,

root@arm:~# lsusb
Bus 001 Device 002: ID 046d:081b Logitech, Inc. Webcam C310
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I could also access the camera with v4l2-ctl. Note that I am very new to OpenCV, so this may sound silly and I apologize for that in advance.

user26641
  • 337
  • 1
  • 2
  • 7

8 Answers8

15
HIGHGUI ERROR: V4L: index 1 is not correct!
False
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array  type) in cvGetMat, file /home/kaushik/Desktop/OpenCV-2.4.1/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
File "x2.py", line 8, in <module>
cv2.imshow('frame', frame)
cv2.error: /home/kaushik/Desktop/OpenCV-2.4.1/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat

if you are getting this kind of an error then probably something is wrong with the indexing.

instead of cv2.VideoCapture(0) add:

cv2.VideoCapture(-1)

this will get you the first working camera. And if anything goes wrong, just post the stack trace here and i'll see if i can help you :)

kaushik94
  • 687
  • 6
  • 17
  • 1
    Seems counter intuitive but replacing 0 with -1 fixed the error for me. – Lightsout Aug 13 '16 at 00:41
  • 1
    @bakalolo I know, I have read its documentation a few times but the index part is not yet clear in there or may be I am missing something. Its just a matter of which device to pick up. so may be it can't find the device you want on the index `0`. using `-1` will default go to the first working camera it finds. – kaushik94 Mar 21 '17 at 12:24
14

video related functionality is not supported (not compiled with FFmpeg), if cv2 was installed from pypi wheel:

pip install opencv-python

https://pypi.python.org/pypi/opencv-python

  • 1
    Is this still correct? The page you linked says that "All wheels ship with FFmpeg licensed under the LGPLv2.1." Why would they ship with FFmpeg if it wasn't supported by the wheel? – Jim Pfleger May 27 '18 at 15:46
  • Linux versions are now compiled with FFmpeg since https://github.com/skvark/opencv-python/releases/tag/11 Though IIRC it was not working for me until somewhere around the latest 3.4.1.15 release – Hal Jul 05 '18 at 01:09
1

I met the similar issue. It may be related to user permission. Try using the follow procedure to diagnose the issue.

  1. Run the following command to determine the camera access permission

    ls -la /dev/video*

    You might get similar output as below (you might get video1 if you have multiple cameras). As you can see, only root user and users in video group have the permission to access the camera.

    crw-rw----. 1 root video 188, 0 Apr 3 21:16 /dev/video0

  2. So the fix is simple, add your user account to the video group, using the follow command:

    sudo usermod -a -G video <you login name>

Hope it helps!

Mingjiang Shi
  • 7,415
  • 2
  • 26
  • 31
0

If you didn't solve it in many ways,you can try to
find and install "opencv3.2.0-dev",I use it to solve
the problem twice.
just pip install opencv-python is not enough.(hmm,
at least sometimes)

Song
  • 351
  • 3
  • 7
0

It depends on the argument being passed to the cv2.VideoCapture().

Normally, it is 0 for making the primary webcam of your pc work. Similarly, if you want to get access to a second camera installed on you system pass the argument as 2.

But if you have only 1 camera and indexing '0' is not helping, then try passing the index as -1 instead.

Dragon
  • 1,194
  • 17
  • 24
0

I found something in documentation which might just help.

cap.read() returns a bool (True/False). If frame is read correctly, it will be True. Sometimes, cap may not have initialized the capture. In that case, the code shows error. You can check whether it is initialized or not by the method cap.isOpened(). If it is True, OK. Otherwise open it using cap.open().

Source: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html#display-video

Ashish Gupta
  • 185
  • 1
  • 12
0

For me the solution was to restart the computer, seems that there was mismanagement in releasing the camera. I don't like it though bc seems that is not a definitive solution. But it might be that it was a problem with jupyter notebook, now I'm working with spyder bc I read that jupyter is more prone to problems.

Jorge
  • 45
  • 3
-3

It is a matter of missing packages. I had installed a bunch of packages after installing OpenCV. I ran the cmake again and it worked.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
user26641
  • 337
  • 1
  • 2
  • 7