Ask Your Question
1

CvCaptureCAM_DShow::open with an out of bound index

asked 2013-08-06 10:04:03 -0600

Eric HUBERT gravatar image

updated 2013-08-07 03:12:16 -0600

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

edit retag flag offensive close merge delete

Comments

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...

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-08-06 19:20:41 -0600 )edit

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.

Eric HUBERT gravatar imageEric HUBERT ( 2013-08-07 03:06:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-14 04:40:14 -0600

Eric HUBERT gravatar image

My defect and proposed fix has been accepted and merged into the 2.4.7 branch http://code.opencv.org/issues/3201

edit flag offensive delete link more

Comments

Thank you :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-14 04:54:15 -0600 )edit

Question Tools

Stats

Asked: 2013-08-06 10:04:03 -0600

Seen: 763 times

Last updated: Aug 14 '13