| 696 | } |
| 697 | |
| 698 | void testHomographyFitting( |
| 699 | double ransac_confidence_, // The confidence required |
| 700 | double maximum_threshold_, // The maximum threshold value |
| 701 | std::string test_scene_, // The name of the current test scene |
| 702 | bool use_magsac_plus_plus_, // A flag to decide if MAGSAC++ or MAGSAC should be used |
| 703 | bool draw_results_, // A flag determining if the results should be visualized |
| 704 | double drawing_threshold_) // The threshold used for visualizing the results |
| 705 | { |
| 706 | // Print the name of the current test scene |
| 707 | std::cout << "Processed scene = '" << test_scene_ << "'."; |
| 708 | |
| 709 | // Load the images of the current test scene |
| 710 | cv::Mat image1 = cv::imread("../data/homography/" + test_scene_ + "A.png"); |
| 711 | cv::Mat image2 = cv::imread("../data/homography/" + test_scene_ + "B.png"); |
| 712 | if (image1.cols == 0 || image2.cols == 0) // If the images have not been loaded, try to load them as jpg files. |
| 713 | { |
| 714 | image1 = cv::imread("../data/homography/" + test_scene_ + "A.jpg"); |
| 715 | image2 = cv::imread("../data/homography/" + test_scene_ + "B.jpg"); |
| 716 | } |
| 717 | |
| 718 | // If the images have not been loaded, return |
| 719 | if (image1.cols == 0 || image2.cols == 0) |
| 720 | { |
| 721 | std::cerr << "A problem occured when loading the images for test scene " << test_scene_ << "."; |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | cv::Mat points; // The point correspondences, each is of format "x1 y1 x2 y2" |
| 726 | std::vector<int> ground_truth_labels; // The ground truth labeling provided in the dataset |
| 727 | |
| 728 | // A function loading the points from files |
| 729 | readAnnotatedPoints("../data/homography/" + test_scene_ + "_pts.txt", // The path where the reference labeling and the points are found |
| 730 | points, // All data points |
| 731 | ground_truth_labels); // The reference labeling |
| 732 | |
| 733 | // The number of points in the datasets |
| 734 | const size_t point_number = points.rows; // The number of points in the scene |
| 735 | |
| 736 | if (point_number == 0) // If there are no points, return |
| 737 | { |
| 738 | std::cerr << "A problem occured when loading the annotated points for test scene " << test_scene_ << "."; |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | magsac::utils::DefaultHomographyEstimator estimator; // The robust homography estimator class containing the function for the fitting and residual calculation |
| 743 | gcransac::Homography model; // The estimated model |
| 744 | |
| 745 | // In this used datasets, the manually selected inliers are not all inliers but a subset of them. |
| 746 | // Therefore, the manually selected inliers are augmented as follows: |
| 747 | // (i) First, the implied model is estimated from the manually selected inliers. |
| 748 | // (ii) Second, the inliers of the ground truth model are selected. |
| 749 | std::vector<int> refined_labels = ground_truth_labels; |
| 750 | refineManualLabeling<gcransac::Homography, magsac::utils::DefaultHomographyEstimator>( |
| 751 | points, // The data points |
| 752 | refined_labels, // The refined labeling |
| 753 | estimator, // The model estimator |
| 754 | 2.0); // The used threshold in pixels |
| 755 |
no test coverage detected