blob: a235afb5d0e468a49d2d315e8de9d9d336fa7036 [file] [log] [blame]
Brian Silvermanf1196122020-01-16 00:41:54 -08001#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 Pleinesd99b1ee2024-02-02 20:56:44 -08009namespace frc971::vision {
Brian Silvermanf1196122020-01-16 00:41:54 -080010
11/*!
12 SIFT implementation.
13
14 The class implements SIFT algorithm by D. Lowe.
15 */
16class 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 Silverman3fec6482020-01-19 17:56:20 -080043 void buildGaussianAndDifferencePyramid(const cv::Mat &base,
44 std::vector<cv::Mat> &pyr,
45 std::vector<cv::Mat> &dogpyr,
46 int nOctaves) const;
Brian Silvermanf1196122020-01-16 00:41:54 -080047 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 Silverman3fec6482020-01-19 17:56:20 -080057
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 Silvermanf1196122020-01-16 00:41:54 -080066};
67
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080068} // namespace frc971::vision
Brian Silvermanf1196122020-01-16 00:41:54 -080069
70#endif // Y2020_VISION_SIFT_SIFT971_H_