模板 0 -1 0
-1 5 -1
0 -1 0
#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace cv;
int main()
{
Mat src,dst;
src = imread("aa.jpg");
if(!src.data)
{
printf("加载失败");
return -1;
}
imshow("src",src);
int cols=src.cols*src.channels();
int rows=src.rows;
int offsex=src.channels(); std::cout<<src.rows<<" "<<src.cols;
dst= Mat(src.size(),src.type());
double t=getTickCount();
for(int i= 1;i<rows-1;i++)
{
const uchar *previous=src.ptr<uchar>(i-1);
const uchar *current =src.ptr<uchar>(i);
const uchar *next =src.ptr<uchar>(i+1);
uchar *output=dst.ptr<uchar>(i);
for(int j=offsex;j<cols;j++)
{
output[j]=saturate_cast<uchar>(5*current[j]-(current[j-offsex]+current[j+offsex]+previous[j]+next[j]));
}
}
/*Mat kernel=(Mat_<char>(3,3)<<0,-1,0,-1,5,-1,0,-1,0);
filter2D(src,dst,src.depth(),kernel);*/ // opencv 自带的掩模函数
double timeconsum =(getTickCount()-t)/getTickFrequency();
printf("time consum %.2fs\n",timeconsum);
imshow("dst",dst);
waitKey(0);
return 0;
}