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
This commit is contained in:
parent
065ad88ea8
commit
ada571b679
@ -18,6 +18,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "opencv2/calib3d/calib3d.hpp"
|
#include "opencv2/calib3d/calib3d.hpp"
|
||||||
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
|
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
@ -1038,32 +1039,24 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
|
|
||||||
if(!image.empty())
|
if(!image.empty())
|
||||||
{
|
{
|
||||||
IplImage iplImage = image;
|
|
||||||
|
|
||||||
QTime time;
|
QTime time;
|
||||||
time.start();
|
time.start();
|
||||||
|
|
||||||
//Convert to grayscale
|
//Convert to grayscale
|
||||||
IplImage * imageGrayScale = 0;
|
cv::Mat grayscaleImg;
|
||||||
if(iplImage.nChannels != 1 || iplImage.depth != IPL_DEPTH_8U)
|
if(image.channels() != 1 || image.depth() != CV_8U)
|
||||||
{
|
{
|
||||||
imageGrayScale = cvCreateImage(cvSize(iplImage.width,iplImage.height), IPL_DEPTH_8U, 1);
|
cv::cvtColor(image, grayscaleImg, cv::COLOR_BGR2GRAY);
|
||||||
cvCvtColor(&iplImage, imageGrayScale, CV_BGR2GRAY);
|
|
||||||
}
|
|
||||||
cv::Mat img;
|
|
||||||
if(imageGrayScale)
|
|
||||||
{
|
|
||||||
img = cv::Mat(imageGrayScale);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
img = cv::Mat(&iplImage);
|
grayscaleImg = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXTRACT KEYPOINTS
|
// EXTRACT KEYPOINTS
|
||||||
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
|
cv::FeatureDetector * detector = Settings::createFeaturesDetector();
|
||||||
std::vector<cv::KeyPoint> keypoints;
|
std::vector<cv::KeyPoint> keypoints;
|
||||||
detector->detect(img, keypoints);
|
detector->detect(grayscaleImg, keypoints);
|
||||||
delete detector;
|
delete detector;
|
||||||
ui_->label_timeDetection->setNum(time.restart());
|
ui_->label_timeDetection->setNum(time.restart());
|
||||||
|
|
||||||
@ -1072,16 +1065,12 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
{
|
{
|
||||||
// EXTRACT DESCRIPTORS
|
// EXTRACT DESCRIPTORS
|
||||||
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor();
|
cv::DescriptorExtractor * extractor = Settings::createDescriptorsExtractor();
|
||||||
extractor->compute(img, keypoints, descriptors);
|
extractor->compute(grayscaleImg, keypoints, descriptors);
|
||||||
delete extractor;
|
delete extractor;
|
||||||
if((int)keypoints.size() != descriptors.rows)
|
if((int)keypoints.size() != descriptors.rows)
|
||||||
{
|
{
|
||||||
printf("ERROR : kpt=%d != descriptors=%d\n", (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());
|
ui_->label_timeExtraction->setNum(time.restart());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1092,7 +1081,7 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
|
|
||||||
if(this->isVisible())
|
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
|
// COMPARE
|
||||||
@ -1377,7 +1366,7 @@ void MainWindow::update(const cv::Mat & image)
|
|||||||
}
|
}
|
||||||
else if(this->isVisible())
|
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())
|
if(this->isVisible())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user