简体   繁体   中英

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(). I think the memory may leak. Who can help me?

I believe your opencv version is 2.4.4 or later. I encounter the same problem using opencv 2.4.7 and 2.4.8. Then I go back to 2.4.3 and everything goes well. I believe it is a bug with recent opencv.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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