Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 1 | #ifndef Y2020_VISION_SIFT_SIFT971_H_ |
| 2 | #define Y2020_VISION_SIFT_SIFT971_H_ |
| 3 | |
| 4 | #include <vector> |
| 5 | |
| 6 | #include <opencv2/core/types.hpp> |
| 7 | #include <opencv2/features2d.hpp> |
| 8 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 9 | namespace frc971::vision { |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 10 | |
| 11 | /*! |
| 12 | SIFT implementation. |
| 13 | |
| 14 | The class implements SIFT algorithm by D. Lowe. |
| 15 | */ |
| 16 | class SIFT971_Impl : public cv::Feature2D { |
| 17 | public: |
| 18 | explicit SIFT971_Impl(int nfeatures = 0, int nOctaveLayers = 3, |
| 19 | double contrastThreshold = 0.04, |
| 20 | double edgeThreshold = 10, double sigma = 1.6); |
| 21 | |
| 22 | //! returns the descriptor size in floats (128) |
| 23 | int descriptorSize() const override; |
| 24 | |
| 25 | //! returns the descriptor type |
| 26 | int descriptorType() const override; |
| 27 | |
| 28 | //! returns the default norm type |
| 29 | int defaultNorm() const override; |
| 30 | |
| 31 | //! finds the keypoints and computes descriptors for them using SIFT |
| 32 | //! algorithm. Optionally it can compute descriptors for the user-provided |
| 33 | //! keypoints |
| 34 | void detectAndCompute(cv::InputArray img, cv::InputArray mask, |
| 35 | std::vector<cv::KeyPoint> &keypoints, |
| 36 | cv::OutputArray descriptors, |
| 37 | bool useProvidedKeypoints = false) override; |
| 38 | |
| 39 | void buildGaussianPyramid(const cv::Mat &base, std::vector<cv::Mat> &pyr, |
| 40 | int nOctaves) const; |
| 41 | void buildDoGPyramid(const std::vector<cv::Mat> &pyr, |
| 42 | std::vector<cv::Mat> &dogpyr) const; |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 43 | void buildGaussianAndDifferencePyramid(const cv::Mat &base, |
| 44 | std::vector<cv::Mat> &pyr, |
| 45 | std::vector<cv::Mat> &dogpyr, |
| 46 | int nOctaves) const; |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 47 | void findScaleSpaceExtrema(const std::vector<cv::Mat> &gauss_pyr, |
| 48 | const std::vector<cv::Mat> &dog_pyr, |
| 49 | std::vector<cv::KeyPoint> &keypoints) const; |
| 50 | |
| 51 | protected: |
| 52 | CV_PROP_RW int nfeatures; |
| 53 | CV_PROP_RW int nOctaveLayers; |
| 54 | CV_PROP_RW double contrastThreshold; |
| 55 | CV_PROP_RW double edgeThreshold; |
| 56 | CV_PROP_RW double sigma; |
Brian Silverman | 3fec648 | 2020-01-19 17:56:20 -0800 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | cv::Mat createInitialImage(const cv::Mat &img, bool doubleImageSize) const; |
| 60 | |
| 61 | bool use_fast_gaussian_pyramid_ = true; |
| 62 | bool use_fast_subtract_dogpyr_ = true; |
| 63 | bool use_fast_guassian_initial_ = true; |
| 64 | bool use_fused_pyramid_difference_ = true; |
| 65 | bool use_fast_pyramid_difference_ = true; |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 68 | } // namespace frc971::vision |
Brian Silverman | f119612 | 2020-01-16 00:41:54 -0800 | [diff] [blame] | 69 | |
| 70 | #endif // Y2020_VISION_SIFT_SIFT971_H_ |