1、掩膜
#include <iostream>
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace cv;
int main(){
Mat src,dst;
src = imread("/Users/pc/Desktop/1.jpg");
if(!src.data){
printf("could not load image!");
return -1;
}
namedWindow("input image",CV_WINDOW_AUTOSIZE);
imshow("input image", src);
// //掩膜
// int rows = src.rows-1;
// int cols = (src.cols-1) * src.channels();
// int offset = src.channels();
// //初始化空
// dst = Mat::zeros(src.size(), src.type());
// for(int row=1; row<rows; row++){
// const uchar* previous = src.ptr<uchar>(row-1);
// const uchar* current = src.ptr<uchar>(row);
// const uchar* next = src.ptr<uchar>(row+1);
// uchar* output = dst.ptr<uchar>(row);
// for(int col=offset; col<cols; col++){
// output[col] = saturate_cast<uchar>(5*current[col] - (current[col-offset] + current[col+offset] + previous[col] +next[col]));
// }
// }
double t =getTickCount();
Mat kernel = (Mat_<char>(3,3) << 0,-1,0,-1,5,-1,0,-1,0);
filter2D(src, dst, src.depth(), kernel);
double timeConsume = (getTickCount()-t) / getTickFrequency();
printf("time consume %.3f",timeConsume);
namedWindow("output image", CV_WINDOW_AUTOSIZE);
imshow("output image", dst);
waitKey(0);
return 0;
}