Ask Your Question

multiple webcams VC++

asked 2014-05-23 19:22:20 -0500

vbopencv gravatar image

Need simple code in Visual Studio C++ to list multiple webcam attached to pc so to be able to select a particular webcam. Thanks

edit retag flag offensive close merge delete



sorry, dear, but there's no such functionality in opencv.

berak gravatar imageberak ( 2014-05-24 01:14:18 -0500 )edit

@berak isn't it can be done using VideoCapture cap(0); then VideoCapture cap(1); and so on

FLY gravatar imageFLY ( 2014-05-26 04:04:59 -0500 )edit

i think he was asking for a list of names. (but sure you can just iterate over the ids)

if you try -1 on win, vfw sometimes comes up with a choice box.

berak gravatar imageberak ( 2014-05-26 05:19:20 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-05-24 14:50:21 -0500

Y Simson gravatar image

One simple method is to try open webcams until you fail. The number of successes is the number of webcams.

How is how I would do this:

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

/** @function main */
int main(int argc, const char** argv)
    int numOfWebCams = 0;
    cv::VideoCapture cap[MAX_NUM_OF_CAMERAS];
    cv::Mat frame;
    for (size_t i = 0; i < MAX_NUM_OF_CAMERAS; i++)
        bool bSuccess = true;
        if (!cap[i].isOpened())  // check if we succeeded
            bSuccess &= false;

        bSuccess &= cap[i].read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
            std::cout << "The number of active webcams is: " << numOfWebCams << std::endl;
    return 0;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-05-23 19:22:20 -0500

Seen: 129 times

Last updated: May 24 '14