00001
00028 #ifndef __D_SURF_SET__
00029 #define __D_SURF_SET__
00030
00031
00032
00033 #define USURF_SUPPORTED 0
00034
00035 #include <opencv/cv.h>
00036 #include <opencv/highgui.h>
00037 #include <vector>
00038 #include <string>
00039
00040 namespace DVision {
00041
00042 class Matches;
00043
00045 class SurfSet
00046 {
00047 public:
00049 std::vector<cv::KeyPoint> keys;
00051 std::vector<float> descriptors;
00053 std::vector<int> laplacians;
00054
00055 public:
00056
00057 SurfSet(): m_index(NULL) {}
00058 virtual ~SurfSet(){ delete m_index; }
00059
00066 void Extract(const cv::Mat &image,
00067 double hessianTh = 400.0, bool extended = false);
00068
00069 #if USURF_SUPPORTED
00070
00080 void _ExtractUpright(const cv::Mat &image,
00081 double hessianTh = 400.0, bool extended = false);
00082 #endif
00083
00091 void Compute(const cv::Mat &image,
00092 const std::vector<cv::KeyPoint> &keypoints, bool extended = false);
00093
00094 #if USURF_SUPPORTED
00095
00104 void _ComputeUpright(const cv::Mat &image,
00105 const std::vector<cv::KeyPoint> &keypoints, bool extended = false);
00106 #endif
00107
00113 inline int GetDescriptorLength() const
00114 {
00115 if(!keys.empty()) return descriptors.size() / keys.size();
00116 else return 0;
00117 }
00118
00122 inline unsigned int size() const
00123 {
00124 return keys.size();
00125 }
00126
00130 inline bool empty() const
00131 {
00132 return keys.empty();
00133 }
00134
00140 inline std::vector<float> get(unsigned int i) const;
00141
00146 void Remove(unsigned int i);
00147
00152 void Remove(const std::vector<unsigned int> &ids);
00153
00164 void CalculateCorrespondences(const SurfSet &B,
00165 std::vector<int> &A_corr, std::vector<int> &B_corr,
00166 std::vector<double> *distances = NULL,
00167 bool remove_duplicates = true,
00168 double max_ratio = 0.6) const;
00169
00180 void CalculateFastCorrespondences(const SurfSet &B,
00181 std::vector<int> &A_corr, std::vector<int> &B_corr,
00182 std::vector<double> *distances = NULL,
00183 bool remove_duplicates = true,
00184 double max_ratio = 0.6);
00185
00191 void RecalculateApproximationTree();
00192
00197 void Save(const std::string &filename) const;
00198
00203 void Load(const std::string &filename);
00204
00213 void SaveCustom(const std::string &filename) const;
00214
00219 void LoadCustom(const std::string &filename);
00220
00221 protected:
00222 friend class Matches;
00223
00230 void save(cv::FileStorage &fs, int idx) const;
00231
00238 void load(cv::FileStorage &fs, int idx);
00239
00240 protected:
00241
00248 void extract(const cv::Mat &image, const CvSURFParams ¶ms);
00249
00257 void compute(const cv::Mat &image,
00258 const std::vector<cv::KeyPoint> &keypoints, const CvSURFParams ¶ms);
00259
00266 double calculateSqDistance(std::vector<float>::const_iterator ita,
00267 std::vector<float>::const_iterator itb, const int L) const;
00268
00278 void calculateCorrespondencesNaive(const SurfSet &B,
00279 std::vector<int> &A_corr, std::vector<int> &B_corr,
00280 std::vector<double> *distances,
00281 bool remove_duplicates, double max_ratio) const;
00282
00292 void calculateCorrespondencesApproximate(const SurfSet &B,
00293 std::vector<int> &A_corr, std::vector<int> &B_corr,
00294 std::vector<double> *distances,
00295 bool remove_duplicates, double max_ratio);
00296
00304 int getPointOctave(const CvSURFPoint& kpt, const CvSURFParams& params) const;
00305
00306 protected:
00307
00309 cv::flann::Index *m_index;
00310 };
00311
00312
00313
00314 std::vector<float> SurfSet::get(unsigned int i) const
00315 {
00316 std::vector<float> ret;
00317 if(i < keys.size())
00318 {
00319 const unsigned int L = descriptors.size() / keys.size();
00320 ret.resize(L);
00321 std::copy(this->descriptors.begin() + i*L,
00322 this->descriptors.begin() + (i+1)*L, ret.begin());
00323 }
00324 return ret;
00325 }
00326
00327 }
00328
00329 #endif
00330