|
@ -24,21 +24,37 @@ public class OrcTest { |
|
|
// Mat hello = Mat.eye(3,3, CvType.CV_8UC1);
|
|
|
// Mat hello = Mat.eye(3,3, CvType.CV_8UC1);
|
|
|
// System.out.println(hello.dump());
|
|
|
// System.out.println(hello.dump());
|
|
|
//加载图片
|
|
|
//加载图片
|
|
|
// Mat mat = Imgcodecs.imread("D:\\img\\0df7f58ea9d3a61019596094eb35003.png");
|
|
|
Mat mat = Imgcodecs.imread("D:\\img\\0df7f58ea9d3a61019596094eb35003.png"); |
|
|
// 加载图片并灰度图像
|
|
|
// 加载图片并灰度图像
|
|
|
Mat mat = Imgcodecs.imread("D:\\img\\0df7f58ea9d3a61019596094eb35003.png", Imgcodecs.IMREAD_GRAYSCALE); |
|
|
// Mat mat = Imgcodecs.imread("D:\\img\\0df7f58ea9d3a61019596094eb35003.png", Imgcodecs.IMREAD_GRAYSCALE);
|
|
|
// System.out.println(mat.width() + "*" + mat.height() + "," + mat.type());
|
|
|
// System.out.println(mat.width() + "*" + mat.height() + "," + mat.type());
|
|
|
System.out.println(mat); |
|
|
// System.out.println(mat);
|
|
|
// 输出图片
|
|
|
// 输出图片
|
|
|
// Imgcodecs.imwrite("D:\\img\\1.png", mat);
|
|
|
// Imgcodecs.imwrite("D:\\img\\1.png", mat);
|
|
|
// 截取图像
|
|
|
// 截取图像
|
|
|
Mat submat = mat.submat(50, 300, 60, 250); |
|
|
// Mat submat = mat.submat(50, 300, 60, 250);
|
|
|
// Imgcodecs.imwrite("D:\\img\\1.png", submat);
|
|
|
// Imgcodecs.imwrite("D:\\img\\1.png", submat);
|
|
|
// 模糊图片 模糊子图片后,父模块也跟着模糊了
|
|
|
// 模糊图片 模糊子图片后,父模块也跟着模糊了
|
|
|
Imgproc.blur(submat, submat, new Size(25.0,25.0)); |
|
|
// Imgproc.blur(submat, submat, new Size(25.0,25.0));
|
|
|
System.out.println(submat); |
|
|
// System.out.println(submat);
|
|
|
Imgcodecs.imwrite("D:\\img\\blur.png", mat); |
|
|
// Imgcodecs.imwrite("D:\\img\\blur.png", mat);
|
|
|
|
|
|
// 黑白化
|
|
|
|
|
|
Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2GRAY); |
|
|
|
|
|
/* |
|
|
|
|
|
高亮显示轮廓 |
|
|
|
|
|
■源矩阵 |
|
|
|
|
|
■目标矩阵 |
|
|
|
|
|
■低阈值,使用150.0 |
|
|
|
|
|
■高阈值,通常是低阈值的2倍或3倍 |
|
|
|
|
|
■光圈,3~7之间的一个奇数,我们使用3。光圈值越大,被检测到的轮廓越多 |
|
|
|
|
|
■L2梯度,暂时设置为true |
|
|
|
|
|
*/ |
|
|
|
|
|
Imgproc.Canny(mat, mat, 150,300,5, true); |
|
|
|
|
|
// 反色操作
|
|
|
|
|
|
Core.bitwise_not(mat, mat); |
|
|
|
|
|
// 将反色结果作为掩膜
|
|
|
|
|
|
Mat target = new Mat(mat.height(), mat.width(), CvType.CV_8UC3); |
|
|
|
|
|
|
|
|
|
|
|
Imgcodecs.imwrite("D:\\img\\1.png", mat); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|