linemod.cpp crash (Bug #3139)


Added by Amir Rosenfeld over 11 years ago. Updated over 9 years ago.


Status:Incomplete Start date:2013-07-08
Priority:Normal Due date:
Assignee:Amir Rosenfeld % Done:

0%

Category:samples
Target version:-
Affected version:2.4.6 (latest release) Operating System:Windows
Difficulty: HW Platform:x64
Pull request:

Description

Linemod.cpp crashes for images of certain sizes. For an image of 400x410 pixels it crashed, but not for 640x640. I suspect it expects the image size to be a multiple of 8 or 16.


Associated revisions

Revision 4b84d5d2
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3139 from bmagyar:patch-2

History

Updated by Kirill Kornyakov over 11 years ago

Thanks for report, but could you please attach your image and the command line.

BTW it would be great to know what is your expectation: better failure message or another behavior.

  • Assignee changed from Kirill Kornyakov to Amir Rosenfeld
  • Difficulty deleted (Easy)

Updated by Amir Rosenfeld over 11 years ago

Here's the code, it simply loads an image of size width=410, height = 400, and fits to it a template of 30x29 pixels. To make sure that nothing is wrong with the specific images I used, I created new empty images in mspaint with the same dimensions, so you can reproduce the results exactly.
Note that I've added code to crop the image so it's size is a whole multiple of "Dmodulo", where I set it to 1 to leave the image unchanged. I've tried a variety of options, including 2,4,8,16,32,64,128. The minimal one that worked was 160 (but I did not check more options). Maybe this is because linemod processes video of 640x480?
Thanks,
-Amir

color = cv::imread("C:/Users/amirro/Desktop/linemod_images/empty_image.jpg");    
    cv::Mat template1 = cv::imread("C:/Users/amirro/Desktop/linemod_images/empty_template.jpg");

    int dModulo = 1; // Change this to 160 to avoid it crash!
    cv::Size newSize(color.size().width-color.size().width % dModulo,
        color.size().height-color.size().height % dModulo);
    cout <<"old size: " << color.size() << ", new size: " << newSize << endl;
    color = color.rowRange(0,newSize.height).colRange(0,newSize.width);

    std::vector<cv::Mat> sources;
    sources.push_back(color);            
    std::vector<cv::Mat> templates;
    templates.push_back(template1);
    cv::Mat mask;
    detector->addTemplate(templates,"template1",mask);

    cv::Mat display = color.clone();
    num_classes = templates.size();
    // Perform matching
    std::vector<cv::linemod::Match> matches;
    std::vector<std::string> class_ids;
    std::vector<cv::Mat> quantized_images;
    match_timer.start();    
    detector->match(sources, (float)matching_threshold, matches, class_ids, quantized_images);
    match_timer.stop();

p.s the crash is somewhere in orUnaligned8u, it then crashes inside checkHardwareSupport with a null pointer.

Updated by Nikita Manovich over 11 years ago

Amir,

Thank you for the update. Unfortunately we need more info from you.
You wrote:
>> Linemod.cpp crashes for images of certain sizes. For an image of 400x410 pixels it crashed, but not for 640x640. I suspect it expects the image size to be a multiple of 8 or 16.

We need to know exact steps to reproduce and fix the problem. Could you please specify them? We have a lot of bug reports a day and it is mostly impossible for us to fix a problem if we don't have exact steps to reproduce it. For example,
1. I compiled opencv master branch using default options
2. My environment is ... (OS, compiler and so on)
3. I run the sample with the following options: ...
4. Please find attached images: ...
4. As a result of these actions I got crash with the following message: ...

  • Target version deleted (2.4.7)
  • Status changed from New to Incomplete

Updated by Some Dirtbag over 10 years ago

I see that this is old, but not yet resolved. The linearize function in linemod.cpp has two CV_Assert calls that hint at cv::linemod::Detector::T_at_level being related to the image size limitation. Linemod should not crash so long as your image dimensions or T_at_level are adjusted to pass this CV_Assert code:

for( unsigned i=0; i< T_at_level.size(); ++i)
{
    CV_Assert( im.cols % ( (int)pow(2.,i+1) * T_at_level[i]) == 0 && im.rows % ( (int)pow(2.,i+1) * T_at_level[i] ) == 0);
}

I should note that I've only tested this for 1 modality and 2 pyramid levels. By default T_at_level = {5,8} but a custom T_at_level can be defined when creating the cv::linemod::Detector object in place of calling cv::linemod::getDefaultLINE().

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4593

Also available in: Atom PDF