canny边缘检测 java_OpenCV Canny边缘检测

本文详述了如何使用OpenCV库在Java中应用Canny算法进行边缘检测,包括方法介绍、参数解释及示例代码展示,帮助读者理解和实践Canny边缘检测技术。
摘要由CSDN通过智能技术生成

本篇文章帮大家学习OpenCV Canny边缘检测,包含了OpenCV Canny边缘检测使用方法、操作技巧、实例演示和注意事项,有一定的学习价值,大家可以用来参考。

Canny边缘检测用于检测图像中的边缘。 它接受灰度图像作为输入,并使用多级算法。可以使用imgproc类的Canny()方法在图像上执行此操作,以下是此方法的语法。

Imgproc.Canny(image, edges, threshold1, threshold2)

该方法接受以下参数 -

image - 表示此操作的源(输入图像)的Mat对象。

edges - 表示此操作的目标(边缘)的Mat对象。

threshold1 - 类型为double的变量表示滞后过程的第一个阈值。

threshold2 - 类型为double的变量表示滞后过程的第二个阈值。

示例

以下程序是演示如何在给定图像上执行Canny边缘检测操作的示例。

package com.yiibai.miscellaneous;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.imgcodecs.Imgcodecs;

import org.opencv.imgproc.Imgproc;

public class CannyEdgeDetection {

public static void main(String args[]) throws Exception {

// Loading the OpenCV core library

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

// Reading the Image from the file and storing it in to a Matrix object

String file = "F:/worksp/opencv/images/sample3.jpg";

// Reading the image

Mat src = Imgcodecs.imread(file);

// Creating an empty matrix to store the result

Mat gray = new Mat();

// Converting the image from color to Gray

Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);

Mat edges = new Mat();

// Detecting the edges

Imgproc.Canny(gray, edges, 60, 60*3);

// Writing the image

Imgcodecs.imwrite("F:/worksp/opencv/images/canny_output.jpg", edges);

System.out.println("Image Loaded");

}

}

假定以下是上述程序中指定的输入图像:sample3.jpg。

执行上面示例代码,得到以下结果 -

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值