#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace std;
static int mask( int argc, char* argv[])
{
Mat src, dst;
src = imread("./data/lena.jpg", IMREAD_COLOR);
if (src.empty())
{
cerr << "Can't open image" << endl;
return EXIT_FAILURE;
}
namedWindow("Input", WINDOW_AUTOSIZE);
namedWindow("Output", WINDOW_AUTOSIZE);
imshow( "Input", src );
Mat kernel = (Mat_<char>(3,3) << 0, -1, 0,
-1, 5, -1,
0, -1, 0);
filter2D( src, dst, src.depth(), kernel );
imshow( "Output", dst );
waitKey();
return EXIT_SUCCESS;
}
int main( int argc, char ** argv )
{
mask(argc, argv);
return 0;
}
- 效果
![](https://i-blog.csdnimg.cn/blog_migrate/ea587a9884841587b69ed132dc08d982.png#pic_center)