c++ OpenCV memory management -


i'm trying build program recognises objects through template matching. whenever select roi program memory starts gain 2-3 mbs per second , after 20-30 minutes program crashes because uses memory.

i think problem starts somewhere in code below have no idea where, , how somehow free memory without corrupting program.

could give me lead on how fix problem?

void testapp::update() {  vidgrabber.grabframe();         if (vidgrabber.isframenew())         {         colorimg.setfrompixels(vidgrabber.getpixels(), camwidth,camheight);         if(subjectisdefined)             {                            iplimage *result = cvcreateimage(cvsize(camwidth - subjectimg.width + 1, camheight - subjectimg.height + 1), 32, 1);                 cvmatchtemplate(colorimg.getcvimage(), subjectimg.getcvimage(), result, cv_tm_sqdiff);                 double minval, maxval;                 cvpoint minloc, maxloc;                 cvminmaxloc(result, &minval, &maxval, &minloc, &maxloc, 0);                 subjectlocation.x = minloc.x;                 subjectlocation.y = minloc.y;             }     } }    void testapp::mousereleased(int x, int y, int button) { //end tracking , normalize subject frame if(subjectframe.width < 0) {     subjectframe.x += subjectframe.width;     subjectframe.width *= -1; }  if(subjectframe.height < 0) {     subjectframe.y += subjectframe.height;     subjectframe.height *= -1; } isselectingtrackingregion = false; subjectlocation.x = subjectframe.x; subjectlocation.y = subjectframe.y;   //copy selected portion of image subject image; subjectimg.allocate(subjectframe.width, subjectframe.height);    colorimg.setroi(subjectframe); subjectimg = colorimg; colorimg.resetroi(); subjectisdefined = true; } 

you have use cvreleaseimage() image iplmage have created in program. have careful find correct place write cvreleaseimage(image name) because once release memory related image, can not access image again.

suggestion: don't use iplimage. that's old c api of opencv. days, can use mat images can manage memory themself. advantage of using mat don't need think freeing memory.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -