Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 318
Seb Avatar asked Apr 15 '26 10:04

Seb


1 Answers

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.

like image 109
karlphillip Avatar answered Apr 17 '26 23:04

karlphillip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!