From c621c3781d69539d81d8d8ac174511dddb82ba7c Mon Sep 17 00:00:00 2001 From: EvanYap Date: Mon, 14 Nov 2016 20:00:23 -0800 Subject: [PATCH] adds code to detect edges --- IsolateImage.java | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/IsolateImage.java b/IsolateImage.java index 5768d5b..18b76a2 100644 --- a/IsolateImage.java +++ b/IsolateImage.java @@ -38,6 +38,26 @@ public class IsolateImage { processImage(); } + public static void findContours() { + + ArrayList contours = new ArrayList(); + int frameCount = 0; + int THE_BEST_MAGIC_NUMBER = 300; + + contours.clear(); + matOriginal = Imgcodecs.imread("imgs/goal2.png"); // convert image + // into matrix + + filtered = matOriginal; + + // bing bing bong bong + // bing bing bong bong + Imgproc.cvtColor(matOriginal, filtered, Imgproc.COLOR_BGR2GRAY); + Imgproc.GaussianBlur(matOriginal, filtered, new Size(5, 5), Core.BORDER_DEFAULT); + Imgproc.Canny(matOriginal, filtered, 35, 125); + + } + public static void processImage() { ArrayList contours = new ArrayList(); @@ -45,7 +65,7 @@ public class IsolateImage { int THE_BEST_MAGIC_NUMBER = 300; while (frameCount < 1) { contours.clear(); - matOriginal = Imgcodecs.imread("imgs/goal.png"); // convert image + matOriginal = Imgcodecs.imread("imgs/goal2.png"); // convert image // into matrix filtered = matOriginal; @@ -61,7 +81,7 @@ public class IsolateImage { MatOfPoint matOfPoint = iterator.next(); Rect rec = Imgproc.boundingRect(matOfPoint); if (rec.height < THE_BEST_MAGIC_NUMBER || rec.width < THE_BEST_MAGIC_NUMBER) { - System.out.println(rec.toString()); + iterator.remove(); } @@ -70,13 +90,13 @@ public class IsolateImage { for (MatOfPoint mop : contours) { Rect rec = Imgproc.boundingRect(mop); Imgproc.rectangle(matOriginal, rec.br(), rec.tl(), GRAY, 1); + System.out.println(rec.toString()); } frameCount++; } Imgcodecs.imwrite("output.png", filtered); - System.out.println("done"); } -- 2.30.2