using namespace cv;
using namespace std;
int main() {
Mat img = imread("D://图片//5.jpg");
if (!img.data) {
cout << "empty" << endl;
}
int num = 3;
img.convertTo(img, CV_32F);
Mat f = ( Mat_<float>(3,3) << 0,0,num,0,0,0,-num,0,0 )/9;
Mat result;
filter2D(img, result, img.depth(), f);
result += 8;
normalize(result, result, 0, 1, CV_MINMAX);
imshow("result", result);
waitKey(0);
destroyAllWindows;
return 0;
}
效果: