From c724deb3ad3f02eff94e8ff066fd661f38ef4b0e Mon Sep 17 00:00:00 2001 From: EvanYap Date: Mon, 17 Oct 2016 21:00:25 -0700 Subject: [PATCH] Make guassian blur work with BORDER_DEFAULT --- IsolateImage.java | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/IsolateImage.java b/IsolateImage.java index d2462da..64a82a0 100644 --- a/IsolateImage.java +++ b/IsolateImage.java @@ -1,5 +1,8 @@ +import java.util.ArrayList; + import org.opencv.core.Core; import org.opencv.core.Mat; +import org.opencv.core.MatOfPoint; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.core.Size; @@ -11,10 +14,11 @@ public class IsolateImage { public static Mat matOriginal; public static Mat filtered; public static Mat kernel; + public static Mat matHierarchy; public static final Scalar LOWER_BOUNDS = new Scalar(169, 164, 103); public static final Scalar UPPER_BOUNDS = new Scalar(255, 229, 140); - // public static final Scalar LOWER_BOUNDS = new Scalar(255, 0, 0); + public static final Scalar BLACK = new Scalar(0, 0, 0); // public static final Scalar UPPER_BOUNDS = new Scalar(0, 255, 255); static { @@ -25,21 +29,32 @@ public class IsolateImage { matOriginal = new Mat(); filtered = new Mat(); + matHierarchy = new Mat(); - kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5)); + kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5, 5)); processImage(); } public static void processImage() { + ArrayList contours = new ArrayList(); + contours.clear(); matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image - // into matrix + // into matrix filtered = matOriginal; + Imgproc.GaussianBlur(matOriginal, filtered, new Size(17, 17), Core.BORDER_DEFAULT); Core.inRange(matOriginal, LOWER_BOUNDS, UPPER_BOUNDS, filtered); - Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 2); - + // Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 4); + Imgproc.dilate(matOriginal, filtered, kernel, new Point(-1, -1), 4); + // Imgproc.findContours(filtered, contours, matHierarchy, + // Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); + + // for (MatOfPoint mop : contours) { + // Rect rec = Imgproc.boundingRect(mop); + // Imgproc.rectangle(matOriginal, rec.br(), rec.tl(), BLACK, 5); + // } Imgcodecs.imwrite("output.png", filtered); } -- 2.30.2