Point Cloud Library (PCL)  1.11.0
correspondence_rejection_sample_consensus_2d.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  *
37  */
38 
39 #pragma once
40 
41 #include <pcl/memory.h>
42 #include <pcl/pcl_macros.h>
43 #include <pcl/registration/correspondence_rejection_sample_consensus.h>
44 
45 namespace pcl
46 {
47  namespace registration
48  {
49  /** \brief CorrespondenceRejectorSampleConsensus2D implements a pixel-based
50  * correspondence rejection using Random Sample Consensus to identify inliers
51  * (and reject outliers)
52  * \author Radu B. Rusu
53  * \ingroup registration
54  */
55  template <typename PointT>
57  {
59  using PointCloudPtr = typename PointCloud::Ptr;
60  using PointCloudConstPtr = typename PointCloud::ConstPtr;
61 
62  public:
72 
73  using Ptr = shared_ptr<CorrespondenceRejectorSampleConsensus2D<PointT> >;
74  using ConstPtr = shared_ptr<const CorrespondenceRejectorSampleConsensus2D<PointT> >;
75 
76  /** \brief Empty constructor. Sets the inlier threshold to 5cm (0.05m),
77  * and the maximum number of iterations to 1000.
78  */
80  : projection_matrix_ (Eigen::Matrix3f::Identity ())
81  {
82  rejection_name_ = "CorrespondenceRejectorSampleConsensus2D";
83  // Put the projection matrix together
84  //projection_matrix_ (0, 0) = 525.f;
85  //projection_matrix_ (1, 1) = 525.f;
86  //projection_matrix_ (0, 2) = 320.f;
87  //projection_matrix_ (1, 2) = 240.f;
88  }
89 
90  /** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
91  * \param[in] original_correspondences the set of initial correspondences given
92  * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
93  */
94  inline void
95  getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
96  pcl::Correspondences& remaining_correspondences);
97 
98  /** \brief Sets the focal length parameters of the target camera.
99  * \param[in] fx the focal length in pixels along the x-axis of the image
100  * \param[in] fy the focal length in pixels along the y-axis of the image
101  */
102  inline void
103  setFocalLengths (const float fx, const float fy)
104  {
105  projection_matrix_ (0, 0) = fx;
106  projection_matrix_ (1, 1) = fy;
107  }
108 
109  /** \brief Reads back the focal length parameters of the target camera.
110  * \param[out] fx the focal length in pixels along the x-axis of the image
111  * \param[out] fy the focal length in pixels along the y-axis of the image
112  */
113  inline void
114  getFocalLengths (float &fx, float &fy) const
115  {
116  fx = projection_matrix_ (0, 0);
117  fy = projection_matrix_ (1, 1);
118  }
119 
120 
121  /** \brief Sets the camera center parameters of the target camera.
122  * \param[in] cx the x-coordinate of the camera center
123  * \param[in] cy the y-coordinate of the camera center
124  */
125  inline void
126  setCameraCenters (const float cx, const float cy)
127  {
128  projection_matrix_ (0, 2) = cx;
129  projection_matrix_ (1, 2) = cy;
130  }
131 
132  /** \brief Reads back the camera center parameters of the target camera.
133  * \param[out] cx the x-coordinate of the camera center
134  * \param[out] cy the y-coordinate of the camera center
135  */
136  inline void
137  getCameraCenters (float &cx, float &cy) const
138  {
139  cx = projection_matrix_ (0, 2);
140  cy = projection_matrix_ (1, 2);
141  }
142 
143  protected:
144 
145  /** \brief Apply the rejection algorithm.
146  * \param[out] correspondences the set of resultant correspondences.
147  */
148  inline void
150  {
152  }
153 
154  /** \brief Camera projection matrix. */
155  Eigen::Matrix3f projection_matrix_;
156 
157  public:
159  };
160  }
161 }
162 
163 #include <pcl/registration/impl/correspondence_rejection_sample_consensus_2d.hpp>
pcl::registration::CorrespondenceRejector::Ptr
shared_ptr< CorrespondenceRejector > Ptr
Definition: correspondence_rejection.h:61
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition: convolution.h:46
Eigen
Definition: bfgs.h:9
pcl::registration::CorrespondenceRejector::ConstPtr
shared_ptr< const CorrespondenceRejector > ConstPtr
Definition: correspondence_rejection.h:62
pcl::registration::CorrespondenceRejectorSampleConsensus2D::getFocalLengths
void getFocalLengths(float &fx, float &fy) const
Reads back the focal length parameters of the target camera.
Definition: correspondence_rejection_sample_consensus_2d.h:114
pcl::registration::CorrespondenceRejectorSampleConsensus2D::projection_matrix_
Eigen::Matrix3f projection_matrix_
Camera projection matrix.
Definition: correspondence_rejection_sample_consensus_2d.h:155
pcl::registration::CorrespondenceRejectorSampleConsensus2D::setCameraCenters
void setCameraCenters(const float cx, const float cy)
Sets the camera center parameters of the target camera.
Definition: correspondence_rejection_sample_consensus_2d.h:126
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:52
pcl::registration::CorrespondenceRejectorSampleConsensus2D
CorrespondenceRejectorSampleConsensus2D implements a pixel-based correspondence rejection using Rando...
Definition: correspondence_rejection_sample_consensus_2d.h:56
pcl::registration::CorrespondenceRejectorSampleConsensus2D::getRemainingCorrespondences
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.
Definition: correspondence_rejection_sample_consensus_2d.hpp:55
pcl::registration::CorrespondenceRejectorSampleConsensus2D::getCameraCenters
void getCameraCenters(float &cx, float &cy) const
Reads back the camera center parameters of the target camera.
Definition: correspondence_rejection_sample_consensus_2d.h:137
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::registration::CorrespondenceRejectorSampleConsensus
CorrespondenceRejectorSampleConsensus implements a correspondence rejection using Random Sample Conse...
Definition: correspondence_rejection_sample_consensus.h:62
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:88
pcl::registration::CorrespondenceRejectorSampleConsensus2D::CorrespondenceRejectorSampleConsensus2D
CorrespondenceRejectorSampleConsensus2D()
Empty constructor.
Definition: correspondence_rejection_sample_consensus_2d.h:79
pcl::registration::CorrespondenceRejector::input_correspondences_
CorrespondencesConstPtr input_correspondences_
The input correspondences.
Definition: correspondence_rejection.h:188
pcl::registration::CorrespondenceRejector::rejection_name_
std::string rejection_name_
The name of the rejection method.
Definition: correspondence_rejection.h:185
pcl::registration::CorrespondenceRejectorSampleConsensus2D::applyRejection
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
Definition: correspondence_rejection_sample_consensus_2d.h:149
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl::registration::CorrespondenceRejectorSampleConsensus2D::setFocalLengths
void setFocalLengths(const float fx, const float fy)
Sets the focal length parameters of the target camera.
Definition: correspondence_rejection_sample_consensus_2d.h:103