汉宁窗作用:
- 防止在 DFT 或 FFT 过程中出现频率泄露
代码:
#include <iostream>
#include "opencv2/highgui.hpp"
#define PI 3.1415926
cv::Mat CreatHannWindow(int width, int height)
{
cv::Mat vertical(height, 1, CV_32FC1);
cv::Mat horizontal(1, width, CV_32FC1);
for (int r = 0; r < height; r++)
{
vertical.at<float>(r, 0) = 0.5 - 0.5 * cos(2 * PI * r / (height - 1));
}
for (int c = 0; c < width; c++)
{
horizontal.at<float>(0, c) = 0.5 - 0.5 * cos(2 * PI * c / (width - 1));
}
cv::Mat out = vertical * horizontal;
return out;
}
int main()
{
cv::Mat out = CreatHannWindow(200, 200);
return 1;
}
得到的汉宁窗效果: