Ask Your Question
0

How to change the input of the video capture card?

asked 2016-06-09 04:07:55 -0500

trial_22 gravatar image

I have a video capture card which has 3 inputs (S-video,Composite,TV). How can I change the input of the capture card in run-time by using OpenCV? I am using Visual Studio 2010 c++ and OpenCV 2.1.

When I try to capture video with "capture = cvCaptureFromCAM(0);", It selects the default input of the capture card. Changing the the index of "cvCaptureFromCAM" (capture = cvCaptureFromCAM(1);) does not solve my problem. Any help would be appreciated. Thank you in advance...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-06-17 10:48:41 -0500

pklab gravatar image

Maybe your capture device maps each input with different device index... try enumerating multiple APIs and devices with this code... may be it works

Mat img;
VideoCapture cap;
string str;
vector<int> apiList({ CAP_DSHOW, CAP_MSMF, CAP_VFW });
for (int apiIdx = 0; apiIdx < apiList.size(); apiIdx++) 
{
    int api = apiList[apiIdx];
    for (int camIdx = 0; camIdx<10; camIdx++) 
    {
        cap.release();
        cap.open(camIdx + api);
        if (!cap.isOpened()) 
            continue;
        str = cv::format("API: %d device : %d", apiIdx, camIdx);
        cout << "Device found !! " << str << endl;
        cap >> img;
        if (img.empty()) {
            cout << "\t Unable to grab from " << str << endl;
            continue;
        }
        putText(img, str, Point(10, 20), FONT_HERSHEY_PLAIN,2, 
            Scalar(0, 255, 255),2);

        //a window for each device
        //imshow(str, img);  

        //a single window for all device
        imshow("Frame from current device", img);

        cv::waitKey(10);
    } // for devices
} //for APIs 
cout << endl << "Press Enter to terminate "; cin.get();
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-06-09 03:53:25 -0500

Seen: 1,014 times

Last updated: Jun 17 '16