OpenCV学习十五:filter2D 线性滤波
程序员文章站
2023-12-23 17:23:57
...
简单介绍下函数:
filter2D(输入,输出,卷积核,锚点),其中锚点Point(-1,-1)表示中心。
介绍几个滤波器:
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
char file[] = "1.jpg";
int main(int argc, char** argv)
{
Mat img = imread(file, -1);
pyrDown(img, img, Size(img.cols/2, img.rows/2));
imshow("1",img);
Mat out;
Mat kernel_x = (Mat_<int>(2,2) << 1,0, 0,-1);
filter2D(img, out, -1, kernel_x, Point(-1,-1));
imshow("filter", out);imwrite("filter.jpg", out);
//这里就是为了突出结果
cvtColor(out, out, CV_BGR2GRAY);
normalize(out, out, 255, 0, NORM_MINMAX);
imshow("filter3", out);imwrite("filter3.jpg", out);
waitKey();
return 1;
}
原图:
filter.jpg
filter3.jpg
推荐阅读