Ask Your Question
0

Simple Frame code issue

asked 2013-03-20 08:56:12 -0600

codey666 gravatar image

updated 2013-03-20 09:04:22 -0600

berak gravatar image
int main()
{
    VideoCapture vid(0);
    if(!vid.isOpened())
        return 1;
    double rate= vid.get(CV_CAP_PROP_FPS);
    Mat frame,temp;
    namedWindow("temp");
    int delay=2000;
    bool stop(false);
    vid>>temp;
    while(!stop)
    {


        vid>>frame;

    imshow("temp",temp);


        if(waitKey(delay)>=0)
            stop=true;

    }
    imshow("Frame",frame);
    imshow("Ex Frame",temp);
    Mat dif=(temp - .5 * frame);
    imshow("x frame",dif);
    vid.release();



    waitKey();

    return 0;
}

In the above code the 'temp' is acquired before the loop and is shown in the loop and i expected to get only the first frame as output but i get the continuous frame output i just cant figure it out its just as if i've written "imshow("temp",frame);" Please help..silly thing...big headache...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-20 09:10:37 -0600

berak gravatar image

the images you get from a webcam point to videodriver memory. though you've got 2 Mat instances, their pixels point at the same thing. (temp will get overwritten in the next frame)

so, if you want to save temp for a rainy day, clone it!

vid >> temp;
temp = temp.clone();
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-20 08:56:12 -0600

Seen: 134 times

Last updated: Mar 20 '13