TEST_F(TestRansac, TestDrawInliers) { // Load two images and compute feature matches. Draw matches with and without // RANSAC. if (!FLAGS_ransac_draw_feature_matches) { return; } // Get some noisy feature matches. Image image1(test_image1.c_str()); Image image2(test_image2.c_str()); image1.Resize(0.25); image2.Resize(0.25); KeypointDetector detector; detector.SetDetector("SIFT"); KeypointList keypoints1; KeypointList keypoints2; detector.DetectKeypoints(image1, keypoints1); detector.DetectKeypoints(image2, keypoints2); // DistanceMetric::Instance().SetMetric(DistanceMetric::Metric::SCALED_L2); DescriptorExtractor extractor; extractor.SetDescriptor("SIFT"); std::vector<Feature> features1; std::vector<Feature> features2; std::vector<Descriptor> descriptors1; std::vector<Descriptor> descriptors2; extractor.DescribeFeatures(image1, keypoints1, features1, descriptors1); extractor.DescribeFeatures(image2, keypoints2, features2, descriptors2); FeatureMatcherOptions matcher_options; matcher_options.distance_metric = "SCALED_L2"; NaiveMatcher2D2D feature_matcher; feature_matcher.AddImageFeatures(features1, descriptors1); feature_matcher.AddImageFeatures(features2, descriptors2); PairwiseImageMatchList image_matches; feature_matcher.MatchImages(matcher_options, image_matches); ASSERT_TRUE(image_matches.size() == 1); // RANSAC the feature matches to get inliers. FundamentalMatrixRansacProblem problem; problem.SetData(image_matches[0].feature_matches_); // Create the ransac solver, set options, and run RANSAC on the problem. Ransac<FeatureMatch, FundamentalMatrixRansacModel> solver; RansacOptions ransac_options; ransac_options.iterations = 5000; ransac_options.acceptable_error = 1e-3; ransac_options.minimum_num_inliers = 100; ransac_options.num_samples = 8; solver.SetOptions(ransac_options); solver.Run(problem); ASSERT_TRUE(problem.SolutionFound()); drawing::DrawImageFeatureMatches(image1, image2, image_matches[0].feature_matches_, "Noisy Matched Features"); const FeatureMatchList& inliers = problem.Inliers(); drawing::DrawImageFeatureMatches(image1, image2, inliers, "Inlier Matched Features"); }