cv2.VideoCapture.open() always returns FALSE

后端 未结 8 1956
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 17:52

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.



        
相关标签:
8条回答
  • 2020-12-09 18:28

    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.

    0 讨论(0)
  • 2020-12-09 18:30
    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 :)

    0 讨论(0)
  • 2020-12-09 18:32

    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!

    0 讨论(0)
  • 2020-12-09 18:38

    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.

    0 讨论(0)
  • 2020-12-09 18:41

    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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题