place_recognition.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Intelligent Robotics Lab, DLUT.
00005  *  Author: Qinghua Li, Yan Zhuang, Fei Yan
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Intelligent Robotics Lab, DLUT. nor the names
00020  *     of its contributors may be used to endorse or promote products
00021  *     derived from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  */
00036 
00037 #ifndef PLACE_RECOGNITION_H_
00038 #define PLACE_RECOGNITION_H_
00039 
00040 #include <QFileDialog>
00041 #include <QMessageBox>
00042 #include <boost/foreach.hpp>
00043 #include "dlut_place_recognition/bearing_angle_image.h"
00044 
00045 #define NEIGHBOR 24
00046 #define SCANOCTAVE 3
00047 #define FILTERSCALE 4
00048 
00049 typedef struct GlobalFeature
00050 {
00051   /* Global features */
00052   double area;         // area of scene
00053   double duty_cycle;   // duty cycle of scene
00054 } GlobalFeature;
00055 
00056 typedef struct SURFDescriptor
00057 {
00058   int x;
00059   int y;
00060   int laplacian;
00061   double s;
00062   double dir;
00063   double mod;
00064   struct SURFDescriptor* fwd_match;
00065   void* feature_data;
00066   double vector[128];
00067   pcl::PointXYZ cor_point;  // The corresponding position of laser point for this pixel
00068   std::vector < pcl::PointXYZ > laser_neighbors;  // The neighborhood laser points for this pixel
00069 } SURFDescriptor;
00070 
00071 typedef struct SURFPoint
00072 {
00073   int x;
00074   int y;
00075   int laplacian;
00076   int size;
00077   int octave;
00078   int scale;
00079 } SURFPoint;
00080 
00081 /* A node in a KD-Tree */
00082 typedef struct SURFKDNode
00083 {
00084   int ki;                     /* interval index */
00085   double kv;                  /* interval key value */
00086   int leaf;                   /* 1 or 0 */
00087   SURFDescriptor* features;   /* the feature of node */
00088   int n;                      /* the number of features */
00089   struct SURFKDNode* kd_left;   /* left child */
00090   struct SURFKDNode* kd_right;  /* right child */
00091 } SURFKDNode;
00092 
00093 typedef struct BbfData
00094 {
00095   double d;
00096   void* old_data;
00097 } BbfData;
00098 
00099 /* One element in the minimum priority queue */
00100 typedef struct PqNode
00101 {
00102   void* data;
00103   int key;
00104 } PqNode;
00105 
00106 /* A minimum priority queue */
00107 typedef struct MinPq
00108 {
00109   PqNode* pq_array;   /* the array of containing priority queue */
00110   int nallocd;         /* the number of allocating elements */
00111   int n;               /* the number of elements in queue */
00112 } MinPq;
00113 
00114 
00115 class PlaceRecognition
00116 {
00117   public:
00118     PlaceRecognition ();
00119     ~PlaceRecognition ();
00120 
00121   public:
00122     bool extractGlobalFeature (std::vector< std::vector<pcl::PointXYZ> > &points, GlobalFeature* global_feature);
00123 
00124     void cvSURFInitialize ();
00125 
00126     CvSeq* cvSURFDescriptor (const CvArr* _img, CvMemStorage* storage, double quality, int flags = 0);
00127 
00128     bool drawSURFFeatures (IplImage* img, CvSeq* feat, int n);
00129 
00130     void readFeaturesFromFile ();
00131 
00132     CvSeq* findSURFMatchPairs (CvSeq* sep, int n, std::vector<SURFDescriptor> sfeat, CvMemStorage* storage);
00133 
00134     double getMatchDegree (CvSeq* seq);
00135 
00136   private:
00137     void cvSURFGaussian (CvMat* mat, double s);
00138 
00139     CvSeq* cvFastHessianDetector (const CvMat* sum, CvMemStorage* storage, double quality);
00140 
00141     void cvResizeHaarPattern (int* t_s, int* t_d, int OldSize, int NewSize);
00142 
00143     double cvCalHaarPattern (int* origin, int* t, int widthStep);
00144 
00145     SURFPoint cvSURFPoint (int x, int y, int laplacian, int size, int octave, int scale);
00146 
00147     void drawSURFLoweFeatures (IplImage*, CvSeq*, int);
00148 
00149     void drawSURFLoweFeature (IplImage*, SURFDescriptor*, CvScalar);
00150 
00151     SURFKDNode* buildKDTree (SURFDescriptor* features, int n, int flags);
00152 
00153     SURFKDNode* initKDNode (SURFDescriptor* features, int n);
00154 
00155     void expandKDNodeSubtree (SURFKDNode* kd_node, int flags);
00156 
00157     void assignPartKey (SURFKDNode* kd_node, int flags);
00158 
00159     double selectMedian (double* array, int n);
00160 
00161     double selectRank (double* array, int n, int r);
00162 
00163     void sortInsertion (double* array, int n);
00164 
00165     int partitionArray (double* array, int n, double pivot);
00166 
00167     void partitionFeatures (SURFKDNode* kd_node);
00168 
00169     int KDTreeBbfKnn (SURFKDNode* kd_root, SURFDescriptor* feat, int k,
00170                   SURFDescriptor*** nbrs, int max_nn_chks, int flags);
00171 
00172     MinPq* initMinPq ();
00173 
00174     int insertMinPq (MinPq* min_pq, void* data, int key);
00175 
00176     void decreasePqNodeKey (PqNode* pq_array, int i, int key);
00177 
00178     void restoreMinPqOrder (PqNode* pq_array, int i, int n);
00179 
00180     void* minPqExtractMin (MinPq* min_pq);
00181 
00182     SURFKDNode* exploreToLeaf (SURFKDNode* kd_node, SURFDescriptor* feat, MinPq* min_pq, int flags);
00183 
00184     double descrDistSq (SURFDescriptor* f1, SURFDescriptor* f2, int flags);
00185 
00186     int insertIntoNbrArray (SURFDescriptor* feat, SURFDescriptor** nbrs, int n, int k);
00187 
00188     void releaseMinPq (MinPq** min_pq);
00189 
00190     int doubleArray (void** array, int n, int size);
00191 
00192     void execute (CvSeq* seq);
00193 
00194     void transMatrix (CvSeq* seq);
00195 
00196     void Matrix ();
00197 
00198     void SVD ();
00199 
00200     int Jcbi (double A[], double V[]);
00201 
00202     void initSelect (CvSeq* seq);
00203 
00204     bool Marix (CvSeq* seq, double* RMatrix, double* TVector);
00205 
00206     void cutFalseMatrix();
00207 
00208     double calculateErr (CvSeq* seq, double RMatrix[9], double TVector[3]);
00209 
00210   public:
00211     QStringList files;
00212     int eff_match_pairs;
00213     std::vector<GlobalFeature> global_descriptors;  // Store global features
00214     std::vector< std::vector<SURFDescriptor> > surf_descriptors; // Store SURF features
00215 
00216   private:
00217     CvMat* wrap;
00218     IplImage* region_cache;
00219     IplImage* regions_cache[SCANOCTAVE * FILTERSCALE];
00220 
00221     CvMat* dx_cache;
00222     CvMat* dy_cache;
00223     CvMat* gauss_kernel_cache;
00224 
00225     double cos_cache[3600];
00226     double sin_cache[3600];
00227 
00228     /* Relate to the rotate translation vector */
00229     std::vector<pcl::PointXYZ> lib_points;  // 3D laser feature points of database
00230     std::vector<pcl::PointXYZ> sce_points;  // 3D laser feature points of scene
00231 
00232     double A[9];
00233     double A_AH[9];
00234     double AH_A[9];
00235     double U[9];    // Unit orthogonal eigenvectors matrix of AH*A
00236     double V[9];    // Unit orthogonal eigenvectors matrix of AH*A
00237     pcl::PointXYZ centroid1;  // The centroid of 3D laser feature point cloud in database
00238     pcl::PointXYZ centroid2;  // The centroid of 3D laser feature point cloud in scene
00239 
00240     double RMatrix[9];  // Rotation matrix
00241     double TVector[3];  // Translation vector
00242 
00243     std::vector<double*> RMatrixPlist;  // Pointer array of rotation matrix
00244     std::vector<double*> TVectorPlist;  // Pointer array of translation vector
00245     std::vector<bool> if_false_pairs;    // Whether false matching pairs
00246 };
00247 
00248 #endif // PLACE_RECOGNITION_H_


dlut_place_recognition
Author(s): Qinghua Li, Yan Zhuang, Fei Yan
autogenerated on Sun Oct 5 2014 23:29:57