memory leak in MSER algorithm (Bug #4379)
Description
This bug does not always occur. An image has been attached which will cause memory leak when I do the following:
vector<vector<Point> > contours; vector<Rect> boxes; Mat gray_im = imread("memtest.jpg", 0);//use grayscale image Ptr<MSER> mser = MSER::create(21,(int)(0.00002*gray_im.cols*gray_im.rows),(int)(0.05*gray_im.cols*gray_im.rows),1,0.7); //here the memory leak will be caused mser->detectRegions(gray, contours, boxes);
History
Updated by Haojin Yang almost 10 years ago
I have found the problem is within this function:
void pass( const Mat& img, vector<vector<Point> >& msers, vector<Rect>& bboxvec,
Size size, const int* level_size, int mask );
once a pixel component tries to set the next pixel component.
I added this small check, and found that for this image there will be many pixel items pointed to itself.
Of course this will result in infinite loop in the comptr->capture(....).
But I'm not sure what way to fix this problem is the optimal.
I would be better that someone fixing this who is more familiar with the algorithm.
// add a pixel to the pixel list
if( comptr->tail ){
if(comptr->tail == ptrofs){
printf("pointer to itself, %d\n", ptrofs);
}
ptr0[comptr->tail].setNext(ptrofs);
}
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/5009