Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I hope someone can help. I have been trying to work with SIFT and even the simplest program like this will cause a debug assertion failed.

C++
int DoSift()
{
    string image2 ="G:/SIFT Test/Foods/f1.jpg";
    string image1 ="G:/SIFT Test/Foods/f2.jpg";

    Mat input = imread(image1, IMREAD_GRAYSCALE );
    Mat img_2 = imread( image2, IMREAD_GRAYSCALE );

    // const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale

    cv::SiftFeatureDetector detector;
    std::vector<cv::keypoint> keypoints;
    detector.detect(input, keypoints);

    // Add results to image and save.
    cv::Mat output;
    cv::drawKeypoints(input, keypoints, output);`enter code here`
    cv::imwrite("sift_result.jpg", output);
   return Exit_Success(); //<- it happens here
}


I think it's in the cleanup somewhere here:

C++
void _Tidy()
{	// free all storage
    if (this->_Myfirst != pointer())
    {	// something to free, destroy and deallocate it
        this->_Orphan_all();
        _Destroy(this->_Myfirst, this->_Mylast);
        this->_Getal().deallocate(this->_Myfirst,
        this->_Myend - this->_Myfirst);**//--->......Here.....**
        this->_Myfirst = pointer();
        this->_Mylast = pointer();
        this->_Myend = pointer();
    }
}


The exception details says:

**Debug assertion failed.
Program:...
File: f:\dd\vctools\ctr_bld\self_x86\crt\src\dbgheap.c
Line: 1322
Expression: _CrtIsValidHeapPointers(pUserData)**</cv::keypoint>
Posted
Updated 12-Mar-14 5:35am
v3
Comments
Rage 12-Mar-14 9:43am    
2 remarks:
1. The detector has not much info about what it has to detect.
2. It could be that the error is not made in this function, but happens earlier in the code flow. Can you show the code calling this ?
stephcyl 12-Mar-14 10:07am    
I thought the detector takes as input the image, and then the keypoint is passed by reference?
It's in the cleanup of this function, as the code calling is is:
int main()
{
cerr<<"Please select what you want to test for"<<endl;
cerr<<"0. Exit"<<endl;
cerr<<"1. XT "<<endl;
cerr<<"2. MLP"<<endl;
cerr<<"3. Image"<<endl;
cerr<<"4. Sift"<<endl;
cerr<<"5. Surf"<<endl;

int cmd, returnVal;
cin>>cmd;
if (cmd==1)
{
returnVal= DoSift();
}

cerr<<"Press enter to exit"<<endl;

std::cin.ignore();
return returnVal;
}

When I call other functions and not this one it runs fine
Rage 12-Mar-14 10:29am    
The clean up function is where the assertion is triggered, but it is not there that the real error has been made. From what I can see, the keypoints are not properly deleted in the vector.

Does the image load properly ?
stephcyl 12-Mar-14 11:20am    
Yes, image loads properly.
How can I delete the keypoints? I notice that just declaring the keypoints will not trigger the error, but once I have called the "detect" function it triggers the exception.
Rage 12-Mar-14 11:40am    
Yes, this is because the detect function actually puts keypoints in the vector standard structure, and this fails to be done properly for some obscure reason. It could be that:
- the image is not read properly. Is IMREAD_GRAYSCALE = 0 ?
- the detect function has a problem -> can you debug through it and see how many keypoints are created ?
- Can you check how many keypoints are remaining in the vector before leaving the function ?

Note: I've also seen you have used cv::Mat and Mat. Have you defined the cv namespace as "used" somewhere ?

1 solution

The problem was with visual studio 2012. When I ran the program in 2010 it ran smoothly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900