大作业2(Sobel算子)

来源:互联网 发布:世界顶级音乐学院知乎 编辑:程序博客网 时间:2024/06/06 03:16

include

include

using namespace cv;
int main(int argc, char **argv){
Mat src = imread(“C:/opencv/test.jpg”);
if (src.empty()){
printf(“could not load image..\n”);
return -1;
}
namedWindow(“MyWindow”, CV_WINDOW_AUTOSIZE);
imshow(“MyWindow”, src);
Mat dst, gray_dst;
GaussianBlur(src, src, Size(3, 3), 0, 0);
cvtColor(src, gray_dst, CV_BGR2GRAY);
Mat kernel_x = (Mat_(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
Mat kernel_y = (Mat_(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
Mat mat_x, mat_y;
filter2D(gray_dst, mat_x, -1, kernel_x, Point(-1, -1));
filter2D(gray_dst, mat_y, -1, kernel_y, Point(-1, -1));
imshow(“kernel_x”, mat_x);
imshow(“kernel_y”, mat_y);
addWeighted(mat_x, 0.5, mat_y, 0.5, 0, dst);
imshow(“Final”, dst);
cvWaitKey(0);
return 0;
}利用Sobel算子自己实现Sobel函数

原创粉丝点击