| 1124 | } |
| 1125 | |
| 1126 | void testFundamentalMatrixFitting( |
| 1127 | const std::string& source_path_, |
| 1128 | const std::string& destination_path_, |
| 1129 | const std::string& out_correspondence_path_, |
| 1130 | const std::string& in_correspondence_path_, |
| 1131 | const std::string& output_match_image_path_, |
| 1132 | const double confidence_, |
| 1133 | const double inlier_outlier_threshold_, |
| 1134 | const double spatial_coherence_weight_, |
| 1135 | const size_t cell_number_in_neighborhood_graph_, |
| 1136 | const int fps_, |
| 1137 | const double minimum_inlier_ratio_for_sprt_) // An assumption about the minimum inlier ratio used for the SPRT test |
| 1138 | { |
| 1139 | // Read the images |
| 1140 | cv::Mat source_image = cv::imread(source_path_); |
| 1141 | cv::Mat destination_image = cv::imread(destination_path_); |
| 1142 | |
| 1143 | if (source_image.empty()) // Check if the source image is loaded successfully |
| 1144 | { |
| 1145 | printf("An error occured while loading image '%s'\n", |
| 1146 | source_path_.c_str()); |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | if (destination_image.empty()) // Check if the destination image is loaded successfully |
| 1151 | { |
| 1152 | printf("An error occured while loading image '%s'\n", |
| 1153 | destination_path_.c_str()); |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | // Detect or load point correspondences using AKAZE |
| 1158 | cv::Mat points; |
| 1159 | utils::detectFeatures( |
| 1160 | in_correspondence_path_, // The path where the correspondences are read from or saved to. |
| 1161 | source_image, // The source image |
| 1162 | destination_image, // The destination image |
| 1163 | points); // The detected point correspondences. Each row is of format "x1 y1 x2 y2" |
| 1164 | |
| 1165 | // Initialize the neighborhood used in Graph-cut RANSAC and, perhaps, |
| 1166 | // in the sampler if NAPSAC or Progressive-NAPSAC sampling is applied. |
| 1167 | std::chrono::time_point<std::chrono::system_clock> start, end; // Variables for time measurement |
| 1168 | start = std::chrono::system_clock::now(); // The starting time of the neighborhood calculation |
| 1169 | neighborhood::GridNeighborhoodGraph<4> neighborhood(&points, |
| 1170 | { source_image.cols / static_cast<double>(cell_number_in_neighborhood_graph_), |
| 1171 | source_image.rows / static_cast<double>(cell_number_in_neighborhood_graph_), |
| 1172 | destination_image.cols / static_cast<double>(cell_number_in_neighborhood_graph_), |
| 1173 | destination_image.rows / static_cast<double>(cell_number_in_neighborhood_graph_) }, |
| 1174 | cell_number_in_neighborhood_graph_); |
| 1175 | end = std::chrono::system_clock::now(); // The end time of the neighborhood calculation |
| 1176 | std::chrono::duration<double> elapsed_seconds = end - start; // The elapsed time in seconds |
| 1177 | printf("Neighborhood calculation time = %f secs\n", elapsed_seconds.count()); |
| 1178 | |
| 1179 | // Checking if the neighborhood graph is initialized successfully. |
| 1180 | if (!neighborhood.isInitialized()) |
| 1181 | { |
| 1182 | fprintf(stderr, "The neighborhood graph is not initialized successfully.\n"); |
| 1183 | return; |
no test coverage detected