• openCV_java Canny边缘检测


    边缘检测的原理:

    检测出图像中所有灰度值变化较大的点,而且这些点连起来构成若干线条,这些线条就称之为图像的边缘。

    1986年,由John F. Canny 提出!

    // Canny(Mat image, Mat edges, double threshold1, double threshold2, int
    // apertureSize, boolean L2gradient)
    // 第一个参数,InputArray类型的image,输入图像,即源图像,填Mat类的对象即可,且需为单通道8位图像。
    // 第二个参数,OutputArray类型的edges,输出的边缘图,需要和源图片有一样的尺寸和类型。
    // 第三个参数,double类型的threshold1,第一个滞后性阈值。
    // 第四个参数,double类型的threshold2,第二个滞后性阈值。
    // 第五个参数,int类型的apertureSize,表示应用Sobel算子的孔径大小,其有默认值3。
    // 第六个参数,bool类型的L2gradient,一个计算图像梯度幅值的标识,有默认值false。

        public static void canny(String oriImg, String dstImg, int threshold) {
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            Mat img = Imgcodecs.imread(oriImg);
            Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
            //
            Imgproc.Canny(img, img, threshold, threshold * 3, 3, true);
            //
            Imgcodecs.imwrite(dstImg, img);
        }

    实例:

    canny:

    threshold越大,轮廓的要求越高(灰度值变化越明显才能构成轮廓)

    上图,thrdshold=20,当设置成50,如下图:

  • 相关阅读:
    su 命令切换用户带来的问题
    系统无法启动
    Linux单用户模式
    反射
    propety/静态方法
    内置方法,序列化模块
    第1月5周3天
    第1月4周5天
    第1月4周4日
    第1月4周3日
  • 原文地址:https://www.cnblogs.com/huangfox/p/5213247.html
Copyright © 2020-2023  润新知