Go to the documentation of this file.00001 #ifndef LC_H
00002 #define LC_H
00003
00004 #include <ros/ros.h>
00005 #include <tf/transform_broadcaster.h>
00006 #include <image_geometry/stereo_camera_model.h>
00007 #include "hash.h"
00008 #include "image.h"
00009
00010 using namespace std;
00011 using namespace Eigen;
00012
00013 namespace haloc
00014 {
00015
00016 class LoopClosure
00017 {
00018
00019 public:
00020
00021
00022 LoopClosure();
00023
00024 struct Params
00025 {
00026
00027 Params();
00028
00029
00030 string work_dir;
00031 string image_dir;
00032 int num_proj;
00033 string desc_type;
00034 string desc_matching_type;
00035 double desc_thresh_ratio;
00036 int epipolar_thresh;
00037 int min_neighbor;
00038 int n_candidates;
00039 int group_range;
00040 int min_matches;
00041 int min_inliers;
00042 double max_reproj_err;
00043 bool verbose;
00044 bool save_images;
00045
00046
00047 static const int DEFAULT_NUM_PROJ = 2;
00048 static const double DEFAULT_DESC_THRESH_RATIO = 0.8;
00049 static const int DEFAULT_EPIPOLAR_THRESH = 1;
00050 static const int DEFAULT_MIN_NEIGHBOR = 10;
00051 static const int DEFAULT_N_CANDIDATES = 2;
00052 static const int DEFAULT_GROUP_RANGE = 5;
00053 static const int DEFAULT_MIN_MATCHES = 20;
00054 static const int DEFAULT_MIN_INLIERS = 12;
00055 static const double DEFAULT_MAX_REPROJ_ERR = 2.0;
00056 static const bool DEFAULT_VERBOSE = false;
00057 static const bool DEFAULT_SAVE_IMAGES = false;
00058 };
00059
00060
00061 void setParams(const Params& params);
00062
00063
00064 inline Params params() const { return params_; }
00065
00066
00067 void init();
00068
00069
00070 void finalize();
00071
00072
00073 void setCameraModel(image_geometry::StereoCameraModel stereo_camera_model,
00074 cv::Mat camera_matrix);
00075
00076
00077 int setNode(cv::Mat img);
00078
00079
00080 int setNode(cv::Mat img_l,
00081 cv::Mat img_r);
00082
00083
00084 bool getHash(int img_id, vector<float>& hash);
00085
00086
00087 bool hashMatching(int img_id_a, int img_id_b, float& matching);
00088
00089
00090 void getCandidates(vector< pair<int,float> >& candidates);
00091
00092
00093 void getCandidates(int image_id,
00094 vector< pair<int,float> >& candidates);
00095
00096
00097 bool getLoopClosure(int& lc_img_id);
00098
00099
00100
00101 bool getLoopClosure(int& lc_img_id,
00102 tf::Transform& trans);
00103
00104 bool getLoopClosure(int img_id_a,
00105 int img_id_b,
00106 tf::Transform& trans,
00107 bool logging=false);
00108 bool getLoopClosure(int img_id_a,
00109 int img_id_b,
00110 tf::Transform& trans,
00111 int& matches,
00112 int& inliers,
00113 bool logging=false);
00114
00115 private:
00116
00117
00118 bool compute(Image query,
00119 Image candidate,
00120 int &matches,
00121 int &inliers,
00122 tf::Transform& trans);
00123
00124
00125 void getBestMatchings(int image_id,
00126 int best_n,
00127 vector< pair<int,float> > &best_matchings);
00128
00129
00130 void buildLikelihoodVector(vector< pair<int,float> > hash_matchings,
00131 vector< pair<int,float> > &likelihood);
00132
00133
00134 void getMatchingsLikelihood(vector< pair<int,float> > matchings,
00135 vector<float> &matchings_likelihood,
00136 vector< pair<int,float> > cur_likelihood,
00137 vector< pair<int,float> > prev_likelihood);
00138
00139
00140 void groupSimilarImages(vector< pair<int,float> > matchings,
00141 vector< vector<int> > &groups);
00142
00143
00144 Image getImage(string img_file);
00145
00146
00147 Params params_;
00148 Image query_;
00149 Hash hash_;
00150 int img_id_;
00151 cv::Mat camera_matrix_;
00152 vector< pair<int, vector<float> > > hash_table_;
00153 vector<int> lc_candidate_positions_;
00154 vector< pair<int,float> > prev_likelihood_;
00155 vector< pair<int, int > > lc_found_;
00156
00157
00158 };
00159
00160 }
00161
00162 #endif // LC_H