From 47fb5eb047df3dfff3a3ca07de71879b22a22b67 Mon Sep 17 00:00:00 2001 From: Andrews Cordolino Sobral <andrewssobral@gmail.com> Date: Sun, 17 Jul 2022 16:08:05 +0200 Subject: [PATCH] Final fixes for OpenCV >= 3.4.7 (cherry picked from commit 32e6d72b4377fb7e376029cf2b747b827138e7a4) --- examples/Demo2.cpp | 1 + src/algorithms/DPAdaptiveMedian.cpp | 10 +++----- src/algorithms/DPAdaptiveMedian.h | 1 - src/algorithms/DPEigenbackground.cpp | 8 ++----- src/algorithms/DPEigenbackground.h | 1 - src/algorithms/DPGrimsonGMM.cpp | 8 ++----- src/algorithms/DPMean.cpp | 8 ++----- src/algorithms/DPPratiMediod.cpp | 8 ++----- src/algorithms/DPTexture.cpp | 5 ++-- src/algorithms/DPWrenGA.cpp | 8 ++----- src/algorithms/DPZivkovicAGMM.cpp | 8 ++----- src/algorithms/FuzzyChoquetIntegral.cpp | 20 ++++++++-------- src/algorithms/FuzzySugenoIntegral.cpp | 20 ++++++++-------- src/algorithms/IMBS/IMBS.cpp | 6 ++--- src/algorithms/IMBS/IMBS.hpp | 4 ++-- src/algorithms/KNN.cpp | 23 +++++-------------- src/algorithms/KNN.h | 4 ---- src/algorithms/LBAdaptiveSOM.cpp | 9 ++++---- src/algorithms/LBFuzzyAdaptiveSOM.cpp | 9 ++++---- src/algorithms/LBFuzzyGaussian.cpp | 9 ++++---- src/algorithms/LBMixtureOfGaussians.cpp | 9 ++++---- src/algorithms/LBSimpleGaussian.cpp | 9 ++++---- src/algorithms/MultiCue.cpp | 22 ++++++++++-------- src/algorithms/MultiLayer.cpp | 10 ++++---- src/algorithms/MultiLayer/CMultiLayerBGS.cpp | 19 ++++++++------- .../MultiLayer/LocalBinaryPattern.cpp | 2 +- src/algorithms/T2FGMM_UM.cpp | 7 ++---- src/algorithms/T2FGMM_UV.cpp | 7 ++---- src/algorithms/T2FMRF_UM.cpp | 7 ++---- src/algorithms/T2FMRF_UV.cpp | 7 ++---- src/algorithms/VuMeter.cpp | 14 +++++++---- 31 files changed, 115 insertions(+), 168 deletions(-) diff --git a/examples/Demo2.cpp b/examples/Demo2.cpp index 8b4f698..2c4b8ad 100644 --- a/examples/Demo2.cpp +++ b/examples/Demo2.cpp @@ -63,6 +63,7 @@ int main(int argc, char **argv) { std::cout << "Exception occurred" << std::endl; std::cout << e.what() << std::endl; + break; } key = cv::waitKey(33); diff --git a/src/algorithms/DPAdaptiveMedian.cpp b/src/algorithms/DPAdaptiveMedian.cpp index e121bdf..e6fd808 100644 --- a/src/algorithms/DPAdaptiveMedian.cpp +++ b/src/algorithms/DPAdaptiveMedian.cpp @@ -21,11 +21,8 @@ void DPAdaptiveMedian::process(const cv::Mat &img_input, cv::Mat &img_output, cv { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -52,7 +49,7 @@ void DPAdaptiveMedian::process(const cv::Mat &img_input, cv::Mat &img_output, cv bgs.Update(frameNumber, frame_data, lowThresholdMask); img_foreground = cv::cvarrToMat(highThresholdMask.Ptr()); - //bitwise_not(img_foreground, img_foreground); + // bitwise_not(img_foreground, img_foreground); img_background = cv::cvarrToMat(bgs.Background()->Ptr()); #ifndef MEX_COMPILE_FLAG @@ -65,7 +62,6 @@ void DPAdaptiveMedian::process(const cv::Mat &img_input, cv::Mat &img_output, cv img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPAdaptiveMedian.h b/src/algorithms/DPAdaptiveMedian.h index fbad2da..9d00cea 100644 --- a/src/algorithms/DPAdaptiveMedian.h +++ b/src/algorithms/DPAdaptiveMedian.h @@ -17,7 +17,6 @@ namespace bgslibrary int threshold; int samplingRate; int learningFrames; - IplImage* frame; dp::RgbImage frame_data; dp::AdaptiveMedianParams params; dp::AdaptiveMedianBGS bgs; diff --git a/src/algorithms/DPEigenbackground.cpp b/src/algorithms/DPEigenbackground.cpp index dfc7d64..2627cdc 100644 --- a/src/algorithms/DPEigenbackground.cpp +++ b/src/algorithms/DPEigenbackground.cpp @@ -21,11 +21,8 @@ void DPEigenbackground::process(const cv::Mat &img_input, cv::Mat &img_output, c { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -65,7 +62,6 @@ void DPEigenbackground::process(const cv::Mat &img_input, cv::Mat &img_output, c img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPEigenbackground.h b/src/algorithms/DPEigenbackground.h index 0d9b18d..6db3de4 100644 --- a/src/algorithms/DPEigenbackground.h +++ b/src/algorithms/DPEigenbackground.h @@ -18,7 +18,6 @@ namespace bgslibrary int threshold; int historySize; int embeddedDim; - IplImage* frame; dp::RgbImage frame_data; dp::EigenbackgroundParams params; dp::Eigenbackground bgs; diff --git a/src/algorithms/DPGrimsonGMM.cpp b/src/algorithms/DPGrimsonGMM.cpp index 743acf1..3febe64 100644 --- a/src/algorithms/DPGrimsonGMM.cpp +++ b/src/algorithms/DPGrimsonGMM.cpp @@ -21,11 +21,8 @@ void DPGrimsonGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Ma { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -64,7 +61,6 @@ void DPGrimsonGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Ma img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPMean.cpp b/src/algorithms/DPMean.cpp index 18320cd..673e9df 100644 --- a/src/algorithms/DPMean.cpp +++ b/src/algorithms/DPMean.cpp @@ -21,11 +21,8 @@ void DPMean::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -64,7 +61,6 @@ void DPMean::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPPratiMediod.cpp b/src/algorithms/DPPratiMediod.cpp index 3cade20..12ea039 100644 --- a/src/algorithms/DPPratiMediod.cpp +++ b/src/algorithms/DPPratiMediod.cpp @@ -21,11 +21,8 @@ void DPPratiMediod::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -65,7 +62,6 @@ void DPPratiMediod::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPTexture.cpp b/src/algorithms/DPTexture.cpp index 7f58230..0959339 100644 --- a/src/algorithms/DPTexture.cpp +++ b/src/algorithms/DPTexture.cpp @@ -29,7 +29,8 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { width = img_input.size().width; @@ -112,8 +113,6 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & // update background subtraction bgs.UpdateModel(fgMask, bgModel, curTextureHist, modeArray); - - delete frame; } void DPTexture::save_config(cv::FileStorage &fs) { diff --git a/src/algorithms/DPWrenGA.cpp b/src/algorithms/DPWrenGA.cpp index a7f9128..971e4d4 100644 --- a/src/algorithms/DPWrenGA.cpp +++ b/src/algorithms/DPWrenGA.cpp @@ -21,11 +21,8 @@ void DPWrenGA::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -63,7 +60,6 @@ void DPWrenGA::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/DPZivkovicAGMM.cpp b/src/algorithms/DPZivkovicAGMM.cpp index 289f5cc..1d2efbe 100644 --- a/src/algorithms/DPZivkovicAGMM.cpp +++ b/src/algorithms/DPZivkovicAGMM.cpp @@ -21,11 +21,8 @@ void DPZivkovicAGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv:: { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -63,7 +60,6 @@ void DPZivkovicAGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv:: img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/FuzzyChoquetIntegral.cpp b/src/algorithms/FuzzyChoquetIntegral.cpp index 90dfe6e..808c874 100644 --- a/src/algorithms/FuzzyChoquetIntegral.cpp +++ b/src/algorithms/FuzzyChoquetIntegral.cpp @@ -73,10 +73,17 @@ void FuzzyChoquetIntegral::process(const cv::Mat &img_input, cv::Mat &img_output cv::Mat img_background_f1; cv::cvtColor(img_background_f3, img_background_f1, CV_BGR2GRAY); - IplImage* input_f3 = new IplImage(img_input_f3); - IplImage* input_f1 = new IplImage(img_input_f1); - IplImage* background_f3 = new IplImage(img_background_f3); - IplImage* background_f1 = new IplImage(img_background_f1); + IplImage _input_f3 = cvIplImage(img_input_f3); + IplImage* input_f3 = cvCloneImage(&(IplImage)_input_f3); + + IplImage _input_f1 = cvIplImage(img_input_f1); + IplImage* input_f1 = cvCloneImage(&(IplImage)_input_f1); + + IplImage _background_f3 = cvIplImage(img_background_f3); + IplImage* background_f3 = cvCloneImage(&(IplImage)_background_f3); + + IplImage _background_f1 = cvIplImage(img_background_f1); + IplImage* background_f1 = cvCloneImage(&(IplImage)_background_f1); IplImage* lbp_input_f1 = cvCreateImage(cvSize(input_f1->width, input_f1->height), IPL_DEPTH_32F, 1); cvSetZero(lbp_input_f1); @@ -151,11 +158,6 @@ void FuzzyChoquetIntegral::process(const cv::Mat &img_input, cv::Mat &img_output cvReleaseImage(&sim_color_f3); cvReleaseImage(&integral_choquet_f1); cvReleaseImage(&updated_background_f3); - - delete background_f1; - delete background_f3; - delete input_f1; - delete input_f3; } firstTime = false; diff --git a/src/algorithms/FuzzySugenoIntegral.cpp b/src/algorithms/FuzzySugenoIntegral.cpp index 5ac009a..6043d98 100644 --- a/src/algorithms/FuzzySugenoIntegral.cpp +++ b/src/algorithms/FuzzySugenoIntegral.cpp @@ -72,10 +72,17 @@ void FuzzySugenoIntegral::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat img_background_f1; cv::cvtColor(img_background_f3, img_background_f1, CV_BGR2GRAY); - IplImage* input_f3 = new IplImage(img_input_f3); - IplImage* input_f1 = new IplImage(img_input_f1); - IplImage* background_f3 = new IplImage(img_background_f3); - IplImage* background_f1 = new IplImage(img_background_f1); + IplImage _input_f3 = cvIplImage(img_input_f3); + IplImage* input_f3 = cvCloneImage(&(IplImage)_input_f3); + + IplImage _input_f1 = cvIplImage(img_input_f1); + IplImage* input_f1 = cvCloneImage(&(IplImage)_input_f1); + + IplImage _background_f3 = cvIplImage(img_background_f3); + IplImage* background_f3 = cvCloneImage(&(IplImage)_background_f3); + + IplImage _background_f1 = cvIplImage(img_background_f1); + IplImage* background_f1 = cvCloneImage(&(IplImage)_background_f1); IplImage* lbp_input_f1 = cvCreateImage(cvSize(input_f1->width, input_f1->height), IPL_DEPTH_32F, 1); cvSetZero(lbp_input_f1); @@ -150,11 +157,6 @@ void FuzzySugenoIntegral::process(const cv::Mat &img_input, cv::Mat &img_output, cvReleaseImage(&sim_color_f3); cvReleaseImage(&integral_sugeno_f1); cvReleaseImage(&updated_background_f3); - - delete background_f1; - delete background_f3; - delete input_f1; - delete input_f3; } firstTime = false; diff --git a/src/algorithms/IMBS/IMBS.cpp b/src/algorithms/IMBS/IMBS.cpp index bab74da..e808176 100644 --- a/src/algorithms/IMBS/IMBS.cpp +++ b/src/algorithms/IMBS/IMBS.cpp @@ -9,7 +9,7 @@ BackgroundSubtractorIMBS::BackgroundSubtractorIMBS() fps = 0.; fgThreshold = 15; associationThreshold = 5; - samplingPeriod = 250;//500.ms + samplingPeriod = 50;//500.ms minBinHeight = 2; numSamples = 10; //30 alpha = 0.65f; @@ -410,7 +410,7 @@ void BackgroundSubtractorIMBS::createBg(unsigned int bg_sample_number) { bg_reset = false; if (sudden_change) { - numSamples *= 3.; + numSamples *= 2.; samplingPeriod *= 2.; sudden_change = false; } @@ -699,7 +699,7 @@ void BackgroundSubtractorIMBS::changeBg() { //cout << "qua" << endl; if (!bg_reset) { - numSamples /= 3.; + numSamples /= 2.; samplingPeriod /= 2.; bg_frame_counter = 0; bg_reset = true; diff --git a/src/algorithms/IMBS/IMBS.hpp b/src/algorithms/IMBS/IMBS.hpp index d17f051..3f86660 100644 --- a/src/algorithms/IMBS/IMBS.hpp +++ b/src/algorithms/IMBS/IMBS.hpp @@ -29,9 +29,9 @@ namespace bgslibrary BackgroundSubtractorIMBS(double fps, unsigned int fgThreshold = 15, unsigned int associationThreshold = 5, - double samplingPeriod = 500., + double samplingPeriod = 50., unsigned int minBinHeight = 2, - unsigned int numSamples = 30, + unsigned int numSamples = 10, double alpha = 0.65, double beta = 1.15, double tau_s = 60., diff --git a/src/algorithms/KNN.cpp b/src/algorithms/KNN.cpp index 3327094..33f5cd0 100644 --- a/src/algorithms/KNN.cpp +++ b/src/algorithms/KNN.cpp @@ -6,9 +6,7 @@ using namespace bgslibrary::algorithms; KNN::KNN() : IBGS(quote(KNN)), - history(500), nSamples(7), dist2Threshold(20.0f * 20.0f), - knnSamples(0), doShadowDetection(true), shadowValue(127), - shadowThreshold(0.5f) + history(10), dist2Threshold(20.0f * 20.0f), shadowThreshold(0.5f) { debug_construction(KNN); initLoadSaveConfig(algorithmName); @@ -35,16 +33,15 @@ void KNN::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bg // Fast for small foreground object. Results on the benchmark data is at http://www.changedetection.net. //------------------------------------------------------------------ - int prevNSamples = nSamples; if (firstTime) - knn = cv::createBackgroundSubtractorKNN(history, dist2Threshold, doShadowDetection); + knn = cv::createBackgroundSubtractorKNN(); // history, dist2Threshold, doShadowDetection - knn->setNSamples(nSamples); - knn->setkNNSamples(knnSamples); - knn->setShadowValue(shadowValue); + knn->setHistory(history); + knn->setDist2Threshold(dist2Threshold); knn->setShadowThreshold(shadowThreshold); - knn->apply(img_input, img_foreground, prevNSamples != nSamples ? 0.f : 1.f); + //knn->apply(img_input, img_foreground, nSamples >= knnSamples ? 0.f : 1.f); + knn->apply(img_input, img_foreground); knn->getBackgroundImage(img_background); #ifndef MEX_COMPILE_FLAG @@ -62,22 +59,14 @@ void KNN::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bg void KNN::save_config(cv::FileStorage &fs) { fs << "history" << history; - fs << "nSamples" << nSamples; fs << "dist2Threshold" << dist2Threshold; - fs << "knnSamples" << knnSamples; - fs << "doShadowDetection" << doShadowDetection; - fs << "shadowValue" << shadowValue; fs << "shadowThreshold" << shadowThreshold; fs << "showOutput" << showOutput; } void KNN::load_config(cv::FileStorage &fs) { fs["history"] >> history; - fs["nSamples"] >> nSamples; fs["dist2Threshold"] >> dist2Threshold; - fs["knnSamples"] >> knnSamples; - fs["doShadowDetection"] >> doShadowDetection; - fs["shadowValue"] >> shadowValue; fs["shadowThreshold"] >> shadowThreshold; fs["showOutput"] >> showOutput; } diff --git a/src/algorithms/KNN.h b/src/algorithms/KNN.h index 6950472..4bc986a 100644 --- a/src/algorithms/KNN.h +++ b/src/algorithms/KNN.h @@ -19,11 +19,7 @@ namespace bgslibrary private: cv::Ptr<cv::BackgroundSubtractorKNN> knn; int history; - int nSamples; float dist2Threshold; - int knnSamples; - bool doShadowDetection; - int shadowValue; float shadowThreshold; public: diff --git a/src/algorithms/LBAdaptiveSOM.cpp b/src/algorithms/LBAdaptiveSOM.cpp index b051ed5..76efbc1 100644 --- a/src/algorithms/LBAdaptiveSOM.cpp +++ b/src/algorithms/LBAdaptiveSOM.cpp @@ -23,11 +23,12 @@ void LBAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M { init(img_input, img_output, img_bgmodel); - IplImage *frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { - int w = cvGetSize(frame).width; - int h = cvGetSize(frame).height; + int w = img_input.size().width; + int h = img_input.size().height; m_pBGModel = new lb::BGModelSom(w, h); m_pBGModel->InitModel(frame); @@ -54,8 +55,6 @@ void LBAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; - firstTime = false; } diff --git a/src/algorithms/LBFuzzyAdaptiveSOM.cpp b/src/algorithms/LBFuzzyAdaptiveSOM.cpp index a4feed6..8fb0ccb 100644 --- a/src/algorithms/LBFuzzyAdaptiveSOM.cpp +++ b/src/algorithms/LBFuzzyAdaptiveSOM.cpp @@ -22,11 +22,12 @@ void LBFuzzyAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, { init(img_input, img_output, img_bgmodel); - IplImage *frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { - int w = cvGetSize(frame).width; - int h = cvGetSize(frame).height; + int w = img_input.size().width; + int h = img_input.size().height; m_pBGModel = new lb::BGModelFuzzySom(w, h); m_pBGModel->InitModel(frame); @@ -53,8 +54,6 @@ void LBFuzzyAdaptiveSOM::process(const cv::Mat &img_input, cv::Mat &img_output, img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; - firstTime = false; } diff --git a/src/algorithms/LBFuzzyGaussian.cpp b/src/algorithms/LBFuzzyGaussian.cpp index c501848..e175d59 100644 --- a/src/algorithms/LBFuzzyGaussian.cpp +++ b/src/algorithms/LBFuzzyGaussian.cpp @@ -22,11 +22,12 @@ void LBFuzzyGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv: { init(img_input, img_output, img_bgmodel); - IplImage *frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { - int w = cvGetSize(frame).width; - int h = cvGetSize(frame).height; + int w = img_input.size().width; + int h = img_input.size().height; m_pBGModel = new lb::BGModelFuzzyGauss(w, h); m_pBGModel->InitModel(frame); @@ -52,8 +53,6 @@ void LBFuzzyGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv: img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; - firstTime = false; } diff --git a/src/algorithms/LBMixtureOfGaussians.cpp b/src/algorithms/LBMixtureOfGaussians.cpp index 219cd1b..d949adb 100644 --- a/src/algorithms/LBMixtureOfGaussians.cpp +++ b/src/algorithms/LBMixtureOfGaussians.cpp @@ -22,11 +22,12 @@ void LBMixtureOfGaussians::process(const cv::Mat &img_input, cv::Mat &img_output { init(img_input, img_output, img_bgmodel); - IplImage *frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { - int w = cvGetSize(frame).width; - int h = cvGetSize(frame).height; + int w = img_input.size().width; + int h = img_input.size().height; m_pBGModel = new lb::BGModelMog(w, h); m_pBGModel->InitModel(frame); @@ -52,8 +53,6 @@ void LBMixtureOfGaussians::process(const cv::Mat &img_input, cv::Mat &img_output img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; - firstTime = false; } diff --git a/src/algorithms/LBSimpleGaussian.cpp b/src/algorithms/LBSimpleGaussian.cpp index 6586833..6764119 100644 --- a/src/algorithms/LBSimpleGaussian.cpp +++ b/src/algorithms/LBSimpleGaussian.cpp @@ -21,11 +21,12 @@ void LBSimpleGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv { init(img_input, img_output, img_bgmodel); - IplImage *frame = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { - int w = cvGetSize(frame).width; - int h = cvGetSize(frame).height; + int w = img_input.size().width; + int h = img_input.size().height; m_pBGModel = new lb::BGModelGauss(w, h); m_pBGModel->InitModel(frame); @@ -50,8 +51,6 @@ void LBSimpleGaussian::process(const cv::Mat &img_input, cv::Mat &img_output, cv img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; - firstTime = false; } diff --git a/src/algorithms/MultiCue.cpp b/src/algorithms/MultiCue.cpp index 72fbab1..8f7e0ac 100644 --- a/src/algorithms/MultiCue.cpp +++ b/src/algorithms/MultiCue.cpp @@ -73,26 +73,28 @@ void MultiCue::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i { init(img_input, img_output, img_bgmodel); - //--STep1: Background Modeling--// - //IplImage* frame = &IplImage(img_input); - IplImage* frame = new IplImage(img_input); - IplImage* result_image = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); + // Step 1: Background Modeling + IplImage _frame = cvIplImage(img_input); + IplImage* frame = cvCloneImage(&(IplImage)_frame); + + int width = img_input.size().width; + int height = img_input.size().height; + IplImage* result_image = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); cvSetZero(result_image); if (g_iFrameCount <= g_iTrainingPeriod) { BackgroundModeling_Par(frame); g_iFrameCount++; } - //--Step2: Background Subtraction--// + // Step 2: Background Subtraction else { g_bForegroundMapEnable = FALSE; ForegroundExtraction(frame); UpdateModel_Par(); - //Get BGS Results + // Get BGS Results GetForegroundMap(result_image, NULL); } - delete frame; img_background = cv::Mat::zeros(img_input.size(), img_input.type()); img_foreground = cv::cvarrToMat(result_image, TRUE); @@ -537,8 +539,9 @@ void MultiCue::GaussianFiltering(IplImage* frame, uchar*** aFilteredFrame) { cv::GaussianBlur(temp_img, temp_img, cv::Size(7, 7), dSigma); //Store results into aFilteredFrame[][][] - //IplImage* img = &IplImage(temp_img); - IplImage* img = new IplImage(temp_img); + IplImage _img = cvIplImage(temp_img); + IplImage* img = cvCloneImage(&(IplImage)_img); + //int iWidthStep = img->widthStep; for (int i = 0; i < g_iRHeight; i++) { @@ -548,7 +551,6 @@ void MultiCue::GaussianFiltering(IplImage* frame, uchar*** aFilteredFrame) { aFilteredFrame[i][j][2] = img->imageData[i*img->widthStep + j * 3 + 2]; } } - delete img; } } diff --git a/src/algorithms/MultiLayer.cpp b/src/algorithms/MultiLayer.cpp index 1914785..49ad0c5 100644 --- a/src/algorithms/MultiLayer.cpp +++ b/src/algorithms/MultiLayer.cpp @@ -57,8 +57,9 @@ void MultiLayer::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat if (status == MLBGS_DETECT) std::cout << algorithmName + " in DETECT mode" << std::endl; - - org_img = new IplImage(img_input); + + IplImage _frame = cvIplImage(img_input); + org_img = cvCloneImage(&(IplImage)_frame); fg_img = cvCreateImage(img_size, org_img->depth, org_img->nChannels); bg_img = cvCreateImage(img_size, org_img->depth, org_img->nChannels); @@ -156,7 +157,6 @@ void MultiLayer::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat } BGS->SetParameters(max_mode_num, mode_learn_rate_per_second, weight_learn_rate_per_second, init_mode_weight); - delete org_img; } //IplImage* inputImage = new IplImage(img_input); @@ -181,7 +181,8 @@ void MultiLayer::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat std::cout << algorithmName + " enabled learning in DETECT mode" << std::endl; } - IplImage* img = new IplImage(img_input); + IplImage _frame = cvIplImage(img_input); + IplImage* img = cvCloneImage(&(IplImage)_frame); BGS->SetRGBInputImage(img); BGS->Process(); @@ -206,7 +207,6 @@ void MultiLayer::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete img; //cvReleaseImage(&img); firstTime = false; diff --git a/src/algorithms/MultiLayer/CMultiLayerBGS.cpp b/src/algorithms/MultiLayer/CMultiLayerBGS.cpp index 481f416..b295216 100644 --- a/src/algorithms/MultiLayer/CMultiLayerBGS.cpp +++ b/src/algorithms/MultiLayer/CMultiLayerBGS.cpp @@ -167,7 +167,7 @@ void CMultiLayerBGS::MergeImages(int num, ...) { va_end(arg_ptr); CvRect imgROIRect; - CvSize imgSize = cvGetSize(ppIplImg[0]); + CvSize imgSize = cvSize(ppIplImg[0]->width, ppIplImg[0]->height); if (ppIplImg[num] == NULL) { // for the output video ppIplImg[num] = cvCreateImage(cvSize(imgSize.width*nCols, imgSize.height * nRows), IPL_DEPTH_8U, ppIplImg[0]->nChannels); } @@ -321,7 +321,7 @@ void CMultiLayerBGS::SetNewImage(IplImage *new_img, CvRect *roi) { void CMultiLayerBGS::SetBkMaskImage(IplImage *mask_img) { if (m_pBkMaskImg == NULL) { - m_pBkMaskImg = cvCreateImage(cvGetSize(mask_img), mask_img->depth, mask_img->nChannels); + m_pBkMaskImg = cvCreateImage(cvSize(mask_img->width, mask_img->height), mask_img->depth, mask_img->nChannels); } cvCopy(mask_img, m_pBkMaskImg); } @@ -859,7 +859,7 @@ void CMultiLayerBGS::Initialization(IplImage *first_img, int lbp_level_num, floa m_ppOrgLBPImgs = NULL; m_pFgProbImg = NULL; - m_cvImgSize = cvGetSize(first_img); + m_cvImgSize = cvSize(first_img->width, first_img->height); m_nChannel = first_img->nChannels; @@ -962,9 +962,8 @@ void CMultiLayerBGS::ComputeGradientImage(IplImage *src, IplImage *dst, bool bIs } int a; - - IplImage* _dX = cvCreateImage(cvGetSize(dst), IPL_DEPTH_16S, 1); - IplImage* _dY = cvCreateImage(cvGetSize(dst), IPL_DEPTH_16S, 1); + IplImage* _dX = cvCreateImage(cvSize(dst->width, dst->height), IPL_DEPTH_16S, 1); + IplImage* _dY = cvCreateImage(cvSize(dst->width, dst->height), IPL_DEPTH_16S, 1); int aperture_size = 3; @@ -1284,10 +1283,10 @@ void CMultiLayerBGS::GetCurrentLayeredBackgroundImage(int layered_no, IplImage * } COpencvDataConversion<float, float> ODC; - IplImage* bg_layer_float_mask_img = cvCreateImage(cvGetSize(m_pOrgImg), IPL_DEPTH_32F, 1); - IplImage* bg_layer_low_mask_img = cvCreateImage(cvGetSize(m_pOrgImg), IPL_DEPTH_8U, 1); - IplImage* bg_layer_high_mask_img = cvCreateImage(cvGetSize(m_pOrgImg), IPL_DEPTH_8U, 1); - IplImage* bg_layer_mask_img = cvCreateImage(cvGetSize(m_pOrgImg), IPL_DEPTH_8U, 1); + IplImage* bg_layer_float_mask_img = cvCreateImage(cvSize(m_pOrgImg->width, m_pOrgImg->height), IPL_DEPTH_32F, 1); + IplImage* bg_layer_low_mask_img = cvCreateImage(cvSize(m_pOrgImg->width, m_pOrgImg->height), IPL_DEPTH_8U, 1); + IplImage* bg_layer_high_mask_img = cvCreateImage(cvSize(m_pOrgImg->width, m_pOrgImg->height), IPL_DEPTH_8U, 1); + IplImage* bg_layer_mask_img = cvCreateImage(cvSize(m_pOrgImg->width, m_pOrgImg->height), IPL_DEPTH_8U, 1); ODC.SetImageData(bg_layer_float_mask_img, bg_layer_mask); diff --git a/src/algorithms/MultiLayer/LocalBinaryPattern.cpp b/src/algorithms/MultiLayer/LocalBinaryPattern.cpp index 89e5338..120e01d 100644 --- a/src/algorithms/MultiLayer/LocalBinaryPattern.cpp +++ b/src/algorithms/MultiLayer/LocalBinaryPattern.cpp @@ -27,7 +27,7 @@ void CLocalBinaryPattern::Initialization(IplImage **first_imgs, int imgs_num, in m_ppOrgImgs = first_imgs; int a, b; for (a = 0; a < m_nImgsNum; a++) { - m_cvImgSize = cvGetSize(first_imgs[a]); + m_cvImgSize = cvSize(first_imgs[a]->width, first_imgs[a]->height); if (first_imgs[a]->nChannels > 1) { printf("Input image channel must be 1!"); exit(1); diff --git a/src/algorithms/T2FGMM_UM.cpp b/src/algorithms/T2FGMM_UM.cpp index 7c95dfe..a3bff75 100644 --- a/src/algorithms/T2FGMM_UM.cpp +++ b/src/algorithms/T2FGMM_UM.cpp @@ -20,11 +20,9 @@ T2FGMM_UM::~T2FGMM_UM() { void T2FGMM_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel) { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -65,7 +63,6 @@ void T2FGMM_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/T2FGMM_UV.cpp b/src/algorithms/T2FGMM_UV.cpp index cff817b..c366f42 100644 --- a/src/algorithms/T2FGMM_UV.cpp +++ b/src/algorithms/T2FGMM_UV.cpp @@ -20,11 +20,9 @@ T2FGMM_UV::~T2FGMM_UV() { void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel) { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -65,7 +63,6 @@ void T2FGMM_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; frameNumber++; } diff --git a/src/algorithms/T2FMRF_UM.cpp b/src/algorithms/T2FMRF_UM.cpp index 208be5d..207ceab 100644 --- a/src/algorithms/T2FMRF_UM.cpp +++ b/src/algorithms/T2FMRF_UM.cpp @@ -20,11 +20,9 @@ T2FMRF_UM::~T2FMRF_UM() { void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel) { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -94,7 +92,6 @@ void T2FMRF_UM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; frameNumber++; } diff --git a/src/algorithms/T2FMRF_UV.cpp b/src/algorithms/T2FMRF_UV.cpp index c0a1c5f..ddfb9d7 100644 --- a/src/algorithms/T2FMRF_UV.cpp +++ b/src/algorithms/T2FMRF_UV.cpp @@ -20,11 +20,9 @@ T2FMRF_UV::~T2FMRF_UV() { void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel) { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); - if (firstTime) - frame_data.ReleaseMemory(false); - frame_data = frame; + IplImage _frame = cvIplImage(img_input); + frame_data = cvCloneImage(&(IplImage)_frame); if (firstTime) { int width = img_input.size().width; @@ -94,7 +92,6 @@ void T2FMRF_UV::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat & img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; frameNumber++; } diff --git a/src/algorithms/VuMeter.cpp b/src/algorithms/VuMeter.cpp index c83d6b8..bd84edf 100644 --- a/src/algorithms/VuMeter.cpp +++ b/src/algorithms/VuMeter.cpp @@ -23,20 +23,25 @@ VuMeter::~VuMeter() { void VuMeter::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img_bgmodel) { init(img_input, img_output, img_bgmodel); - frame = new IplImage(img_input); + + IplImage _frame = cvIplImage(img_input); + frame = cvCloneImage(&(IplImage)_frame); if (firstTime) { + int w = img_input.size().width; + int h = img_input.size().height; + bgs.SetAlpha(alpha); bgs.SetBinSize(binSize); bgs.SetThreshold(threshold); - gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1); + gray = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1); cvCvtColor(frame, gray, CV_RGB2GRAY); - background = cvCreateImage(cvGetSize(gray), IPL_DEPTH_8U, 1); + background = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1); cvCopy(gray, background); - mask = cvCreateImage(cvGetSize(gray), IPL_DEPTH_8U, 1); + mask = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1); cvZero(mask); } else @@ -61,7 +66,6 @@ void VuMeter::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &im img_foreground.copyTo(img_output); img_background.copyTo(img_bgmodel); - delete frame; firstTime = false; } -- GitLab