MCPcopy Create free account
hub / github.com/danini/magsac / opencvFundamentalMatrixFitting

Function opencvFundamentalMatrixFitting

examples/cpp_example.cpp:1026–1169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1024}
1025
1026void opencvFundamentalMatrixFitting(
1027 double ransac_confidence_,
1028 double threshold_,
1029 std::string test_scene_,
1030 bool draw_results_,
1031 const bool with_magsac_post_processing_)
1032{
1033 // Print the name of the current test scene
1034 std::cout << "Processed scene = '" << test_scene_ << "'.";
1035
1036 // Load the images of the current test scene
1037 cv::Mat image1 = cv::imread("../data/fundamental_matrix/" + test_scene_ + "A.png");
1038 cv::Mat image2 = cv::imread("../data/fundamental_matrix/" + test_scene_ + "B.png");
1039 if (image1.cols == 0 || image2.cols == 0) // Try to load jpg files if there are no pngs
1040 {
1041 image1 = cv::imread("../data/fundamental_matrix/" + test_scene_ + "A.jpg");
1042 image2 = cv::imread("../data/fundamental_matrix/" + test_scene_ + "B.jpg");
1043 }
1044
1045 // If the images are not loaded, return
1046 if (image1.cols == 0 || image2.cols == 0)
1047 {
1048 std::cerr << "A problem occured when loading the images for test scene " << test_scene_ << ".";
1049 return;
1050 }
1051
1052 cv::Mat points; // The point correspondences, each is of format x1 y1 x2 y2
1053 std::vector<int> ground_truth_labels; // The ground truth labeling provided in the dataset
1054
1055 // A function loading the points from files
1056 readAnnotatedPoints("../data/fundamental_matrix/" + test_scene_ + "_pts.txt", // The path to the labels and points
1057 points, // The container for the loaded points
1058 ground_truth_labels); // The ground thruth labeling
1059
1060 // The number of points in the datasets
1061 const size_t point_number = points.rows; // The number of points in the scene
1062
1063 if (point_number == 0) // If there are no points, return
1064 {
1065 std::cerr << "A problem occured when loading the annotated points for test scene " << test_scene_ << ".";
1066 return;
1067 }
1068
1069 gcransac::utils::DefaultFundamentalMatrixEstimator estimator; // The robust homography estimator class containing the function for the fitting and residual calculation
1070 gcransac::FundamentalMatrix model; // The estimated model parameters
1071
1072 // In this used datasets, the manually selected inliers are not all inliers but a subset of them.
1073 // Therefore, the manually selected inliers are augmented as follows:
1074 // (i) First, the implied model is estimated from the manually selected inliers.
1075 // (ii) Second, the inliers of the ground truth model are selected.
1076 std::vector<int> refined_labels = ground_truth_labels;
1077 refineManualLabeling<gcransac::FundamentalMatrix, gcransac::utils::DefaultFundamentalMatrixEstimator>(
1078 points, // All data points
1079 ground_truth_labels, // The refined labeling
1080 estimator, // The estimator used for determining the underlying model
1081 0.35); // Threshold value from the LO*-RANSAC paper
1082
1083 // Select the inliers from the labeling

Callers 1

runTestFunction · 0.85

Calls 3

readAnnotatedPointsFunction · 0.85
getSubsetFromLabelingFunction · 0.85
showImageFunction · 0.85

Tested by

no test coverage detected