Ask Your Question
0

How to extract RANSAC's inlier object points from the matrix produced by solvePNPRansac() or findHomography()?

asked 2018-09-06 13:20:16 -0600

hayley gravatar image

updated 2018-09-14 04:17:52 -0600

Hi everyone,

I understand that both solvePNPRansac() and findHomography() produce a matrix correlated to the inlier and outlier keypoints.

Once I get the Mask from the findHomography(), is there a trivial way to correlate the position of the rows in the Mask to the list of matches and the keypoints (like a simple for loop shown below)?

    for (int nextPosition = 0; nextPosition < Mask.height(); ++nextPosition) {
        if(Mask.get(nextPosition,0)[0] > 0.0){              
            inlierList_good_matches.add(List_good_matches.get(nextPosition));
                    inlierList_KeyPoints1.add(List_KeyPoints1.get(nextPosition));
            inlierList_KeyPoints2.add(List_KeyPoints2.get(nextPosition));      
        }            
    }

Thanks in advance!

edit retag flag offensive close merge delete

Comments

See: http://answers.opencv.org/question/38... When I tried it with cv::findFundamentalMat I had to convert the inliers from a vector<uchar> to a vector<char> in order to use it in cv::drawMatches

Grillteller gravatar imageGrillteller ( 2018-09-13 05:34:29 -0600 )edit

Thanks for the suggestion. I have elaborated on my question.

It is not clear how to refine my keypoints list. Can I assume that the first keypoint1 and first keypoint2 are aligned with the first position in the mask?

hayley gravatar imagehayley ( 2018-09-14 04:13:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-09-18 05:03:55 -0600

hayley gravatar image

I figured it out! The Ransac array will be the same size as your matches. So every position of the Ransac array will be a directly linked to the every position in the matches.

The Ransac array will only contain '1's and '0's. '1' represents an inlier and '0' is an outlier.

So here is a simple way to filter the outlier matches and draw the inlier matches:

final MatOfDMatch inlierMatches = new MatOfDMatch();
for (int i = 0; i < RansacArray.height(); ++i) { if(RansacArray.get(i,0)[0] > 0.0){ inlierMatches.add(matches.get(i)); }
}

Features2d.drawMatches(img1, keypoints1, img2, keypoints2, inlierMatches, outImg);

Note: I am still plotting all keypoints but clearly I can see the outliers as I only match the inliers together.

edit flag offensive delete link more

Comments

how can i get the exact location for every inlier point for example i need to know x and y location for all inliers points or all matched points

fo2sh44 gravatar imagefo2sh44 ( 2018-10-15 12:57:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-06 13:20:16 -0600

Seen: 2,937 times

Last updated: Sep 18 '18