00001 #ifndef _FDETECT_SIFT_DETECTOR_HPP_
00002 #define _FDETECT_SIFT_DETECTOR_HPP_
00003
00004 #ifdef HAVE_SIFT
00005
00006 #include <cv.h>
00007 #include <cv.hpp>
00008
00009 extern "C" {
00010 #include <sift.h>
00011 }
00012
00013 #include <boost/archive/text_oarchive.hpp>
00014 #include <boost/archive/text_iarchive.hpp>
00015
00016 #include "fdetect/Detector.hpp"
00017
00018 namespace jafar {
00019 namespace fdetect {
00024 class SIFTDetector : public fdetect::Detector {
00025 private:
00027 struct feature* detectedFeatures;
00029 int m_intervals;
00031 double m_sigma;
00033 double m_contrastThreshold;
00035 int m_curvatureThreshold;
00037 bool m_doubleImageSize;
00039 int m_descriptorHistogramWidth;
00041 int m_descriptorHistogramBins;
00042
00044 friend class boost::serialization::access;
00045 template<class Archive>
00046 void serialize(Archive & ar, const unsigned int ){
00047 ar & m_intervals;
00048 ar & m_sigma;
00049 ar & m_contrastThreshold;
00050 ar & m_curvatureThreshold;
00051 ar & m_doubleImageSize;
00052 ar & m_descriptorHistogramWidth;
00053 ar & m_descriptorHistogramBins;
00054 }
00055
00056 public:
00067 SIFTDetector(const int& intervals = 3, const double& sigma = 1.6,
00068 const double& contrastThreshold = 0.04, const int& curvatureThreshold = 10,
00069 const bool& doubleImageSize = true, const int& descriptorHistogramWidth = 4,
00070 const int& descriptorHistogramBins = 8);
00072 int intervals() const;
00074 double sigma() const;
00076 double contrastThreshold() const;
00078 int curvatureThreshold() const;
00080 bool doubleImageSize() const;
00082 int descriptorHistogramWidth() const;
00084 int descriptorHistogramBins() const;
00085
00086 void setIntervals(const int& intervals);
00087 void setSigma(const double& sigma);
00088 void setContrastThreshold(const double& contrastThreshold);
00089 void setCurvatureThreshold(const int& curvatureThreshold);
00090 void setDoubleImageSize(const bool& doubleImageSize);
00091 void setDescriptorHistogramWidth(const int& descriptorHistogramWidth);
00092 void setDescriptorHistogramBins(const int& descriptorHistogramBins);
00093
00094 virtual fdetect::DetectionResult detectIn(jafar::image::Image const& image);
00095 };
00096 }
00097 }
00098
00099 #else
00100 #include <opencv/cxcore.h>
00101 #if CV_MAJOR_VERSION*10 + CV_MINOR_VERSION > 21
00102 #include <opencv2/features2d/features2d.hpp>
00103 #include "fdetect/Detector.hpp"
00104 #include "fdetect/RealDescriptor.hpp"
00105
00106 namespace jafar {
00107 namespace fdetect_v2 {
00112
00113 template< typename InterestFeatureT >
00114 class SIFTDetectorT : public fdetect_v2::Detector< InterestFeatureT > {
00115 public:
00116 typedef InterestFeatureT InterestFeatureType;
00117 typedef fdetect_v2::DetectionResult<InterestFeatureT> DetectionResult;
00118
00119 SIFTDetectorT(double threshold = 0.04,
00120 double edgeThreshold = 10,
00121 double magnification = 3,
00122 bool isNormalize = true,
00123 bool recalculateAngles = true,
00124 int nOctaves = cv::SIFT::CommonParams::DEFAULT_NOCTAVES,
00125 int nOctaveLayers = cv::SIFT::CommonParams::DEFAULT_NOCTAVE_LAYERS,
00126 int firstOctave = cv::SIFT::CommonParams::DEFAULT_FIRST_OCTAVE,
00127 int angleMode = cv::SIFT::CommonParams::FIRST_ANGLE);
00129
00131 double getThreshold() const { return m_threshold; }
00132 double getEdgeThreshold() const { return m_edgeThreshold; }
00133 double getMagnification() const { return m_magnification; }
00134 bool getIsNormalize() const { return m_isNormalize; }
00135 bool getRecalculateAngles() const { return m_recalculateAngles; }
00136 int getNOctaves() const { return m_nOctaves; }
00137 int getNOctaveLayers() const { return m_nOctaveLayers; }
00138 int getFirstOctave() const { return m_firstOctave; }
00139 int getAngleMode() const { return m_angleMode; }
00141
00143 void setThreshold(double threshold) { m_threshold = threshold; }
00144 void setEdgeThreshold(double edgeThreshold) { m_edgeThreshold = edgeThreshold; }
00145 void setMagnification(double magnification) { m_magnification = magnification; }
00146 void setIsNormalize(bool isNormalize) { m_isNormalize = isNormalize; }
00147 void setRecalculateAngles(bool recalculateAngles) { m_recalculateAngles = recalculateAngles; }
00148 void setNOctaves(int nOctaves) { m_nOctaves = nOctaves; }
00149 void setNOctaveLayers(int nOctaveLayers) { m_nOctaveLayers = nOctaveLayers; }
00150 void setFirstOctave(int firstOctave) { m_firstOctave = firstOctave; }
00151 void setAngleMode(int angleMode) { m_angleMode = angleMode; }
00152
00153 virtual DetectionResult detectIn(jafar::image::Image const& image) {
00154 return detectIn(image, jafar::image::Image(), true);
00155 }
00161 DetectionResult detectIn(jafar::image::Image const& image,
00162 const jafar::image::Image& mask,
00163 bool with_descriptors);
00167 void computeDescriptors(jafar::image::Image const& image,
00168 DetectionResult& dr)
00169 {
00170 computeDescriptors(image, jafar::image::Image(), dr);
00171 }
00175 void computeDescriptors(jafar::image::Image const& image,
00176 const jafar::image::Image& mask,
00177 DetectionResult& dr);
00178 private:
00179 double m_threshold;
00180 double m_edgeThreshold;
00181 double m_magnification;
00182 bool m_isNormalize;
00183 bool m_recalculateAngles;
00184 int m_nOctaves;
00185 int m_nOctaveLayers;
00186 int m_firstOctave;
00187 int m_angleMode;
00188 cv::SIFT cv_sift;
00190 friend class boost::serialization::access;
00191 template<class Archive>
00192 void serialize(Archive & ar, const unsigned int ){
00193 ar & m_threshold;
00194 ar & m_edgeThreshold;
00195 ar & m_magnification;
00196 ar & m_isNormalize;
00197 ar & m_recalculateAngles;
00198 ar & m_nOctaves;
00199 ar & m_nOctaveLayers;
00200 ar & m_firstOctave;
00201 ar & m_angleMode;
00202 }
00203 };
00205 typedef SIFTDetectorT<fdetect_v2::InterestFeature< fdetect_v2::RealDescriptor<float> > > SIFTDetector;
00206 }
00207 }
00208 #include "fdetect/SIFTDetector.hxx"
00209 #endif
00210 #endif
00211 #endif