MasteringOpenCV / code

Code for the book "Mastering OpenCV with Practical Computer Vision Projects" by Packt Publishing 2012.
Other
2.72k stars 1.64k forks source link

Ch4: Crashes in GetFundamentalMat(,,,) #44

Open MrJimm opened 9 years ago

MrJimm commented 9 years ago

When GetFundamentalMat() from FindCameraMatrices.cpp is called, and matches.size() == 0 it crashes. I found two places, where it usually crashes.

First: FindCameraMatrices.cpp, string 151:

F = findFundamentalMat(pts1, pts2, FM_RANSAC, 0.006 * maxVal, 0.99, status); //threshold from [Snavely07 4.1]

crashes, because pts1 and pts2 have to be the same size, but they don't. And they don't because of:

FindCameraMatrices.cpp, string 132:

if (matches.size() <= 0 ) { 
        //points already aligned...
        imgpts1_tmp = imgpts1;
        imgpts2_tmp = imgpts2;
}

Crash occures if matches.size() == 0, but size of imgpts1 != size of imgpts2.

Second: FindCameraMatrices.cpp, string 162:

if (matches.size() <= 0) { //points already aligned...
new_matches.push_back(DMatch(matches[i].queryIdx,matches[i].trainIdx,matches[i].distance));

matches.size() == 0, but we are going to retreive matches[i].