CvCaptureCAM_DShow::open with an out of bound index
Hello,
In my program (MultiPlatform C++ using OpenCV 2.4.6) , I am trying to determine how many video inputs are available. There is no straightforward API for that, so I'm doing a small workaround:
I try and init a new VideoCapture with an increasing index until it fails. (isOpened() returns false)
while(bOk)
{
test = new cv::VideoCapture(i++);
bOk = test->isOpened();
...
}
While it's working on linux (with V4L2) it fails on Windows (with DirectShow) since the OpenCV Dshow wrapper, when requested to open a camera index out of bound, decides to use the last available one. (so I'm getting 99 working inputs)
cf cap_dshow.cpp l.3172
try_index = try_index < 0 ? 0 : (try_index > devices-1 ? devices-1 : try_index);
Is there any particular reason for this behaviour? (I did not find an obvious one on the source history) maybe is this a workaround for a dshow issue?
Thank you
Edit : The "fall back" behavior should be, in my opinion, a decision from the caller, and not the lib itself. I did a fix yesterday, it seems to be working perfectly. So I assume there is no issue from dshow. I added an issue in the tracker and made a pull request for the fix. I hope it will make it into the 2.4.7 : http://code.opencv.org/issues/3201
Not a real solution, but try to decrease instead of increase (ie: i = 101; ... test = new cv::VideoCapture(i--); ). It assume: 1) their is no more than 100 cameras (acceptable, but you could adapt), 2) the number of camera is continuous (stop when you find a camera). But a "real" solution would be better...
Thank you for the idea, but it won't help me. the "try_index" used within the DShow wrapper makes that even if I start with index 99, it will use the "last" camera from its own list.