I used CV_RANSAC option at findHomography function but now I want to use estimateRigidTransform. Thus I can no more use CV_RANSAC.
I want to eliminate outliers of my SIFT featured matched data and apply estimateRigidTransform. How can I do this?
I used CV_RANSAC option at findHomography function but now I want to use estimateRigidTransform. Thus I can no more use CV_RANSAC.
I want to eliminate outliers of my SIFT featured matched data and apply estimateRigidTransform. How can I do this?
Here is a solution that worked for me:
Crosscheck all the matches. Here is how I did that:
std::vector<Point2f> valid_coords_1, valid_coords_2;
std::vector< DMatch > valid_matches;
//-- Show detected matches
int counter;
float res;
for( int i = 0; i < (int)good_matches.size(); i++ ){
counter = 0;
for(int j = 0; j < (int)good_matches.size(); j++){
if(i!=j){
res = cv::norm(keypoints_1[good_matches[i].queryIdx].pt - keypoints_1[good_matches[j].queryIdx].pt) - cv::norm(keypoints_2[good_matches[i].trainIdx].pt-keypoints_2[good_matches[j].trainIdx].pt);
if(abs(res) < (img_1.rows * 0.004 + 3)){ //this value has to be adjusted
counter++;
}
//printf("Match good point %d with %d: %f \n", i, j, res);
}
}
/* printf( "-- Good Match [%d] Keypoint 1: %d (%f,%f) -- Keypoint 2: %d (%f,%f) Distance: %f \n", i, good_matches[i].queryIdx,
keypoints_1[good_matches[i].queryIdx].pt.x, keypoints_1[good_matches[i].queryIdx].pt.y,
good_matches[i].trainIdx,
keypoints_2[good_matches[i].trainIdx].pt.x, keypoints_2[good_matches[i].trainIdx].pt.y,
good_matches[i].distance); */
//printf("Point nr %d: has %d valid matches \n", i, counter);
if(counter > (good_matches.size() / 10)){
valid_matches.push_back(good_matches[i]);
valid_coords_1.push_back(keypoints_1[good_matches[i].queryIdx].pt);
valid_coords_2.push_back(keypoints_2[good_matches[i].trainIdx].pt);
}
}
I hope this helped in some way. Please let me know if you need further information :)