博客
关于我
opencv16-Sobel算子
阅读量:791 次
发布时间:2023-02-23

本文共 1661 字,大约阅读时间需要 5 分钟。

Mat src = imread("E:\vs2015\opencvstudy\1.jpg", 1); 如果 (src.empty()) { cout << "could not load the src image!" << endl; return -1; } char *input_title = "input Image"; imshow(input_title, src); Mat blur_image; GaussianBlur(src, blur_image, Size(3, 3), 0, 0); Mat gray_image; cvtColor(blur_image, gray_image, CV_BGR2GRAY); imshow("gray_image", gray_image); Mat xgrad_sobel, ygrad_sobel; Sobel(gray_image, xgrad_sobel, CV_16S, 1, 0, 3); //x方向梯度 Sobel(gray_image, ygrad_sobel, CV_16S, 0, 1, 3); //y方向梯度 convertScaleAbs(xgrad_sobel, xgrad_sobel); convertScaleAbs(ygrad_sobel, ygrad_sobel); imshow("xgrad_sobel", xgrad_sobel); imshow("ygrad_sobel", ygrad_sobel); Mat xygrad_sobel; addWeighted(xgrad_sobel, 0.5, ygrad_sobel, 0.5, 0, xygrad_sobel); imshow("xygrad_sobel", xygrad_sobel); Mat xygrad_sobel2 = Mat(xgrad_sobel.size(), xgrad_sobel.type()); int width = xgrad_sobel.cols; int height = xgrad_sobel.rows; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { int xg = xgrad_sobel.at

(row, col); int yg = ygrad_sobel.at
(row, col); int xy = xg + yg; xygrad_sobel2.at
(row, col) = saturate_cast
(xy); } } imshow("xygrad_sobel2", xygrad_sobel2); //Scharr算子 Mat x2grad_sobel, y2grad_sobel; //Scharr(gray_image, x2grad_sobel, CV_16S, 1, 0); //x方向梯度 //Scharr(gray_image, y2grad_sobel, CV_16S, 0, 1); //y方向梯度 //convertScaleAbs(x2grad_sobel, x2grad_sobel); //convertScaleAbs(y2grad_sobel, y2grad_sobel); //imshow("x2grad_sobel", x2grad_sobel); //imshow("y2grad_sobel", y2grad_sobel); //Mat xy2grad_sobel; //addWeighted(x2grad_sobel, 0.5, y2grad_sobel, 0.5, 0, xy2grad_sobel); //imshow("xy2grad_sobel", xy2grad_sobel); waitKey(0); return 0; }

转载地址:http://zmsfk.baihongyu.com/

你可能感兴趣的文章
Objective-C实现香农编码(附完整源码)
查看>>
Objective-C实现骑士旅游算法(附完整源码)
查看>>
Objective-C实现骑士旅游算法(附完整源码)
查看>>
Objective-C实现高斯-赛德尔迭代算法(附完整算法)
查看>>
Objective-C实现高斯消元法(附完整源码)
查看>>
Objective-C实现高斯消元法(附完整源码)
查看>>
Objective-C实现高斯消元算法(附完整源码)
查看>>
Objective-C实现高斯消去法(附完整源码)
查看>>
Objective-C实现高斯消除算法(附完整源码)
查看>>
Objective-C实现高斯滤波GaussianBlur函数用法(附完整源码)
查看>>
Objective-C实现高斯滤波函数(附完整源码)
查看>>
Objective-C实现高精度乘法(附完整源码)
查看>>
Objective-C实现高精度减法(附完整源码)
查看>>
Objective-C实现高精度除法(附完整源码)
查看>>
Objective-C实现高精度除法(附完整源码)
查看>>
Objective-C实现鸡兔同笼问题(附完整源码)
查看>>
Objective-C实现鸡兔同笼问题(附完整源码)
查看>>
Objective-C实现鼠标点击其他程序(附完整源码)
查看>>
Objective-c正确的写法单身
查看>>
Objective-C语法之代码块(block)的使用
查看>>