Ask Your Question
0

Assertion Failed (scn + 1 == m.cols)

asked 2016-11-04 09:43:48 -0600

Vintez gravatar image

I try to get the perspectiveTransform of some Point Matches I find, but I somehow get the Assertion Error and my Application gets killed.

Here is my method for this:

 int MatcherManager::getInlierRANSAC(std::vector<cv::KeyPoint> reference, std::vector<cv::KeyPoint> matches, std::vector<cv::Point2f> &ransacs, std::vector<cv::Point2f> &obj_corners, std::vector<cv::Point2f> &scene_corners){

double ransacThreshold = 1;
int result = 0;
cv::Mat mask;
std::vector<cv::Point2f> points1, points2;
if(reference.size() > 0 && matches.size() > 0) {
    for(int i = 0; i < reference.size(); i++){
        points1.push_back(reference[i].pt);
        points2.push_back(matches[i].pt);
    }

    cv::Mat H = cv::findHomography(points1, points2, CV_RANSAC, ransacThreshold, mask);

    for (int i = 0; i < mask.rows; i++) {
        if ((unsigned int) mask.at<uchar>(i)) {
            result++;
            ransacs.push_back(points2[i]);
        }
    }

    cv::perspectiveTransform(obj_corners, scene_corners, H);
}
return result;
}

Does somebody see what causes the Exception here?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-11-04 09:47:19 -0600

berak gravatar image

most probably, your homography Mat H is empty, because findHomography() did not find nice matches.

(yes, that happens !)

edit flag offensive delete link more

Comments

ok, I thought that it could be that, but, shouldn't be the mask also filled completely with zeroes than?

Vintez gravatar imageVintez ( 2016-11-04 09:57:48 -0600 )edit

idk (never used a mask there). what is inside your mask ?

berak gravatar imageberak ( 2016-11-04 10:19:53 -0600 )edit

The Mask is a cv::Mat which is as big as the number of Points you give into cv::findHomography. The Values in it are either 0 or 1 and show if it is a Inlier our Outlier

Vintez gravatar imageVintez ( 2016-11-04 10:59:14 -0600 )edit

so, is it all 0 ? can't remember, how many minimum inliers are needed, but i guess, like 4 or 5

berak gravatar imageberak ( 2016-11-04 11:09:58 -0600 )edit

I'll try to check that now, but In general it was 4 - 5 Inliers for each step. Until now, I didn't get the Error again... Made some checks before executing the function. So probably it really was totally empty (H) leaving me the Question, how could that actually be? could it be, that the percentage of Outliers is to high?

Vintez gravatar imageVintez ( 2016-11-07 01:56:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-04 09:43:48 -0600

Seen: 7,479 times

Last updated: Nov 04 '16