偷偷拿来记录一下萌新的cs路——day 42 暑假培训作业
处理平面图形需要用到2D卷积。常见锐化滤波器:
(-k -k -k
-k 8k -k
-k -k -k)
用(0,1,0 处理:
-1,5,-1
0,-1,0)
#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main()
{// Read imageMat image = imread("cat.jpg");// Print error messageif (image.empty()) {cout << "Cannot read image. " << endl;}// Apply sharpening using kernelMat sharp_img;Mat kernel3 = (Mat_<double>(3, 3) << 0, -1, 0,-1, 5, -1,0, -1, 0);filter2D(image, sharp_img, -1, kernel3, Point(-1, -1), 0, BORDER_DEFAULT); // BORDER_DEFAULT: calculate all bordersimshow("Original", image);imshow("Sharpenned", sharp_img);imwrite("sharp_image.jpg", sharp_img);waitKey();destroyAllWindows();
}
用(-1,-1,-1, 处理:
-1,9,-1,
-1,-1,-1)