blob: b351d7059bcef1874d7caf902a98dea2f66a3fd8 [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
9namespace frc971 {
10namespace vision {
11
12/*!
13 SIFT implementation.
14
15 The class implements SIFT algorithm by D. Lowe.
16 */
17class SIFT971_Impl : public cv::Feature2D {
18 public:
19 explicit SIFT971_Impl(int nfeatures = 0, int nOctaveLayers = 3,
20 double contrastThreshold = 0.04,
21 double edgeThreshold = 10, double sigma = 1.6);
22
23 //! returns the descriptor size in floats (128)
24 int descriptorSize() const override;
25
26 //! returns the descriptor type
27 int descriptorType() const override;
28
29 //! returns the default norm type
30 int defaultNorm() const override;
31
32 //! finds the keypoints and computes descriptors for them using SIFT
33 //! algorithm. Optionally it can compute descriptors for the user-provided
34 //! keypoints
35 void detectAndCompute(cv::InputArray img, cv::InputArray mask,
36 std::vector<cv::KeyPoint> &keypoints,
37 cv::OutputArray descriptors,
38 bool useProvidedKeypoints = false) override;
39
40 void buildGaussianPyramid(const cv::Mat &base, std::vector<cv::Mat> &pyr,
41 int nOctaves) const;
42 void buildDoGPyramid(const std::vector<cv::Mat> &pyr,
43 std::vector<cv::Mat> &dogpyr) const;
Brian Silverman3fec6482020-01-19 17:56:20 -080044 void buildGaussianAndDifferencePyramid(const cv::Mat &base,
45 std::vector<cv::Mat> &pyr,
46 std::vector<cv::Mat> &dogpyr,
47 int nOctaves) const;
Brian Silvermanf1196122020-01-16 00:41:54 -080048 void findScaleSpaceExtrema(const std::vector<cv::Mat> &gauss_pyr,
49 const std::vector<cv::Mat> &dog_pyr,
50 std::vector<cv::KeyPoint> &keypoints) const;
51
52 protected:
53 CV_PROP_RW int nfeatures;
54 CV_PROP_RW int nOctaveLayers;
55 CV_PROP_RW double contrastThreshold;
56 CV_PROP_RW double edgeThreshold;
57 CV_PROP_RW double sigma;
Brian Silverman3fec6482020-01-19 17:56:20 -080058
59 private:
60 cv::Mat createInitialImage(const cv::Mat &img, bool doubleImageSize) const;
61
62 bool use_fast_gaussian_pyramid_ = true;
63 bool use_fast_subtract_dogpyr_ = true;
64 bool use_fast_guassian_initial_ = true;
65 bool use_fused_pyramid_difference_ = true;
66 bool use_fast_pyramid_difference_ = true;
Brian Silvermanf1196122020-01-16 00:41:54 -080067};
68
69} // namespace vision
70} // namespace frc971
71
72#endif // Y2020_VISION_SIFT_SIFT971_H_