39 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
40 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
42 #include <pcl/sample_consensus/ransac.h>
43 #include <pcl/sample_consensus/sac_model_registration_2d.h>
45 #include <unordered_map>
49 namespace registration {
51 template <
typename Po
intT>
58 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud "
59 "dataset was given!\n",
60 getClassName().c_str());
65 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] No input target "
66 "dataset was given!\n",
67 getClassName().c_str());
71 if (projection_matrix_ == Eigen::Matrix3f::Identity()) {
72 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] Intrinsic camera "
73 "parameters not given!\n",
74 getClassName().c_str());
78 int nr_correspondences =
static_cast<int>(original_correspondences.size());
83 for (std::size_t i = 0; i < original_correspondences.size(); ++i) {
84 source_indices[i] = original_correspondences[i].index_query;
85 target_indices[i] = original_correspondences[i].index_match;
101 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] Error computing "
102 "model! Returning the original correspondences...\n",
103 getClassName().c_str());
104 remaining_correspondences = original_correspondences;
105 best_transformation_.setIdentity();
110 "[pcl::registration::%s::getRemainingCorrespondences] Error refining model!\n",
111 getClassName().c_str());
116 if (inliers.size() < 3) {
117 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] Less than 3 "
118 "correspondences found!\n",
119 getClassName().c_str());
120 remaining_correspondences = original_correspondences;
121 best_transformation_.setIdentity();
125 std::unordered_map<int, int> index_to_correspondence;
126 for (
int i = 0; i < nr_correspondences; ++i)
127 index_to_correspondence[original_correspondences[i].index_query] = i;
129 remaining_correspondences.resize(inliers.size());
130 for (std::size_t i = 0; i < inliers.size(); ++i)
131 remaining_correspondences[i] =
132 original_correspondences[index_to_correspondence[inliers[i]]];
135 Eigen::VectorXf model_coefficients;
137 best_transformation_.row(0) = model_coefficients.segment<4>(0);
138 best_transformation_.row(1) = model_coefficients.segment<4>(4);
139 best_transformation_.row(2) = model_coefficients.segment<4>(8);
140 best_transformation_.row(3) = model_coefficients.segment<4>(12);
RandomSampleConsensus represents an implementation of the RANSAC (RANdom SAmple Consensus) algorithm,...
bool computeModel(int debug_verbosity_level=0) override
Compute the actual model and find the inliers.
void getInliers(Indices &inliers) const
Return the best set of inliers found so far for this model.
void getModelCoefficients(Eigen::VectorXf &model_coefficients) const
Return the model coefficients of the best model found so far.
virtual bool refineModel(const double sigma=3.0, const unsigned int max_iterations=1000)
Refine the model found.
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
SampleConsensusModelRegistration2D defines a model for Point-To-Point registration outlier rejection ...
shared_ptr< SampleConsensusModelRegistration2D< PointT > > Ptr
void setProjectionMatrix(const Eigen::Matrix3f &projection_matrix)
Set the camera projection matrix.
void setInputTarget(const PointCloudConstPtr &target)
Set the input point cloud target.
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences)
Get a list of valid correspondences after rejection from the original set of correspondences.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.