diff --git a/modules/features2d/src/mser.cpp b/modules/features2d/src/mser.cpp index 5c8db481b1..b7e7993449 100644 --- a/modules/features2d/src/mser.cpp +++ b/modules/features2d/src/mser.cpp @@ -873,10 +873,13 @@ extractMSER_8uC3( const Mat& src, const MSER_Impl::Params& params ) { bboxvec.clear(); - MSCRNode* map = (MSCRNode*)cvAlloc( src.cols*src.rows*sizeof(map[0]) ); + AutoBuffer mapBuf(src.cols*src.rows); + MSCRNode* map = mapBuf.data(); int Ne = src.cols*src.rows*2-src.cols-src.rows; - MSCREdge* edge = (MSCREdge*)cvAlloc( Ne*sizeof(edge[0]) ); - TempMSCR* mscr = (TempMSCR*)cvAlloc( src.cols*src.rows*sizeof(mscr[0]) ); + AutoBuffer edgeBuf(Ne); + MSCREdge* edge = edgeBuf.data(); + AutoBuffer mscrBuf(src.cols*src.rows); + TempMSCR* mscr = mscrBuf.data(); double emean = 0; Mat dx( src.rows, src.cols-1, CV_64FC1 ); Mat dy( src.rows-1, src.cols, CV_64FC1 ); @@ -987,9 +990,6 @@ extractMSER_8uC3( const Mat& src, } bboxvec.push_back(Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1)); } - cvFree( &mscr ); - cvFree( &edge ); - cvFree( &map ); } void MSER_Impl::detectRegions( InputArray _src, vector >& msers, vector& bboxes )