0

这是我的代码:

void Init()  // For the first frame.
{
    Mat in=cv::imread("img1.jpg");
    SIFT* s=NULL;
    vector< cv::KeyPoint > key;key.clear();
    Mat* descriptors=NULL;
    _CrtMemState Sh1,Sh2,Sh_Diff;
    _CrtMemCheckpoint(&Sh1);
    s = new SIFT();
    descriptors = new Mat();
    (*s)(in, Mat(), key, *descriptors);
    delete s;
    _CrtMemCheckpoint(&Sh2);
    _CrtMemDifference(&Sh_Diff, &Sh1, &Sh2); 
    _CrtMemDumpAllObjectsSince(&Sh_Diff);

    GetKCent(*descriptors);key.clear();
    mask=cv::Scalar(0);
    mask(selection)=cv::Scalar(255);
    Mat mask(in.rows,in.cols,CV_8U);
    s=new SIFT();
    if (descriptors!=NULL) delete descriptors;
    descriptors = new Mat();
    (*s)(in,mask,key,*descriptors);
    delete s;
}

程序执行此行时出现内存不足错误

(*s)(in,mask,key,*descriptors);

它是第二个 sift::operator()。我认为内存可能会泄漏。谁能帮我?

4

1 回答 1

0

我相信您的 opencv 版本是 2.4.4 或更高版本。我在使用 opencv 2.4.7 和 2.4.8 时遇到了同样的问题。然后我回到 2.4.3,一切顺利。我相信这是最近的opencv的一个错误。

于 2014-01-14T04:24:41.100 回答