OpenCV C++ findHomography mask values meaning

▼魔方 西西 提交于 2019-12-18 12:38:06

问题


I am using the function findHomography of OpenCV with the RANSAC method in order to find the homography that relates two images linked with a set of keypoints. Main issue is that I haven’t been able to find anywhere yet what are the values of the mask matrix that the function outputs. Only information that I know is that 0 values are outliers, and non zero values are inliers. But what does it mean the inliers value? Anyone knows?

Thanks in advance!

Piece of code where I call findHomography:

cv::Mat H12;
cv::Mat mask;

H12 = cv::findHomography(FvPointsIm1, FvPointsIm2, mask, CV_RANSAC, 5); 
ui->Debug_Label->setText(Mat2QString(mask));

回答1:


The mask returned by findHomography is an 8-bit, single-channel cv::Mat (or std::vector<uchar>, if you prefer) containing either 0 or 1 indicating the outlier status.

EDIT: You access each element of the mask by calling .at<double>, which is leading to the confusing output. You should be using .at<uchar>, which will interpret the matrix value correctly.




回答2:


I used the findHomography method after applying keypoint matching.

  • Inliers are matched keypoints that are calculated to be true positives (correct matches);
  • Outliers are matched keypoints that are calculated to be false positives (false matches).

Then you can use the mask output to extract the subset of correct matches from all matches.

  • There is an example in Python 3.6 & OpenCV 3.4.1:

    good_kp = [gray_kp[m.queryIdx].pt for m in good_matches]
    correct_matched_kp = [good_kp[i] for i in range(len(good_kp)) if mask[i]]
    


来源:https://stackoverflow.com/questions/15815304/opencv-c-findhomography-mask-values-meaning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!