| 875 | } |
| 876 | |
| 877 | void opencvHomographyFitting( |
| 878 | double ransac_confidence_, |
| 879 | double threshold_, |
| 880 | std::string test_scene_, |
| 881 | bool draw_results_, |
| 882 | const bool with_magsac_post_processing_) |
| 883 | { |
| 884 | // Print the name of the current scene |
| 885 | std::cout << "Processed scene = '" << test_scene_ << "'."; |
| 886 | |
| 887 | // Load the images of the current test scene |
| 888 | cv::Mat image1 = cv::imread("../data/homography/" + test_scene_ + "A.png"); |
| 889 | cv::Mat image2 = cv::imread("../data/homography/" + test_scene_ + "B.png"); |
| 890 | if (image1.cols == 0 || image2.cols == 0) // If the images have not been loaded, try to load them as jpg files. |
| 891 | { |
| 892 | image1 = cv::imread("../data/homography/" + test_scene_ + "A.jpg"); |
| 893 | image2 = cv::imread("../data/homography/" + test_scene_ + "B.jpg"); |
| 894 | } |
| 895 | |
| 896 | // If the images have not been loaded, return |
| 897 | if (image1.cols == 0 || image2.cols == 0) |
| 898 | { |
| 899 | std::cerr << "A problem occured when loading the images for test scene " << test_scene_ << "."; |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | cv::Mat points; // The point correspondences, each is of format "x1 y1 x2 y2" |
| 904 | std::vector<int> ground_truth_labels; // The ground truth labeling provided in the dataset |
| 905 | |
| 906 | // A function loading the points from files |
| 907 | readAnnotatedPoints("../data/homography/" + test_scene_ + "_pts.txt", // The path where the reference labeling and the points are found |
| 908 | points, // All data points |
| 909 | ground_truth_labels); // The reference labeling |
| 910 | |
| 911 | // The number of points in the scene |
| 912 | const size_t point_number = points.rows; |
| 913 | |
| 914 | if (point_number == 0) // If there are no points, return |
| 915 | { |
| 916 | std::cerr << "A problem occured when loading the annotated points for test scene " << test_scene_ << "."; |
| 917 | return; |
| 918 | } |
| 919 | |
| 920 | magsac::utils::DefaultHomographyEstimator estimator; // The robust homography estimator class containing the function for the fitting and residual calculation |
| 921 | gcransac::Homography model; // The estimated model |
| 922 | |
| 923 | // In this used datasets, the manually selected inliers are not all inliers but a subset of them. |
| 924 | // Therefore, the manually selected inliers are augmented as follows: |
| 925 | // (i) First, the implied model is estimated from the manually selected inliers. |
| 926 | // (ii) Second, the inliers of the ground truth model are selected. |
| 927 | std::vector<int> refined_labels = ground_truth_labels; |
| 928 | refineManualLabeling<gcransac::Homography, magsac::utils::DefaultHomographyEstimator>( |
| 929 | points, // The data points |
| 930 | refined_labels, // The refined labeling |
| 931 | estimator, // The model estimator |
| 932 | 2.0); // The used threshold in pixels |
| 933 | |
| 934 | // Select the inliers from the labeling |
no test coverage detected