Go to the documentation of this file.00001
00024 #ifndef RGBDTOOLS_MOTION_ESTIMATION_PAIRWISE_RANSAC_H
00025 #define RGBDTOOLS_MOTION_ESTIMATION_PAIRWISE_RANSAC_H
00026
00027 #include <pcl/io/pcd_io.h>
00028 #include <pcl/kdtree/kdtree.h>
00029 #include <pcl/registration/transformation_estimation_svd.h>
00030
00031 #include "rgbdtools/types.h"
00032 #include "rgbdtools/registration/motion_estimation.h"
00033 #include "rgbdtools/features/orb_detector.h"
00034
00035 namespace rgbdtools {
00036
00043 class MotionEstimationPairwiseRANSAC: public MotionEstimation
00044 {
00045 public:
00046
00047 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00048
00053 MotionEstimationPairwiseRANSAC();
00054
00057 virtual ~MotionEstimationPairwiseRANSAC();
00058
00066 bool getMotionEstimationImpl(
00067 RGBDFrame& frame,
00068 const AffineTransform& prediction,
00069 AffineTransform& motion);
00070
00071 void setFeatureDetector(FeatureDetectorPtr detector) {detector_ = detector;}
00072
00073 private:
00074
00075 bool initialized_;
00076
00077 RGBDFrame * prev_frame_;
00078
00079 FeatureDetectorPtr detector_;
00080
00081 AffineTransform f2b_;
00082
00083
00084
00085 int sac_min_inliers_;
00086 double sac_max_eucl_dist_sq_;
00087 bool sac_reestimate_tf_;
00088 int ransac_max_iterations_;
00089 double ransac_confidence_;
00090 double log_one_minus_ransac_confidence_;
00091 bool matcher_use_desc_ratio_test_;
00092 double matcher_max_desc_ratio_;
00093 double matcher_max_desc_dist_;
00094
00095 int pairwiseMatchingRANSAC(
00096 const RGBDFrame& frame_q, const RGBDFrame& frame_t,
00097 DMatchVector& best_inlier_matches,
00098 Eigen::Matrix4f& best_transformation);
00099
00100 void getCandidateMatches(
00101 const RGBDFrame& frame_q, const RGBDFrame& frame_t,
00102 cv::DescriptorMatcher& matcher,
00103 DMatchVector& candidate_matches);
00104
00105 void getRandomIndices(
00106 int k, int n, IntVector& output)
00107 {
00108 while ((int)output.size() < k)
00109 {
00110 int random_number = rand() % n;
00111 bool duplicate = false;
00112
00113 for (unsigned int i = 0; i < output.size(); ++i)
00114 {
00115 if (output[i] == random_number)
00116 {
00117 duplicate = true;
00118 break;
00119 }
00120 }
00121
00122 if (!duplicate)
00123 output.push_back(random_number);
00124 }
00125 }
00126
00127 void get3RandomIndices(
00128 int n, std::set<int>& mask, IntVector& output)
00129 {
00130 int key;
00131
00132 while(true)
00133 {
00134 output.clear();
00135 getRandomIndices(3, n, output);
00136
00137
00138 key = output[0] * n * n + output[1] * n + output[2];
00139
00140
00141
00142
00143 if (mask.find(key) == mask.end())
00144 break;
00145 }
00146
00147 mask.insert(key);
00148 }
00149
00150 double distEuclideanSq(const PointFeature& a, const PointFeature& b)
00151 {
00152 float dx = a.x - b.x;
00153 float dy = a.y - b.y;
00154 float dz = a.z - b.z;
00155 return dx*dx + dy*dy + dz*dz;
00156 }
00157 };
00158
00159 }
00160
00161 #endif // RGBDTOOLS_MOTION_ESTIMATION_PAIRWISE_RANSAC_H
00162