blob: 9252e24b703b516e41149e8e86ba4b2ddb8b1b81 [file] [log] [blame]
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08001#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 Pleinesd99b1ee2024-02-02 20:56:44 -08007namespace frc971::vision {
Brian Silverman4b0bcaf2022-01-01 22:48:55 -08008
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.
12inline 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 Pleinesd99b1ee2024-02-02 20:56:44 -080026} // namespace frc971::vision
Brian Silverman4b0bcaf2022-01-01 22:48:55 -080027
28#endif // Y2020_VISION_SIFT_GET_GAUSSIAN_KERNEL_H_