我正在使用OpenCV函数:cvExtractSURF
,但是发现主要的内存泄漏。有人成功实现了此通话吗?
我的代码如下:
IplImage *cvImage = [self CreateIplImageFromUIImage:image grayscale:YES];
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq *objectKeypoints = 0;
//CvSeq *objectDescriptors = 0;
CvSURFParams params = cvSURFParams(self.hessianThreshold, 0);
double tt = (double)cvGetTickCount();
//Extract the features
cvExtractSURF( cvImage, 0, &objectKeypoints, NULL, storage, params, 0);
tt = (double)cvGetTickCount() - tt;
//NSLog(@"%d features found in %gms seconds\n", objectKeypoints->total, tt/(cvGetTickFrequency()*1000.));
cvReleaseImage(&cvImage);
cvReleaseMemStorage(&storage);
有什么想法可能会泄漏吗?当我注释掉该行时:
cvExtractSURF( cvImage, 0, &objectKeypoints, NULL, storage, params, 0);
没有泄漏发生。
最佳答案
函数cvExtractSURF创建一个CvSURFPoint类型的对象列表,并将指向它的指针放在objectKeypoints中。您必须释放它。
添加通话...
cvRelease((void **)&objectKeypoints);