MCPcopy Create free account
hub / github.com/danini/graph-cut-ransac / testRigidTransformFitting

Function testRigidTransformFitting

examples/cpp_example.cpp:853–968  ·  view source on GitHub ↗

An example function showing how to fit calculate a rigid transformation from a set of 3D-3D correspondences by Graph-Cut RANSAC

Source from the content-addressed store, hash-verified

851
852// An example function showing how to fit calculate a rigid transformation from a set of 3D-3D correspondences by Graph-Cut RANSAC
853void testRigidTransformFitting(
854 const std::string& ground_truth_pose_path_, // The path where the ground truth pose can be found
855 const std::string& points_path_, // The path of the points
856 const std::string& inliers_point_path_, // The path where the inlier correspondences are saved
857 const double confidence_, // The RANSAC confidence value
858 const double inlier_outlier_threshold_, // The used inlier-outlier threshold in GC-RANSAC.
859 const double spatial_coherence_weight_, // The weight of the spatial coherence term in the graph-cut energy minimization.
860 const double sphere_radius_, // The radius of the sphere used for determining the neighborhood-graph
861 const double minimum_inlier_ratio_for_sprt_) // An assumption about the minimum inlier ratio used for the SPRT test
862{
863 // The image and world points stored as rows in the matrix. Each row is of format 'u v x y z'.
864 cv::Mat points;
865
866 // Loading the 3D-3D correspondences
867 gcransac::utils::loadPointsFromFile<6, 1, false>(points, // The points in the image
868 points_path_.c_str()); // The path where the image points are stored
869
870 // Load the ground truth pose
871 Eigen::Matrix<double, 4, 4> ground_truth_T;
872 if (!utils::loadMatrix<double, 4, 4>(ground_truth_pose_path_,
873 ground_truth_T))
874 {
875 printf("An error occured when loading the reference camera pose from '%s'\n",
876 ground_truth_pose_path_.c_str());
877 return;
878 }
879
880 // Initialize the neighborhood used in Graph-cut RANSAC and, perhaps,
881 // in the sampler if NAPSAC or Progressive-NAPSAC sampling is applied.
882 std::chrono::time_point<std::chrono::system_clock> start, end; // Variables for time measurement
883 start = std::chrono::system_clock::now(); // The starting time of the neighborhood calculation
884 // TODO: generalize the grid class to handle not only point correspondences
885 neighborhood::FlannNeighborhoodGraph neighborhood(&points, // The data points
886 sphere_radius_); // The radius of the neighborhood sphere used for determining the neighborhood structure
887 end = std::chrono::system_clock::now(); // The end time of the neighborhood calculation
888 std::chrono::duration<double> elapsed_seconds = end - start; // The elapsed time in seconds
889 printf("Neighborhood calculation time = %f secs\n", elapsed_seconds.count());
890
891 // Apply Graph-cut RANSAC
892 utils::DefaultRigidTransformationEstimator estimator; // The estimator used for the pose fitting
893 RigidTransformation model; // The estimated model parameters
894
895 // Initialize the samplers
896 // The main sampler is used inside the local optimization
897 sampler::UniformSampler main_sampler(&points); // The data points
898 sampler::UniformSampler local_optimization_sampler(&points); // The local optimization sampler is used inside the local optimization
899
900 // Checking if the samplers are initialized successfully.
901 if (!main_sampler.isInitialized() ||
902 !local_optimization_sampler.isInitialized())
903 {
904 fprintf(stderr, "One of the samplers is not initialized successfully.\n");
905 return;
906 }
907
908 // Initializing SPRT test
909 preemption::EmptyPreemptiveVerfication<utils::DefaultRigidTransformationEstimator> preemptive_verification;
910

Callers 1

mainFunction · 0.85

Calls 3

savePointsToFileFunction · 0.85
isInitializedMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected