原文地址为:
[学习opencv]图像sobel、laplacian、canny边缘检测
转载请注明本文地址: [学习opencv]图像sobel、laplacian、canny边缘检测
三种常见的边缘检测算子。
#include "cv.h" #include "highgui.h" using namespace cv; int main(int argc, char* argv[]) { Mat src = imread("misaka.jpg"); Mat dst; //输入图像 //输出图像 //输入图像颜色通道数 //x方向阶数 //y方向阶数 Sobel(src,dst,src.depth(),1,1); imwrite("sobel.jpg",dst); //输入图像 //输出图像 //输入图像颜色通道数 Laplacian(src,dst,src.depth()); imwrite("laplacian.jpg",dst); //输入图像 //输出图像 //彩色转灰度 cvtColor(src,src,CV_BGR2GRAY); //canny只处理灰度图 //输入图像 //输出图像 //低阈值 //高阈值,opencv建议是低阈值的3倍 //内部sobel滤波器大小 Canny(src,dst,50,150,3); imwrite("canny.jpg",dst); imshow("dst",dst); waitKey(); return 0; }
原图:

sobel算子:

laplacian算子:

canny算子:

转载请注明本文地址: [学习opencv]图像sobel、laplacian、canny边缘检测
本文通过使用Sobel、Laplacian和Canny三种边缘检测算子,详细介绍了如何利用OpenCV进行图像边缘检测的过程。首先应用Sobel算子检测图像的水平和垂直边缘;然后使用Laplacian算子检测所有方向上的边缘;最后采用Canny算子来获取精确的边缘位置。
6770

被折叠的 条评论
为什么被折叠?



