38 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
39 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
41 #include <pcl/sample_consensus/sac_model_registration_2d.h>
42 #include <pcl/sample_consensus/ransac.h>
45 template <
typename Po
intT>
void
52 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud dataset was given!\n", getClassName ().c_str ());
58 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input target dataset was given!\n", getClassName ().c_str ());
62 if (projection_matrix_ == Eigen::Matrix3f::Identity ())
64 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Intrinsic camera parameters not given!\n", getClassName ().c_str ());
68 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
69 std::vector<int> source_indices (nr_correspondences);
70 std::vector<int> target_indices (nr_correspondences);
73 for (
size_t i = 0; i < original_correspondences.size (); ++i)
75 source_indices[i] = original_correspondences[i].index_query;
76 target_indices[i] = original_correspondences[i].index_match;
80 std::vector<int> source_indices_good;
81 std::vector<int> target_indices_good;
96 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Error computing model! Returning the original correspondences...\n", getClassName ().c_str ());
97 remaining_correspondences = original_correspondences;
98 best_transformation_.setIdentity ();
104 PCL_WARN (
"[pcl::registration::%s::getRemainingCorrespondences] Error refining model!\n", getClassName ().c_str ());
106 std::vector<int> inliers;
109 if (inliers.size () < 3)
111 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Less than 3 correspondences found!\n", getClassName ().c_str ());
112 remaining_correspondences = original_correspondences;
113 best_transformation_.setIdentity ();
117 boost::unordered_map<int, int> index_to_correspondence;
118 for (
int i = 0; i < nr_correspondences; ++i)
119 index_to_correspondence[original_correspondences[i].index_query] = i;
121 remaining_correspondences.resize (inliers.size ());
122 for (
size_t i = 0; i < inliers.size (); ++i)
123 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
126 Eigen::VectorXf model_coefficients;
128 best_transformation_.row (0) = model_coefficients.segment<4>(0);
129 best_transformation_.row (1) = model_coefficients.segment<4>(4);
130 best_transformation_.row (2) = model_coefficients.segment<4>(8);
131 best_transformation_.row (3) = model_coefficients.segment<4>(12);
135 #endif // PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
void setProjectionMatrix(const Eigen::Matrix3f &projection_matrix)
Set the camera projection matrix.
boost::shared_ptr< SampleConsensusModelRegistration2D > Ptr
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.
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
virtual bool refineModel(const double sigma=3.0, const unsigned int max_iterations=1000)
Refine the model found.
bool computeModel(int debug_verbosity_level=0)
Compute the actual model and find the inliers.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
void getModelCoefficients(Eigen::VectorXf &model_coefficients)
Return the model coefficients of the best model found so far.
void getInliers(std::vector< int > &inliers)
Return the best set of inliers found so far for this model.
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm...
void setInputTarget(const PointCloudConstPtr &target)
Set the input point cloud target.
SampleConsensusModelRegistration2D defines a model for Point-To-Point registration outlier rejection ...