From 8c145d564d7e9572b79e7b5104cc3fbdaca5ab3b Mon Sep 17 00:00:00 2001 From: TheTripleV Date: Mon, 25 Mar 2019 11:31:12 -0500 Subject: [PATCH 1/4] Add convexity and inertia ratio to findBlobs --- .../composite/FindBlobsOperation.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java index c661a3e37c..a45f8b3c07 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java @@ -34,6 +34,10 @@ public class FindBlobsOperation implements Operation { .createNumberSpinnerSocketHint("Min Area", 1); private final SocketHint> circularityHint = SocketHints.Inputs .createNumberListRangeSocketHint("Circularity", 0.0, 1.0); + private final SocketHint> convexityHint = SocketHints.Inputs + .createNumberListRangeSocketHint("Convexity", 0.0, 1.0); + private final SocketHint> inertiaRatioHint = SocketHints.Inputs + .createNumberListRangeSocketHint("Inertia Ratio", 0.0, 1.0); private final SocketHint colorHint = SocketHints .createBooleanSocketHint("Dark Blobs", false); @@ -45,6 +49,8 @@ public class FindBlobsOperation implements Operation { private final InputSocket inputSocket; private final InputSocket minAreaSocket; private final InputSocket> circularitySocket; + private final InputSocket> convexitySocket; + private final InputSocket> inertiaRatioSocket; private final InputSocket colorSocket; private final OutputSocket outputSocket; @@ -56,6 +62,8 @@ public FindBlobsOperation(InputSocket.Factory inputSocketFactory, OutputSocket.F this.inputSocket = inputSocketFactory.create(inputHint); this.minAreaSocket = inputSocketFactory.create(minAreaHint); this.circularitySocket = inputSocketFactory.create(circularityHint); + this.convexitySocket = inputSocketFactory.create(convexityHint); + this.inertiaRatioSocket = inputSocketFactory.create(inertiaRatioHint); this.colorSocket = inputSocketFactory.create(colorHint); this.outputSocket = outputSocketFactory.create(blobsHint); @@ -67,6 +75,8 @@ public List getInputSockets() { inputSocket, minAreaSocket, circularitySocket, + convexitySocket, + inertiaRatioSocket, colorSocket ); } @@ -84,6 +94,8 @@ public void perform() { final Mat input = inputSocket.getValue().get().getCpu(); final Number minArea = minAreaSocket.getValue().get(); final List circularity = circularitySocket.getValue().get(); + final List convexity = convexitySocket.getValue().get(); + final List inertiaRatio = inertiaRatioSocket.getValue().get(); final Boolean darkBlobs = colorSocket.getValue().get(); @@ -98,7 +110,15 @@ public void perform() { .filterByCircularity(true) .minCircularity(circularity.get(0).floatValue()) - .maxCircularity(circularity.get(1).floatValue())); + .maxCircularity(circularity.get(1).floatValue()) + + .filterByConvexity(true) + .minConvexity(convexity.get(0).floatValue()) + .maxConvexity(convexity.get(1).floatValue()) + + .filterByInertia(true) + .minInertiaRatio(inertiaRatio.get(0).floatValue()) + .maxInertiaRatio(inertiaRatio.get(1).floatValue())); // Detect the blobs and store them in the output BlobsReport final KeyPointVector keyPointVector = new KeyPointVector(); From 645e5406159881b0f2b27f1782cca203c40bce50 Mon Sep 17 00:00:00 2001 From: TheTripleV Date: Mon, 25 Mar 2019 14:32:20 -0500 Subject: [PATCH 2/4] Reorder sockets to maintain backwards compatibility --- .../core/operations/composite/FindBlobsOperation.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java index a45f8b3c07..0698814e7e 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java @@ -62,9 +62,9 @@ public FindBlobsOperation(InputSocket.Factory inputSocketFactory, OutputSocket.F this.inputSocket = inputSocketFactory.create(inputHint); this.minAreaSocket = inputSocketFactory.create(minAreaHint); this.circularitySocket = inputSocketFactory.create(circularityHint); + this.colorSocket = inputSocketFactory.create(colorHint); this.convexitySocket = inputSocketFactory.create(convexityHint); this.inertiaRatioSocket = inputSocketFactory.create(inertiaRatioHint); - this.colorSocket = inputSocketFactory.create(colorHint); this.outputSocket = outputSocketFactory.create(blobsHint); } @@ -75,9 +75,10 @@ public List getInputSockets() { inputSocket, minAreaSocket, circularitySocket, + colorSocket, + //Sockets placed last to maintain backwards compatibility in deserialization convexitySocket, - inertiaRatioSocket, - colorSocket + inertiaRatioSocket ); } @@ -94,10 +95,9 @@ public void perform() { final Mat input = inputSocket.getValue().get().getCpu(); final Number minArea = minAreaSocket.getValue().get(); final List circularity = circularitySocket.getValue().get(); + final Boolean darkBlobs = colorSocket.getValue().get(); final List convexity = convexitySocket.getValue().get(); final List inertiaRatio = inertiaRatioSocket.getValue().get(); - final Boolean darkBlobs = colorSocket.getValue().get(); - final SimpleBlobDetector blobDetector = SimpleBlobDetector.create(new SimpleBlobDetector .Params() From 098fb0388062abdf2af3ffcf10bdf2bf8176b0e1 Mon Sep 17 00:00:00 2001 From: TheTripleV Date: Mon, 25 Mar 2019 15:59:17 -0500 Subject: [PATCH 3/4] Reordered sockets for style --- .../grip/core/operations/composite/FindBlobsOperation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java index 0698814e7e..74fe8bf4c1 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java @@ -34,12 +34,12 @@ public class FindBlobsOperation implements Operation { .createNumberSpinnerSocketHint("Min Area", 1); private final SocketHint> circularityHint = SocketHints.Inputs .createNumberListRangeSocketHint("Circularity", 0.0, 1.0); + private final SocketHint colorHint = SocketHints + .createBooleanSocketHint("Dark Blobs", false); private final SocketHint> convexityHint = SocketHints.Inputs .createNumberListRangeSocketHint("Convexity", 0.0, 1.0); private final SocketHint> inertiaRatioHint = SocketHints.Inputs .createNumberListRangeSocketHint("Inertia Ratio", 0.0, 1.0); - private final SocketHint colorHint = SocketHints - .createBooleanSocketHint("Dark Blobs", false); private final SocketHint blobsHint = new SocketHint.Builder<>(BlobsReport.class) .identifier("Blobs") @@ -49,9 +49,9 @@ public class FindBlobsOperation implements Operation { private final InputSocket inputSocket; private final InputSocket minAreaSocket; private final InputSocket> circularitySocket; + private final InputSocket colorSocket; private final InputSocket> convexitySocket; private final InputSocket> inertiaRatioSocket; - private final InputSocket colorSocket; private final OutputSocket outputSocket; From 8effda454be97f28767fc79aefaef8dd43e085a6 Mon Sep 17 00:00:00 2001 From: TheTripleV Date: Sun, 19 May 2019 21:54:59 -0500 Subject: [PATCH 4/4] Untested - Code Generation (all 3) --- .../cpp/operations/Find_Blobs.vm | 12 ++++++++---- .../java/operations/Find_Blobs.vm | 18 +++++++++++++----- .../python/operations/Find_Blobs.vm | 10 +++++++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Find_Blobs.vm b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Find_Blobs.vm index cc1cb7a74f..cac0cf275e 100644 --- a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Find_Blobs.vm +++ b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/cpp/operations/Find_Blobs.vm @@ -8,8 +8,8 @@ * @param blobList The output where the MatOfKeyPoint is stored. */ //void $tMeth.name($step.name())(Mat *input, double *minArea, double circularity[2], - //bool *darkBlobs, vector *blobList) { - void $className::#func($step ["input", "minArea", "circularity", "darkBlobs", "blobList"]) { + //bool *darkBlobs, double convexity[2], double inertiaRatio[2], vector *blobList) { + void $className::#func($step ["input", "minArea", "circularity", "darkBlobs", "convexity", "inertiaRatio", "blobList"]) { blobList.clear(); cv::SimpleBlobDetector::Params params; params.filterByColor = 1; @@ -21,8 +21,12 @@ params.filterByCircularity = true; params.minCircularity = circularity[0]; params.maxCircularity = circularity[1]; - params.filterByConvexity = false; - params.filterByInertia = false; + params.filterByConvexity = true; + params.minConvexity = convexity[0]; + params.maxConvexity = convexity[1]; + params.filterByInertia = true; + params.minInertia = inertiaRatio[0]; + params.maxInertia = inertiaRatio[1]; cv::Ptr detector = cv::SimpleBlobDetector::create(params); detector->detect(input, blobList); } diff --git a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/java/operations/Find_Blobs.vm b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/java/operations/Find_Blobs.vm index 523def9e0a..1a77e33f21 100644 --- a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/java/operations/Find_Blobs.vm +++ b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/java/operations/Find_Blobs.vm @@ -7,7 +7,7 @@ * @param blobList The output where the MatOfKeyPoint is stored. */ private void $tMeth.name($step.name())(Mat input, double minArea, double[] circularity, - Boolean darkBlobs, MatOfKeyPoint blobList) { + Boolean darkBlobs, double[] convexity, double[] inertiaRatio, MatOfKeyPoint blobList) { FeatureDetector blobDet = FeatureDetector.create(FeatureDetector.SIMPLEBLOB); try { File tempFile = File.createTempFile("config", ".xml"); @@ -40,11 +40,19 @@ config.append(circularity[1]); config.append("\n"); config.append("1\n"); - config.append("0.1\n"); - config.append("" + Integer.MAX_VALUE + "\n"); + config.append(""); + config.append(inertiaRatio[0]); + config.append("\n"); + config.append(""); + config.append(inertiaRatio[1]); + config.append("\n"); config.append("1\n"); - config.append("0.95\n"); - config.append("" + Integer.MAX_VALUE + "\n"); + config.append(""); + config.append(convexity[0]); + config.append("\n"); + config.append(""); + config.append(convexity[1]); + config.append("\n"); config.append("\n"); FileWriter writer; writer = new FileWriter(tempFile, false); diff --git a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/Find_Blobs.vm b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/Find_Blobs.vm index 9e2644ec6d..c1e75c047e 100644 --- a/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/Find_Blobs.vm +++ b/ui/src/main/resources/edu/wpi/grip/ui/codegeneration/python/operations/Find_Blobs.vm @@ -1,5 +1,5 @@ @staticmethod - def $tMeth.name($step.name())(input, min_area, circularity, dark_blobs): + def $tMeth.name($step.name())(input, min_area, circularity, dark_blobs, convexity, inertia_ratio): """Detects groups of pixels in an image. Args: input: A numpy.ndarray. @@ -19,7 +19,11 @@ params.filterByCircularity = True params.minCircularity = circularity[0] params.maxCircularity = circularity[1] - params.filterByConvexity = False - params.filterByInertia = False + params.filterByConvexity = True + params.minConvexity = convexity[0] + params.maxConvexity = convexity[1] + params.filterByInertia = True + params.minInertia = inertia_ratio[0] + params.maxInertia = inertia_ratio[1] detector = cv2.SimpleBlobDetector_create(params) return detector.detect(input) \ No newline at end of file