Ask Your Question

Revision history [back]

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

click to hide/show revision 2
issue + pull request

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