您的当前位置:首页正文

[学习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算子:

转载于:https://www.cnblogs.com/tiandsp/archive/2013/04/20/3032860.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Top