C++ SURF crash by flat image (Bug #68)


Added by takuya minagawa about 15 years ago. Updated over 14 years ago.


Status:Done Start date:
Priority:Blocker Due date:
Assignee:Mithun Jacob % Done:

0%

Category:features2d
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I tried SURF class of C++ interface, and found that it crashed by entering flat, no feature point, image.

I replaced "cvsurf.cpp" by svn version and recompiled it, but the situation didn't change.

My environment:
Windows XP
MSVC Express 2008

And error seemed to occur at line. 866 of cvsurf.cpp (in cvCvtSeqToArray()).

I attached the image which caused crash.


neg_test.jpg - flat image (1.1 kB) takuya minagawa, 2010-01-15 07:48 am

surf-crash.diff - this fix worked for me (1 kB) Piotr M, 2010-04-15 12:22 am


Related issues

duplicated by Bug #373: Bug in cvExtractSURF() Cancelled

History

Updated by Mithun Jacob about 15 years ago

I tried the following and it worked. When you try it, make sure img_path is correct.

 1        // Read the image
 2    char img_path[] = "neg_new.jpg";
 3    Mat im = imread(img_path,0);
 4    if(im.data == NULL) 
 5    {
 6        cout<<"Unable to read "<<img_path<<endl;
 7        return 1;
 8    }
 9
10    // Create the SURF object
11    const int [[HessianThreshold]] = 500;
12    SURF bug(HessianThreshold);
13    vector<KeyPoint> keypoints;
14    bug(im,255*Mat::ones(im.rows,im.cols,CV_8U),keypoints);
15
16    // Plot the keypoints
17    const int radius = 1, thickness = 2;
18    const Scalar color(0,0,0,0);
19    for(size_t i = 0;i<keypoints.size();++i)
20    {
21        circle(im,keypoints[i].pt,radius,color,thickness);
22    }
23
24    // Display
25    namedWindow("Image");
26    imshow("Image",im);
27    waitKey();

  • Status deleted (Open)

Updated by takuya minagawa about 15 years ago

Thanks for your support.
Sorry, I forgot to mention one thing.
This problem happened when I try to get descpriptor.

So in this case, please try the following code:

        // Read the image
        char img_path[] = "neg_new.jpg";
        Mat im = imread(img_path,0);
        if(im.data == NULL) 
        {
                cout<<"Unable to read "<<img_path<<endl;
                return 1;
        }

        // Create the SURF object
        const int [[HessianThreshold]] = 500;
        SURF bug(HessianThreshold,4,2,true);
        vector<KeyPoint> keypoints;
        vector<float> descriptors;

    Mat ones(im.rows,im.cols,CV_8U);
    ones = Scalar(255);
    bug(im,ones,keypoints,descriptors);

        // Plot the keypoints
        const int radius = 1, thickness = 2;
        const Scalar color(0,0,0,0);
        for(size_t i = 0;i<keypoints.size();++i)
        {
                circle(im,keypoints[i].pt,radius,color,thickness);
        }

        // Display
        namedWindow("Image");
        imshow("Image",im);
        waitKey();

Anyway, I fixed this error for myself.
In cvsurf.cpp (svn version), at line 865,

I changed

    if(d)

to
    if(d->total)

Thanks

Updated by Mithun Jacob about 15 years ago

Thanks for the feedback!

  • Status set to Done
  • (deleted custom field) set to fixed

Updated by Piotr M almost 15 years ago

SURF crash with current SVN rev:3030.

All platforms.

Code to reproduce bug:

int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat white(320,200,CV_8UC1);
    white.setTo( cv::Scalar(255) ) ;

    cv::SURF detector(200, 2, 1, false);

    std::vector<cv::KeyPoint> keyPoints;
    std::vector<float>  descriptors;

    detector( white , cv::Mat() ,  keyPoints , descriptors );
    return 0;
}
  • Status changed from Done to Cancelled
  • (deleted custom field) deleted (fixed)

Updated by Jerry Fetcher almost 15 years ago

Hi,

I am new to this forum and I wonder if there is a solution to this problem. When there is a frame with no keypoints (blank scene with all white pixels), the program crazhes with error message

OpenCV Error: Incorrect size of input array (Non-positive width or height) in unknown function, file ..\..\..\ocv\opencv\src\cxcore\cxarray.cpp, line 113

I tried proposed solutions and edited my cvsurf.cpp but none worked. Any help will be appreciated. Thank you...

Jerry

Updated by anonymous - almost 15 years ago

Do I need to rebuild OPenCV on my Windows machine after I change cvsurf.cpp? If yes, how do I do that?

Thanks

Updated by anonymous - almost 15 years ago

Yes, you need to rebuild, look here: http://opencv.willowgarage.com/wiki/InstallGuide

Updated by Maria Dimashova over 14 years ago

I have tested both samples (reported by takmin and piotrek) to reproduce the bug on win32 (VS2008) and ubuntu64. Using current r3907 the samples work without failing.

  • Status changed from Cancelled to Done
  • (deleted custom field) set to fixed

Updated by takuya minagawa over 14 years ago

I rewrote "cvsurf.cpp" as you described, and recompiled it.
https://code.ros.org/trac/opencv/attachment/ticket/68/surf-crash.diff

Yes, it can avoid the crash, but it seems to have some memory leaks.
I input flat images to SURF again and again, and watched the memory by Windows task manager. Then I found that memory usage was increasing.

please check it. I guess you forgot to release memory when no key points were found.

  • Status changed from Done to Cancelled
  • (deleted custom field) deleted (fixed)

Updated by takuya minagawa over 14 years ago

Maybe, I found the solution for memory leak.

I rewrote the line 728 - 33.

changed from:

if ( N == 0 )  
 { 
     // no key points found; nothing to do  
     return; 
 }

to:

if(N==0)
{
    // no key points found;
    cvReleaseMat( &sum );
    if (mask1) cvReleaseMat( &mask1 );
    if (mask_sum) cvReleaseMat( &mask_sum );
    return;
}

Updated by Maria Dimashova over 14 years ago

What revision do you use? I have not described to apply https://code.ros.org/trac/opencv/attachment/ticket/68/surf-crash.diff. Please, update OpenCV revision that you used to r3907 or higher (from trunk).

I also tested memory leaks in r3907 using sample

int main() {
cv::Mat white(320,200,CV_8UC1);
white.setTo( cv::Scalar(255) ) ;

cv::SURF detector(200, 2, 1, false);
while(1)
{
std::vector&lt;cv::KeyPoint&gt; keyPoints;
std::vector&lt;float&gt; descriptors;
detector( white , cv::Mat() , keyPoints , descriptors );
}
return 0;
}

There are not memory leaks now. Probably your problem was in opencv 2.0. Later it has been fixed - I do not know in which revision exactly, I have tested r3907. Now it's ok.

  • Status changed from Cancelled to Done
  • (deleted custom field) set to fixed

Also available in: Atom PDF