cv2.VideoCapture.open() always returns FALSE

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

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.

回答1:

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



回答2:

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  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 :)



回答3:

First If you are trying to capture video, then cam.open() is not the right way to do it. open() method initializes the camera object(in this case the "cam").

Secondly Here the cam.open() returns false because cv is not able to initialize the cam object. The VideoCapture() method already initializes your camera object. You can check this by adding

cam.isOpened() 

right after

cam.VideoCapture(0) 

that will return "True".

Thirdly if you want to vied camera feed, this is the conventional way to do it

import cv2  cam = cv2.VideoCapture(0) print cam.isOpened()  while(True):         ret, frame = cam.read()         cv2.imshow('frame', frame)         if cv2.waitKey(1) & 0xFF == ord('q'):             break  cam.release() cv2.destroyAllWindows() 


回答4:

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)



回答5:

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.



回答6:

<
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!