I use the below piece of code to read each frame from the camera and pushing it to a vector. Am doing this to process all the collected frames in the vector at later point.
I used the below code to collect the frames from camera. But after 2005 frames the codes throws the below error.
OpenCV Error: Insufficient memory (Failed to allocate 921604 bytes) in OutOfMemoryError, file D:\Opencv\modules\core\src\alloc.cpp, line 52
The below is the code I used to collect the frames and push it into a vector.
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture(0);
if(!capture.isOpened())
return -1;
vector <Mat> frame;
int delay = 10;
int count = 0;
Mat src;
while(true) {
capture >> src;
frame.push_back(src.clone());
imshow("VIDEO", src);
if( waitKey( delay ) >= 0) break;
count = count+1;
cout << count << endl;
}
/* I need to process each frame stored inside the vector*/
destroyWindow("VIDEO");
capture.release();
return 0;
}