Seb
Seb

Reputation: 3564

SiftDescriptorExtractor causes a memory leak

I am currently implementing SIFT to extract feature points from an image and noticed that I have a memory leak when I get the descriptors. Is there anyway I can free the memory that may be attached in the class?

EDIT Added more details to the code block

cv::SiftFeatureDetector* features = new cv::SiftFeatureDetector();
cv::SiftDescriptorExtractor* extractor = new cv::SiftDescriptorExtractor();

std::vector<cv::KeyPoint> KeyPoints;
cv::Mat Descriptors;

// Turn the image into a Mat
cv::Mat mImage = cv::Mat(iplImage);

printf("Searching for keypoints in: %s.\n", szName.c_str());

// Detect keypoints
features->detect(mImage, KeyPoints);

printf("Found %d keypoints.\n", KeyPoints.size());

// Extract descriptors
extractor->compute(mImage, KeyPoints, Descriptors);

printf("Found %d descriptors.\n\n", Descriptors.rows);

// Let my memory go!
delete extractor;
delete features;

Any advice is greatly appreciated. Thanks.

Upvotes: 3

Views: 1227

Answers (2)

BloodAxe
BloodAxe

Reputation: 833

Working with 2.3 too and also experience memory leaks with SiftDescriptorExtractor. However the other descriptor extractors does not have this issue. I suggest to create a ticket in the bugtracker to inform the developers.

Upvotes: 0

karlphillip
karlphillip

Reputation: 93468

You are right. I just tested on Linux with OpenCV 2.3 and there's a memory leak on compute() indeed. This affects SiftDescriptorExtractor, and probably other types too, like SurfDescriptorExtractor, OrbDescriptorExtractor and BriefDescriptorExtractor.

By the way, don't forget to cvReleaseImage() the image you call iplImage at the end of this code.

Upvotes: 1

Related Questions