From ada571b679a6de88fc3ffdbee71f5b2430de14a4 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Thu, 10 Apr 2014 18:07:34 +0000 Subject: [PATCH] fixed a memory leak when no features are extracted from the scene git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@204 620bd6b2-0a58-f614-fd9a-1bd335dccda9 --- src/MainWindow.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ed1747ce..dc0b5246 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -18,6 +18,7 @@ #include #include "opencv2/calib3d/calib3d.hpp" +#include "opencv2/imgproc/imgproc.hpp" #include #include @@ -1038,32 +1039,24 @@ void MainWindow::update(const cv::Mat & image) if(!image.empty()) { - IplImage iplImage = image; - QTime time; time.start(); //Convert to grayscale - IplImage * imageGrayScale = 0; - if(iplImage.nChannels != 1 || iplImage.depth != IPL_DEPTH_8U) + cv::Mat grayscaleImg; + if(image.channels() != 1 || image.depth() != CV_8U) { - imageGrayScale = cvCreateImage(cvSize(iplImage.width,iplImage.height), IPL_DEPTH_8U, 1); - cvCvtColor(&iplImage, imageGrayScale, CV_BGR2GRAY); - } - cv::Mat img; - if(imageGrayScale) - { - img = cv::Mat(imageGrayScale); + cv::cvtColor(image, grayscaleImg, cv::COLOR_BGR2GRAY); } else { - img = cv::Mat(&iplImage); + grayscaleImg = image; } // EXTRACT KEYPOINTS cv::FeatureDetector * detector = Settings::createFeaturesDetector(); std::vector keypoints; - detector->detect(img, keypoints); + detector->detect(grayscaleImg, keypoints); delete detector; ui_->label_timeDetection->setNum(time.restart()); @@ -1072,16 +1065,12 @@ void MainWindow::update(const cv::Mat & image) { // EXTRACT DESCRIPTORS cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor(); - extractor->compute(img, keypoints, descriptors); + extractor->compute(grayscaleImg, keypoints, descriptors); delete extractor; if((int)keypoints.size() != descriptors.rows) { printf("ERROR : kpt=%d != descriptors=%d\n", (int)keypoints.size(), descriptors.rows); } - if(imageGrayScale) - { - cvReleaseImage(&imageGrayScale); - } ui_->label_timeExtraction->setNum(time.restart()); } else @@ -1092,7 +1081,7 @@ void MainWindow::update(const cv::Mat & image) if(this->isVisible()) { - ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage, Settings::currentDetectorType(), Settings::currentDescriptorType()); + ui_->imageView_source->setData(keypoints, cv::Mat(), image, Settings::currentDetectorType(), Settings::currentDescriptorType()); } // COMPARE @@ -1377,7 +1366,7 @@ void MainWindow::update(const cv::Mat & image) } else if(this->isVisible()) { - ui_->imageView_source->setData(keypoints, cv::Mat(), &iplImage, Settings::currentDetectorType(), Settings::currentDescriptorType()); + ui_->imageView_source->setData(keypoints, cv::Mat(), image, Settings::currentDetectorType(), Settings::currentDescriptorType()); } if(this->isVisible())