Brian Silverman | 4b0bcaf | 2022-01-01 22:48:55 -0800 | [diff] [blame] | 1 | #ifndef Y2020_VISION_SIFT_GET_GAUSSIAN_KERNEL_H_ |
| 2 | #define Y2020_VISION_SIFT_GET_GAUSSIAN_KERNEL_H_ |
| 3 | |
| 4 | #include <cmath> |
| 5 | #include <vector> |
| 6 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 7 | namespace frc971::vision { |
Brian Silverman | 4b0bcaf | 2022-01-01 22:48:55 -0800 | [diff] [blame] | 8 | |
| 9 | // A reimplementation of cv::getGaussianKernel for CV_32F without external |
| 10 | // dependencies. See fast_gaussian_halide_generator.sh for details why we want |
| 11 | // this. |
| 12 | inline std::vector<float> GetGaussianKernel(int ksize, double sigma) { |
| 13 | std::vector<float> result; |
| 14 | float total = 0; |
| 15 | for (int i = 0; i < ksize; ++i) { |
| 16 | const float x = i - (ksize - 1) / 2; |
| 17 | result.push_back(std::exp(-x * x / (2 * sigma * sigma))); |
| 18 | total += result.back(); |
| 19 | } |
| 20 | for (float &r : result) { |
| 21 | r /= total; |
| 22 | } |
| 23 | return result; |
| 24 | } |
| 25 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 26 | } // namespace frc971::vision |
Brian Silverman | 4b0bcaf | 2022-01-01 22:48:55 -0800 | [diff] [blame] | 27 | |
| 28 | #endif // Y2020_VISION_SIFT_GET_GAUSSIAN_KERNEL_H_ |