图像轮廓检测
canny()
Imgproc中提供了一个canny函数,用来检测图像轮廓。
以下以下图为例进行演示:
方法 | 说明 |
Canny(Mat image, Mat edges, double threshold1, double threshold2) | image:原图像 edges:目标图像 threshold1:低阈值 threshold2:高阈值 apertureSize:光圈值,3-7之前的一个奇数,光圈值越大,被检测到的轮廓就越多,默认3 L2gradient:L2梯度 |
Canny(Mat image, Mat edges, double threshold1, double threshold2, int apertureSize) | |
Canny(Mat image, Mat edges, double threshold1, double threshold2, int apertureSize, boolean L2gradient) |
示例:
public static void main(String[] args) {
String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
System.load(libraryPath);
Mat img = Imgcodecs.imread("rabbit.jpg");
Mat mat =new Mat();
Imgproc.Canny(img,mat,150.0,150.0);
HighGui.imshow("img",img);
HighGui.imshow("mat",mat);
HighGui.waitKey(1);
}
执行结果