00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00052 double area;
00053 double duty_cycle;
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;
00068 std::vector < pcl::PointXYZ > laser_neighbors;
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
00082 typedef struct SURFKDNode
00083 {
00084 int ki;
00085 double kv;
00086 int leaf;
00087 SURFDescriptor* features;
00088 int n;
00089 struct SURFKDNode* kd_left;
00090 struct SURFKDNode* kd_right;
00091 } SURFKDNode;
00092
00093 typedef struct BbfData
00094 {
00095 double d;
00096 void* old_data;
00097 } BbfData;
00098
00099
00100 typedef struct PqNode
00101 {
00102 void* data;
00103 int key;
00104 } PqNode;
00105
00106
00107 typedef struct MinPq
00108 {
00109 PqNode* pq_array;
00110 int nallocd;
00111 int n;
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;
00214 std::vector< std::vector<SURFDescriptor> > surf_descriptors;
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
00229 std::vector<pcl::PointXYZ> lib_points;
00230 std::vector<pcl::PointXYZ> sce_points;
00231
00232 double A[9];
00233 double A_AH[9];
00234 double AH_A[9];
00235 double U[9];
00236 double V[9];
00237 pcl::PointXYZ centroid1;
00238 pcl::PointXYZ centroid2;
00239
00240 double RMatrix[9];
00241 double TVector[3];
00242
00243 std::vector<double*> RMatrixPlist;
00244 std::vector<double*> TVectorPlist;
00245 std::vector<bool> if_false_pairs;
00246 };
00247
00248 #endif // PLACE_RECOGNITION_H_