Accumulating a number of Mat in vector<Mat> [closed]

asked 2013-11-21 05:44:40 -0500

updated 2013-11-21 05:45:35 -0500

I'm grabbing frame from webcam am displaying them on a window. To do a temporal analysis, I keeping the frames on a vector<mat> as I grab them. In order to test it, when the size of my vector reaches 100, I attempt to visualize all the frames that I stored so far. The strange thing is that, indeed the vector has 100 frames inside, but they are all the same and correspond to the last frame that was captured.

Code:

Mat frame;       

    _cap.start(0);  //VideoCapture object   

    vector<Mat> seq;
    while(1)
    {
        _cap.getFrame(frame);           

        seq.push_back(frame);

        imshow("a", seq[0]);

        if (seq.size() == 100)
        {
            for (int n = 0; n < seq.size(); n++)
            {
                cout << "I'm in" << endl;
                imshow("b", seq[n]);
                waitKey(0);
            }
        }

            waitKey(30);   
    }
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2013-11-21 06:20:50.006303

Comments

1

Got it, needed push frame.clone() rather than just frame

Pedro Batista gravatar imagePedro Batista ( 2013-11-21 06:08:22 -0500 )edit

This problem has passed the forum alot lately. Indeed the getframe only pushes a pointer to the current memory location. This means that all pushes into the vector will actually contain the same information. Cloning does solve it!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-11-21 06:19:03 -0500 )edit