Search code examples
c#opencvcameraemgucv

OpenCV counting cameras


I am currently building an application which is able to access a number of USB webcams. I am well aware that there is no method which can count the number of camera devices on a machine, however, whenever I try to access a camera with a wrong index, I get a black image. Is there some way to use this image to denote a limit?

For example, I have two webcams. The application retrieves frames from the first camera at index 0, and from the second camera at index 1. When i increment index to 2, all I get is a black screen (obviously, since there is no 3rd camera attached).

So far the only way how to go about this is to access every single pixel in a 320x240 bitmap and check that it is black. This is not very efficient so maybe there's some other way of doing this which I am overlooking.

Thanks for your time.


Solution

  • Yes, there is method can count cameras.

    you have to use directshow or directshow.net.

    IEnumMoniker.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms692852%28v=vs.85%29.aspx