简体   繁体   English

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

[英]Opencv Error: Insufficient memory(Failled to allocated) when I use the sift()

Here is my code: 这是我的代码:

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;
}

The insufficient memory error occured when the program execute this line 程序执行此行时发生内存不足错误

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

It is the second sift::operator(). 这是第二个sift :: operator()。 I think the memory may leak. 我认为内存可能会泄漏。 Who can help me? 谁能帮我?

I believe your opencv version is 2.4.4 or later. 我相信您的opencv版本是2.4.4或更高版本。 I encounter the same problem using opencv 2.4.7 and 2.4.8. 我在使用opencv 2.4.7和2.4.8时遇到相同的问题。 Then I go back to 2.4.3 and everything goes well. 然后我回到2.4.3,一切顺利。 I believe it is a bug with recent opencv. 我相信这是最近的opencv的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM