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..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 @@ -36,6 +36,10 @@ public class FindBlobsOperation implements Operation { .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 blobsHint = new SocketHint.Builder<>(BlobsReport.class) .identifier("Blobs") @@ -46,6 +50,8 @@ public class FindBlobsOperation implements Operation { private final InputSocket minAreaSocket; private final InputSocket> circularitySocket; private final InputSocket colorSocket; + private final InputSocket> convexitySocket; + private final InputSocket> inertiaRatioSocket; private final OutputSocket outputSocket; @@ -57,6 +63,8 @@ public FindBlobsOperation(InputSocket.Factory inputSocketFactory, OutputSocket.F 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.outputSocket = outputSocketFactory.create(blobsHint); } @@ -67,7 +75,10 @@ public List getInputSockets() { inputSocket, minAreaSocket, circularitySocket, - colorSocket + colorSocket, + //Sockets placed last to maintain backwards compatibility in deserialization + convexitySocket, + inertiaRatioSocket ); } @@ -85,7 +96,8 @@ public void perform() { 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 SimpleBlobDetector blobDetector = SimpleBlobDetector.create(new SimpleBlobDetector .Params() @@ -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(); 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