VideoCapture: Count connected cameras (Windows vs. OS X)

asked 2013-01-30 07:12:50 -0500

dom__dom gravatar image

Hello guys,

Right now I am digging deeper and deeper into this fantastic world of openCV. For an application, I've written a small function to determine the amount of cameras, connected to the computer. On OS X (Macbook Pro 2007, 1.7 Lion) everything works as expected.

Here's the little function:

int detectNumAttachedCvCameras()
{
    int number = 0;
    while (true)
    {
        VideoCapture cap;
        cap.open(number);
        if (!cap.isOpened())
        {
            break;
        }
        else
        {
            number++;
            cap.release();
        }
    }
    return number;
}

The function detects the internal iSight camera, a connected logitech usb camera and a ptgrey firewire 400 camera. However, when running on a Windows 7 (x64) machine things get strange. Without any camera connected, the function returns the expected value zero. With the usb camera connected, the function detects the camera and continues looping until the number 100 has been reached. The PC doesn't have a firewire card, so I wasn't able to take this one into account.

Here are some facts about both machines:

Macbook Pro, 2007: 10.7 Lion, OpenCV 2.4.3_1 (macports) +dc1394 +qt4 +universal

PC: Windows 7 x64, OpenCV 2.4.3 (git Merge release 2.4.3)with the following cmake flags:

General configuration for OpenCV 2.4.9 =====================================
  Version control:               commit:4d059e9

  Platform:
    Host:                        Windows 6.1 x86
    CMake:                       2.8.9
    CMake generator:             Visual Studio 10
    CMake build tool:            C:/PROGRA~2/MICROS~2.0/Common7/IDE/devenv.com
    MSVC:                        1600

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                cl
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4  /EHa /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:SSE2 /Oi /fp:fast  /wd4251 /MP8  /MD /O2 /Ob2 /D NDEBUG  /Zi
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4  /EHa /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:SSE2 /Oi /fp:fast  /wd4251 /MP8  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  cl
    C flags (Release):           /DWIN32 /D_WINDOWS /W3   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:SSE2 /Oi /fp:fast    /MP8  /MD /O2 /Ob2 /D NDEBUG  /Zi
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3   /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:SSE2 /Oi /fp:fast    /MP8  /D_DEBUG /MDd /Zi  /Ob0 /Od /RTC1 
    Linker flags (Release):      /STACK:10000000 /machine:X86   /INCREMENTAL:NO  /debug
    Linker flags (Debug):        /STACK:10000000 /machine:X86   /debug /INCREMENTAL 
    Precompiled headers:         YES

  OpenCV modules:
    To be built:                 core imgproc flann highgui features2d calib3d ml video objdetect contrib nonfree photo legacy gpu python stitching ts videostab world
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 androidcamera java ocl

  GUI: 
    QT 4.x:                      YES (ver 4.8.3 EDITION = OpenSource)
    QT OpenGL support:           YES (optimized C:/Qt/4.8.3/lib/QtOpenGL4.lib debug C:/Qt/4.8.3/lib/QtOpenGLd4.lib)
    OpenGL support:              YES (glu32 opengl32)

  Media I/O: 
    ZLib:                        build (ver 1.2.7)
    JPEG:                        build (ver 62)
    PNG:                         build (ver 1.5.12)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    FFMPEG:                      YES (prebuilt binaries)
      codec:                     YES (ver ...
(more)
edit retag flag offensive close merge delete