OpenCv图像处理之中值滤波-非线性滤波
test.cpp文件//用于定义常用的函数
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void resize_img(Mat &mat, int width, int height, int interpolation = INTER_AREA) {
cv::resize(mat, mat, Size(width, height), 0, 0, interpolation);
}
Mat zero_mat(Mat mat, int width, int height) {
Mat dst = Mat::zeros(Size(width, height), mat.type());
return dst;
}
main.cpp文件
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void resize_img(Mat &mat, int width, int height, int interpolation = INTER_AREA);
Mat zero_mat(Mat mat, int width, int height);
int main() {
Mat original_img, clone_img, dst_img;
original_img = imread("D:/cat.jpg", IMREAD_COLOR);
if (original_img.empty()) {
cout << "open error!" << endl;
return -1;
}
clone_img = original_img.clone();
double scale = 0.5;
int width = int(clone_img.cols * scale);
int height = int(clone_img.rows * scale);
resize_img(clone_img, width, height);
dst_img = zero_mat(dst_img, width, height);
medianBlur(clone_img, dst_img, 9);
imshow("dst", dst_img);
waitKey(0);
return 0;
}
效果显示
|