lc.h
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   // Class constructor
00022   LoopClosure();
00023 
00024   struct Params
00025   {
00026     //Default constructor sets all values to defaults.
00027     Params();
00028 
00029     // Class parameters
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     // Default values
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   // Set the parameter struct.
00061   void setParams(const Params& params);
00062 
00063   // Return current parameters.
00064   inline Params params() const { return params_; }
00065 
00066   // Initialize class.
00067   void init();
00068 
00069   // Finalize class.
00070   void finalize();
00071 
00072   // Save the camera model.
00073   void setCameraModel(image_geometry::StereoCameraModel stereo_camera_model,
00074                       cv::Mat camera_matrix);
00075 
00076   // Compute kp, desc and hash for one image (mono version).
00077   int setNode(cv::Mat img);
00078 
00079   // Compute kp, desc and hash for two images (stereo version).
00080   int setNode(cv::Mat img_l,
00081               cv::Mat img_r);
00082 
00083   // Returns the hash for a node.
00084   bool getHash(int img_id, vector<float>& hash);
00085 
00086   // Compute the hash matching between two nodes
00087   bool hashMatching(int img_id_a, int img_id_b, float& matching);
00088 
00089   // Retrieve the candidates to close loop with the last saved node.
00090   void getCandidates(vector< pair<int,float> >& candidates);
00091 
00092   // Retrieve the candidates to close loop with the specified node.
00093   void getCandidates(int image_id,
00094                      vector< pair<int,float> >& candidates);
00095 
00096   // Try to find a loop closure for the last saved node.
00097   bool getLoopClosure(int& lc_img_id);
00098   /* Try to find a loop closure for the last saved node
00099      and get the transformation (2D for mono and 3D for stereo).
00100    */
00101   bool getLoopClosure(int& lc_img_id,
00102                       tf::Transform& trans);
00103   // Try to find a loop closure given 2 image identifiers
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   // Compute the loop closure
00118   bool compute(Image query,
00119                Image candidate,
00120                int &matches,
00121                int &inliers,
00122                tf::Transform& trans);
00123 
00124   // Get the best matchings given an image id
00125   void getBestMatchings(int image_id,
00126                         int best_n,
00127                         vector< pair<int,float> > &best_matchings);
00128 
00129   // Build the likelihood vector
00130   void buildLikelihoodVector(vector< pair<int,float> > hash_matchings,
00131                              vector< pair<int,float> > &likelihood);
00132 
00133   // Compute the likelihood for every matching
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   // Group similar images
00140   void groupSimilarImages(vector< pair<int,float> > matchings,
00141                           vector< vector<int> > &groups);
00142 
00143   // Get the image information from file
00144   Image getImage(string img_file);
00145 
00146   // Properties
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 } // namespace
00161 
00162 #endif // LC_H


libhaloc
Author(s): Pep Lluis Negre
autogenerated on Thu Jun 6 2019 21:25:00