Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let user select a video recording device (web-cam) with OpenCV?

So what I need is something like capture devices list.

And some function to get from user on which device he wants to stream.

How to do such thing with openCV in win32 C++ console application?

like image 876
Rella Avatar asked Nov 25 '10 21:11

Rella


1 Answers

As Martin said it's not supported in OpenCV but you could use a little trick. If that satisfies your needs, you can find out the number of cameras by successively enumerating the cameras by calling cvCreateCameraCapture() until it returns NULL.

Sth like this:

CvCapture *cap;
int n = 0;
while(1)
{
   cap = cvCreateCameraCapture(n++);
   if (cap == NULL) break;
   cvReleaseCapture(&cap);
}

cvReleaseCapture(&cap);
return n-1;

Now you have a number of camera devices so you can let your user to select one by its index from i.e. list box.

Disadvantage is that OpenCV doesn't give you any information about device name so if you want to accomplish that too you should take a look at Microsoft DirectShow or the library Martin proposed.

like image 162
Adi Avatar answered Oct 14 '22 22:10

Adi