Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count cameras in OpenCV 2.3?

Tags:

I want to get the number of available cameras.

I tried to count cameras like this:

for(int device = 0; device<10; device++)  {     VideoCapture cap(device);     if (!cap.isOpened())         return device;           } 

If I have a camera connected, it never failed to open. So I tried to preview different devices but I get always the image of my camera.

If I connect a second camera, device 0 is camera 1 and device 1-10 are camera 2.

I think there is a problem with DirectShow devices.

How to solve this problem? Or is there a function like in OpenCV1 cvcamGetCamerasCount()?

I am using Windows 7 and USB cameras.

like image 406
Leon Avatar asked Sep 06 '11 16:09

Leon


People also ask

How do I know how many cameras My OpenCV has?

OpenCV still has no API to enumerate the cameras or get the number of available devices. See this ticket on OpenCV bug tracker for details. Behavior of VideoCapture is undefined for device numbers greater then number of devices connected and depends from API used to communicate with your camera.

Which camera is best for OpenCV?

Pretty much any logitech camera is great for openCV, the most common one being the C270. You can get wider-angle cameras but they are nearly $100, so it's usually easier to just glue a phone camera lens on for a wider FOV. The Pixy is really popular, and it has a bunch of code and libraries available online.


1 Answers

OpenCV still has no API to enumerate the cameras or get the number of available devices. See this ticket on OpenCV bug tracker for details.

Behavior of VideoCapture is undefined for device numbers greater then number of devices connected and depends from API used to communicate with your camera. See OpenCV 2.3 (C++,QtGui), Problem Initializing some specific USB Devices and Setups for the list of APIs used in OpenCV.

like image 141
Andrey Kamaev Avatar answered Sep 21 '22 23:09

Andrey Kamaev