First time here? Check out the FAQ!

Ask Your Question
0

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

asked Nov 4 '16

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Nov 4 '16

berak gravatar image

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

(yes, that happens !)

Preview: (hide)

Comments

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

Vintez gravatar imageVintez (Nov 4 '16)edit

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

berak gravatar imageberak (Nov 4 '16)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 (Nov 4 '16)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 (Nov 4 '16)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 (Nov 7 '16)edit

Question Tools

1 follower

Stats

Asked: Nov 4 '16

Seen: 7,597 times

Last updated: Nov 04 '16