blob: c13c58886d3af3afc3e90fd231747bb5369a7920 [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
7namespace frc971 {
8namespace vision {
9
10// A reimplementation of cv::getGaussianKernel for CV_32F without external
11// dependencies. See fast_gaussian_halide_generator.sh for details why we want
12// this.
13inline std::vector<float> GetGaussianKernel(int ksize, double sigma) {
14 std::vector<float> result;
15 float total = 0;
16 for (int i = 0; i < ksize; ++i) {
17 const float x = i - (ksize - 1) / 2;
18 result.push_back(std::exp(-x * x / (2 * sigma * sigma)));
19 total += result.back();
20 }
21 for (float &r : result) {
22 r /= total;
23 }
24 return result;
25}
26
27} // namespace vision
28} // namespace frc971
29
30#endif // Y2020_VISION_SIFT_GET_GAUSSIAN_KERNEL_H_