Accumulating a number of Mat in vector<Mat> [closed]
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);
}
Got it, needed push frame.clone() rather than just frame
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!