Bag of words insufficient memory
HI All,
I am using BOW on a high resolution human action recognition data set. I have tried several solutions online such as releasing the images as soon as they are processed, downsampling the images, converting images in 8 bit. As far as I understand the program works till calculating the descriptors on all video frames. However, it causes a problem at BOW clustering after reading few action classes.
I also tried to create one dictionary per class to simplify the problem. However, still the same problem. I would really appreciate some guidance.
Here is the code:
int do_something() { Mat frame(Size(1280,720),CV_8UC3); Mat frameDown(Size(640,360),CV_8UC3); Mat Grayframe(Size(640,360),CV_8UC1);
// vector of keypoints
vector<KeyPoint> keypoints;
VideoCapture capture(buffer);
// check if video successfully opened
if (!capture.isOpened())
return 1;
// for all frames in video
for (;;)
{
// read next frame if any
if (!capture.read(frame))
break;
// convert to half, i.e., 640 * 360, downsamplying
pyrDown(frame,frameDown, Size( frame.cols/2, frame.rows/2 ));
// Convert images to Gray Scale
if (frameDown.channels()==3)
cvtColor(frameDown,Grayframe,CV_BGR2GRAY);
// feature point detection
fast.detect(Grayframe,keypoints);
extractor->compute(Grayframe, keypoints, descriptor);
// add features to BOW trainer
bowtrainer.add(descriptor);
// Delay to display the video frames
//waitKey(10); // Add this display to avoid blank screen
} // End of For loop
// Releasing memory
capture.release();
frame.release();
frameDown.release();
Grayframe.release();
keypoints.clear();
descriptor.release();
} // End of Do_Something
vocabulary = bowtrainer.cluster();