Opencv错误:当我使用sift()时内存不足(无法分配)

时间:2013-06-23 11:56:31

标签: c++ visual-studio-2010 opencv sift

这是我的代码:

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()。我认为记忆可能会泄漏。谁能帮帮我?

1 个答案:

答案 0 :(得分:0)

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