Ask Your Question
0

How to open VideoCapture twice?

asked 2013-02-07 21:46:49 -0600

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-07 23:37:36 -0600

Vladislav Vinogradov gravatar image

After loop you decrease num variable. And when you open cap before reading frame you decrease it again. Remove one of decrement.

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

Mat frame;
cap.open(num-1);
cap >> frame;
cv::imwrite("test.jpg", frame);
edit flag offensive delete link more
0

answered 2013-02-13 16:47:07 -0600

Thanks... Sorry for this naive question.. ^_^ Close the topic please...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-07 21:46:49 -0600

Seen: 2,063 times

Last updated: Feb 13 '13