Ask Your Question

Revision history [back]

How to open VideoCapture twice?

Hi, all:

I would like to open VideoCapture twice. 1) The first time, scan all existing VideoCapture devices. 2) The second time, use some certain capture device to start capturing.

Code patch is attached.

unsigned int num = 0;
cv::VideoCapture cap;
while(true)
{
    cap.open(num++);
    if(!cap.isOpened())
        break;
    cap.release();
}
num--;

Mat frame;
cap.open(num-1);
cap >> frame;
cv::imwrite("test.jpg", frame);

I couldn't see anything wrong that I've done. But, I failed to retrieve a frame, and of course, what I saved is not a non-jpg file -- just nothing .

Can anybody help please?

Cheers Pei