Go to the documentation of this file.00001
00024 #ifndef RGBDTOOLS_KEYFRAME_GRAPH_DETECTOR_H
00025 #define RGBDTOOLS_KEYFRAME_GRAPH_DETECTOR_H
00026
00027 #include <boost/thread/mutex.hpp>
00028 #include <set>
00029 #include <pcl/registration/transformation_estimation_svd.h>
00030 #include <opencv2/nonfree/features2d.hpp>
00031 #include <aruco/aruco.h>
00032
00033 #include "rgbdtools/types.h"
00034 #include "rgbdtools/rgbd_keyframe.h"
00035 #include "rgbdtools/map_util.h"
00036 #include "rgbdtools/graph/keyframe_association.h"
00037
00038 namespace rgbdtools {
00039
00043 class KeyframeGraphDetector
00044 {
00045 public:
00046
00047 enum CandidateGenerationMethod
00048 {
00049 CANDIDATE_GENERATION_BRUTE_FORCE,
00050 CANDIDATE_GENERATION_SURF_TREE
00051 };
00052
00053 enum PairwiseMatchingMethod
00054 {
00055 PAIRWISE_MATCHING_BFSAC,
00056 PAIRWISE_MATCHING_RANSAC
00057 };
00058
00059 enum PairwiseMatcherIndex
00060 {
00061 PAIRWISE_MATCHER_LINEAR,
00062 PAIRWISE_MATCHER_KDTREE
00063 };
00064
00069 KeyframeGraphDetector();
00070
00073 virtual ~KeyframeGraphDetector();
00074
00075 void setMaxIterations(bool ransac_max_iterations);
00076 void setVerbose(bool verbose);
00077 void setNCandidates(int n_candidates);
00078 void setKNearestNeighbors(int k_nearest_neighbors);
00079 void setNKeypoints(int n_keypoints);
00080 void setOutputPath(const std::string& output_path);
00081 void setSACSaveResults(bool sac_save_results);
00082 void setSACReestimateTf(bool sac_reestimate_tf);
00083 void setCandidateGenerationMethod(CandidateGenerationMethod candidate_method);
00084 void setPairwiseMatchingMethod(PairwiseMatchingMethod pairwsie_matching_method);
00085 void setPairwiseMatcherIndex(PairwiseMatcherIndex pairwsie_matcher_index);
00086 void setMapping(bool mapping);
00087 void setSacMinInliers(int min);
00088 void setMatcherUseDescRatioTest(bool matcher_use_desc_ratio_test);
00089 void setMatcherMaxDescRatio(double matcher_max_desc_ratio);
00090 void setMatcherMaxDescDist(double matcher_max_desc_dist);
00091
00092 const cv::Mat getAssociationMatrix() const { return association_matrix_; }
00093 const cv::Mat getCandidateMatrix() const { return candidate_matrix_; }
00094 const cv::Mat getCorrespondenceMatrix() const { return correspondence_matrix_; }
00095 const cv::Mat getMatchMatrix() const { return match_matrix_; }
00096 const std::vector<std::vector<aruco::Marker> > getMarkers() const { return found_markers; }
00097
00102 void generateKeyframeAssociations(
00103 KeyframeVector& keyframes,
00104 KeyframeAssociationVector& associations);
00105 void generateKeyframeAssociations_Iterative(
00106 KeyframeVector& keyframes,
00107 KeyframeAssociationVector& associations);
00108
00109
00110 void prepareFeaturesForRANSAC_mine(KeyframeVector& keyframes);
00111 void prepareFeaturesForRANSAC_Iterative(u_int kf_idx, KeyframeVector& keyframes);
00112 void prepareFeaturesForRANSAC(KeyframeVector& keyframes);
00113 void buildMatchMatrixSurfTree_Iterative(unsigned int kf_idx,
00114 const KeyframeVector& keyframes);
00115 void buildAssociationMatrix(
00116 const KeyframeVector& keyframes,
00117 KeyframeAssociationVector& associations);
00118 void buildAssociationMatrix_Iterative(
00119 const KeyframeVector& keyframes,
00120 KeyframeAssociationVector& associations);
00121
00122
00123 bool verbose_;
00124 bool mapping_;
00127 int ransac_max_iterations_;
00128
00134 int sac_min_inliers_;
00135
00136 bool matcher_use_desc_ratio_test_;
00137
00138 double matcher_max_desc_ratio_;
00139
00143 double matcher_max_desc_dist_;
00144
00148 double sac_max_eucl_dist_sq_;
00149
00150 bool sac_reestimate_tf_;
00151
00152 double ransac_sufficient_inlier_ratio_;
00153
00154 double ransac_confidence_;
00155 double log_one_minus_ransac_confidence_;
00156
00160 bool sac_save_results_;
00161
00164 std::string output_path_;
00165
00169 double n_candidates_;
00170
00173 int k_nearest_neighbors_;
00174
00177 int n_keypoints_;
00178
00179 double init_surf_threshold_;
00180
00181 int n_matches_accept;
00182
00184 CandidateGenerationMethod candidate_method_;
00185
00186 PairwiseMatchingMethod pairwise_matching_method_;
00187
00188 PairwiseMatcherIndex pairwise_matcher_index_;
00189
00190
00191 float marker_size;
00192 std::vector<std::vector<aruco::Marker> > found_markers;
00193
00194 u_int n_original_poses;
00195
00196
00198 cv::Mat association_matrix_;
00199
00201 cv::Mat candidate_matrix_;
00202
00204 cv::Mat correspondence_matrix_;
00205
00207 cv::Mat match_matrix_;
00208
00209 std::vector<cv::FlannBasedMatcher> matchers_;
00210
00211
00212
00213 void buildCandidateMatrix(const KeyframeVector& keyframes);
00214
00215 void buildMatchMatrixSurfTree(const KeyframeVector& keyframes);
00216 void buildCandidateMatrixSurfTree_Iterative(int v);
00217
00218 void buildCandidateMatrixSurfTree();
00219
00220 void buildCorrespondenceMatrix(
00221 const KeyframeVector& keyframes,
00222 KeyframeAssociationVector& associations);
00223 void buildCorrespondenceMatrix_mine(
00224 const KeyframeVector& keyframes,
00225 KeyframeAssociationVector& associations);
00226 void buildCorrespondenceMatrix_onlyLandmarks(
00227 const KeyframeVector& keyframes,
00228 KeyframeAssociationVector& associations);
00229 void buildCorrespondenceMatrix_mine_Iterative(u_int kf_idx_q,
00230 const KeyframeVector& keyframes,
00231 KeyframeAssociationVector& associations);
00232 void buildCorrespondenceMatrix_rgb_Iterative(u_int kf_idx_q,
00233 const KeyframeVector& keyframes,
00234 KeyframeAssociationVector& associations);
00235 int pairwiseMatching(
00236 int kf_idx_q, int kf_idx_t,
00237 const KeyframeVector& keyframes,
00238 DMatchVector& best_inlier_matches,
00239 Eigen::Matrix4f& best_transformation);
00240
00241 int pairwiseMatchingBFSAC(
00242 int kf_idx_q, int kf_idx_t,
00243 const KeyframeVector& keyframes,
00244 DMatchVector& best_inlier_matches,
00245 Eigen::Matrix4f& best_transformation);
00246
00247 int pairwiseMatchingRANSAC(
00248 int kf_idx_q, int kf_idx_t,
00249 const KeyframeVector& keyframes,
00250 DMatchVector& best_inlier_matches,
00251 Eigen::Matrix4f& best_transformation);
00252
00253 int pairwiseMatchingRANSAC(
00254 int kf_idx_q, int kf_idx_t,
00255 const KeyframeVector& keyframes,
00256 DMatchVector& best_inlier_matches,
00257 Eigen::Matrix4f& best_transformation,
00258 std::vector<cv::DMatch> matches);
00259
00260 void getCandidateMatches(
00261 const RGBDFrame& frame_q, const RGBDFrame& frame_t,
00262 cv::FlannBasedMatcher& matcher,
00263 DMatchVector& candidate_matches);
00264
00265 void prepareMatchers(
00266 const KeyframeVector& keyframes);
00267 private:
00268 };
00269
00270 }
00271
00272 #endif // RGBDTOOLS_KEYFRAME_GRAPH_DETECTOR_H