Skip to content
Snippets Groups Projects
Commit 4650d370 authored by Andrews Cordolino Sobral's avatar Andrews Cordolino Sobral
Browse files

[important] Fixed memory leak on T2F* algorithms

4  algorithms: T2FGMM_UM, T2FGMM_UV, T2FMRF_UM, T2FMRF_UV
parent 4dfd8696
Branches
Tags
No related merge requests found
...@@ -253,6 +253,7 @@ void MRF_TC::InitEvidence2(GMM *gmm, HMM *hmm, IplImage *labeling) ...@@ -253,6 +253,7 @@ void MRF_TC::InitEvidence2(GMM *gmm, HMM *hmm, IplImage *labeling)
} }
} }
} }
background.ReleaseImage();
} }
void MRF_TC::CreateOutput2() void MRF_TC::CreateOutput2()
......
...@@ -62,6 +62,7 @@ void T2FGMM_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -62,6 +62,7 @@ void T2FGMM_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
img_foreground.copyTo(img_output); img_foreground.copyTo(img_output);
img_background.copyTo(img_bgmodel); img_background.copyTo(img_bgmodel);
frame_data.ReleaseImage();
firstTime = false; firstTime = false;
frameNumber++; frameNumber++;
......
...@@ -62,6 +62,7 @@ void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -62,6 +62,7 @@ void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
img_foreground.copyTo(img_output); img_foreground.copyTo(img_output);
img_background.copyTo(img_bgmodel); img_background.copyTo(img_bgmodel);
frame_data.ReleaseImage();
firstTime = false; firstTime = false;
frameNumber++; frameNumber++;
......
...@@ -25,14 +25,8 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -25,14 +25,8 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
frame_data = cvCloneImage(&_frame); frame_data = cvCloneImage(&_frame);
if (firstTime) { if (firstTime) {
int width = img_input.size().width; width = img_input.size().width;
int height = img_input.size().height; height = img_input.size().height;
lowThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
lowThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
highThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
highThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
params.SetFrameSize(width, height); params.SetFrameSize(width, height);
params.LowThreshold() = threshold; params.LowThreshold() = threshold;
...@@ -46,16 +40,25 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -46,16 +40,25 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
bgs.Initalize(params); bgs.Initalize(params);
bgs.InitModel(frame_data); bgs.InitModel(frame_data);
old_labeling = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
old = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
mrf.height = height; mrf.height = height;
mrf.width = width; mrf.width = width;
mrf.Build_Classes_OldLabeling_InImage_LocalEnergy(); mrf.Build_Classes_OldLabeling_InImage_LocalEnergy();
old_labeling = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
old = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
gmm = bgs.gmm();
hmm = bgs.hmm();
firstTime = false; firstTime = false;
} }
lowThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
lowThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
highThresholdMask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
highThresholdMask.Ptr()->origin = IPL_ORIGIN_BL;
bgs.Subtract(frameNumber, frame_data, lowThresholdMask, highThresholdMask); bgs.Subtract(frameNumber, frame_data, lowThresholdMask, highThresholdMask);
cvCopy(lowThresholdMask.Ptr(), old); cvCopy(lowThresholdMask.Ptr(), old);
...@@ -65,19 +68,18 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -65,19 +68,18 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
//the optimization process is done when the foreground detection is stable, //the optimization process is done when the foreground detection is stable,
if (frameNumber >= 10) if (frameNumber >= 10)
{ {
gmm = bgs.gmm();
hmm = bgs.hmm();
mrf.background2 = frame_data.Ptr(); mrf.background2 = frame_data.Ptr();
mrf.in_image = lowThresholdMask.Ptr(); mrf.in_image = lowThresholdMask.Ptr();
mrf.out_image = lowThresholdMask.Ptr(); mrf.out_image = lowThresholdMask.Ptr();
mrf.InitEvidence2(gmm, hmm, old_labeling); mrf.InitEvidence2(gmm, hmm, old_labeling);
// mrf.InitEvidence2(gmm, hmm, lowThresholdMask.Ptr());
mrf.ICM2(); mrf.ICM2();
cvCopy(mrf.out_image, lowThresholdMask.Ptr()); cvCopy(mrf.out_image, lowThresholdMask.Ptr());
} }
cvCopy(old, old_labeling); cvCopy(old, old_labeling);
lowThresholdMask.Clear(); // lowThresholdMask.Clear();
bgs.Update(frameNumber, frame_data, lowThresholdMask); bgs.Update(frameNumber, frame_data, lowThresholdMask);
img_foreground = cv::cvarrToMat(highThresholdMask.Ptr()); img_foreground = cv::cvarrToMat(highThresholdMask.Ptr());
...@@ -91,6 +93,9 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -91,6 +93,9 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
img_foreground.copyTo(img_output); img_foreground.copyTo(img_output);
img_background.copyTo(img_bgmodel); img_background.copyTo(img_bgmodel);
frame_data.ReleaseImage();
lowThresholdMask.ReleaseImage();
highThresholdMask.ReleaseImage();
frameNumber++; frameNumber++;
} }
......
...@@ -19,6 +19,8 @@ namespace bgslibrary ...@@ -19,6 +19,8 @@ namespace bgslibrary
float km; float km;
float kv; float kv;
int gaussians; int gaussians;
int width;
int height;
IplImage *old_labeling; IplImage *old_labeling;
IplImage *old; IplImage *old;
dp::RgbImage frame_data; dp::RgbImage frame_data;
......
...@@ -53,6 +53,9 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -53,6 +53,9 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
mrf.width = width; mrf.width = width;
mrf.Build_Classes_OldLabeling_InImage_LocalEnergy(); mrf.Build_Classes_OldLabeling_InImage_LocalEnergy();
gmm = bgs.gmm();
hmm = bgs.hmm();
firstTime = false; firstTime = false;
} }
...@@ -65,8 +68,6 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -65,8 +68,6 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
//the optimization process is done when the foreground detection is stable, //the optimization process is done when the foreground detection is stable,
if (frameNumber >= 10) if (frameNumber >= 10)
{ {
gmm = bgs.gmm();
hmm = bgs.hmm();
mrf.background2 = frame_data.Ptr(); mrf.background2 = frame_data.Ptr();
mrf.in_image = lowThresholdMask.Ptr(); mrf.in_image = lowThresholdMask.Ptr();
mrf.out_image = lowThresholdMask.Ptr(); mrf.out_image = lowThresholdMask.Ptr();
...@@ -91,6 +92,7 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & ...@@ -91,6 +92,7 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
img_foreground.copyTo(img_output); img_foreground.copyTo(img_output);
img_background.copyTo(img_bgmodel); img_background.copyTo(img_bgmodel);
frame_data.ReleaseImage();
frameNumber++; frameNumber++;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment