c++ - Release memory OpenCV , right memory allocation/deallocation ( management ) on OpenCV structures in function -


i calling next function inside class inside thread in loop ( capturing frames camera , processing them ) :

cvrect imageprocessor::detectfaceinimage(const iplimage *inputimg) // {     iplimage *detectimg;     cvmemstorage* storage = 0;     cvrect *rc = 0;     cvrect rect;     double count;     cvseq* rects = 0;     int l,n;     detection_time = (double)cvgettickcount();     detectimg = cvcloneimage(inputimg);     if(fastdetectmode)     {         facecascade = (cvhaarclassifiercascade*)cvload(             facecascadefile[0].toascii().data(),              0,              0,              0         );          if( !facecascade )         {             qmessagebox mbox;             mbox.seticon(qmessagebox::information);             mbox.settext("can't load haar cascade face detector 0");             mbox.setstandardbuttons(qmessagebox::ok);             mbox.exec();              if(detectimg)                 cvreleaseimage(&detectimg);              return cvrect(-1,-1,-1,-1);         }         for(l=0;l<10;l++) //10 different search scale factors ( 10 )         {             storage = cvcreatememstorage(1000000); //0              rects = cvhaardetectobjects(                 detectimg,                 (cvhaarclassifiercascade*)facecascade,                  storage,                  search_scale_factor[l],                  minneighborhood[1],                 flags[0],                  minfeaturesize[0]             );              if(rects->total>0)             {                 for(n=0;n<rects->total;n++)                 {                     rc = (cvrect*)cvgetseqelem( rects, n );                     if((rc->height > 0.1*faceheight) && (rc->width>0.1*facewidth))                     {                         if(detectimg)                             cvreleaseimage(&detectimg);                          if(facecascade)                             cvfree(&facecascade);                          count = (double)cvgettickcount();                          detection_time = (double)((count - detection_time) /                              (double)cvgettickfrequency())/1000000;                          rect = *rc;                         cvreleasememstorage(&storage);                         return rect;                     }                 }             }              if(storage)                 cvreleasememstorage(&storage);         }          cvfree(&facecascade);     }      //nothing found:     rect = cvrect(-1,-1,-1,-1);     count = (double)cvgettickcount();      detection_time = (double)((count - detection_time) /          (double)cvgettickfrequency())/1000000;      if(detectimg)         cvreleaseimage(&detectimg);      return rect; } 

i expecting each time call function necessary memory detecting desired face region ( rectangle cvrect) in input image allocated , deallocated after function return. happening when run there memory leak in function , words , ram ( pc physical memory ) growing when call function in loop.

facecascade imageprocessor class member not declared in function variables. see wrong memory creation/release ( allocation/deallocation ) in function? why memory leak. thank in advance help. paul


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -