Rella
Rella

Reputation: 66965

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?

Upvotes: 7

Views: 10188

Answers (3)

Utkarsh Sinha
Utkarsh Sinha

Reputation: 3305

Try using some OS functions to enumerate webcams. It might take some work, but this approach will guarantee that you get a list every time (unlike the OpenCV hack, which sometimes doesn't work, for some reason).

Upvotes: 1

Adi
Adi

Reputation: 1316

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.

Upvotes: 5

Martin Beckett
Martin Beckett

Reputation: 96139

Not directly supported in opencv (AFAIK) but try http://www.muonics.net/school/spring05/videoInput/

Upvotes: 3

Related Questions