This is an automated email from the ASF dual-hosted git repository.
tex pushed a commit to branch dev
in repository
https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
The following commit(s) were added to refs/heads/dev by this push:
new bca188d [STREAMPIPES-184] add annotation to bounding box
bca188d is described below
commit bca188d07967f587d87afbade2f25e0019c5c8de
Author: tex <[email protected]>
AuthorDate: Mon Jul 20 18:24:49 2020 +0200
[STREAMPIPES-184] add annotation to bounding box
---
.../jvm/processor/commons/RequiredBoxStream.java | 9 +++++
.../jvm/processor/imageenrichment/ColorUtil.java | 46 ++++++++++++++++++++++
.../processor/imageenrichment/ImageEnricher.java | 34 +++++++++++++---
.../imageenrichment/ImageEnrichmentController.java | 5 ++-
.../imageenrichment/ImageEnrichmentParameters.java | 22 ++++++++++-
.../documentation.md | 3 +-
.../strings.en | 8 +++-
7 files changed, 117 insertions(+), 10 deletions(-)
diff --git
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/RequiredBoxStream.java
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/RequiredBoxStream.java
index 93ee800..49be114 100644
---
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/RequiredBoxStream.java
+++
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/RequiredBoxStream.java
@@ -22,11 +22,14 @@ import
org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
import org.apache.streampipes.sdk.helpers.CollectedStreamRequirements;
import org.apache.streampipes.sdk.helpers.EpRequirements;
import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.utils.Datatypes;
public class RequiredBoxStream {
public static final String IMAGE_PROPERTY = "image-property";
public static final String BOX_ARRAY_PROPERTY = "box-array-property";
+ public static final String SCORE_ARRAY_PROPERTY = "score-array-property";
+ public static final String LABEL_ARRAY_PROPERTY = "label-array-property";
public static CollectedStreamRequirements getBoxStream() {
return StreamRequirementsBuilder
@@ -37,6 +40,12 @@ public class RequiredBoxStream {
.requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReqList("https://streampipes.org/boundingboxes"),
Labels.withId(BOX_ARRAY_PROPERTY),
PropertyScope.NONE)
+
.requiredPropertyWithUnaryMapping(EpRequirements.listRequirement(Datatypes.Number),
+ Labels.withId(SCORE_ARRAY_PROPERTY),
+ PropertyScope.NONE)
+
.requiredPropertyWithUnaryMapping(EpRequirements.listRequirement(Datatypes.String),
+ Labels.withId(LABEL_ARRAY_PROPERTY),
+ PropertyScope.NONE)
.build();
}
}
diff --git
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ColorUtil.java
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ColorUtil.java
new file mode 100644
index 0000000..f098f9d
--- /dev/null
+++
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ColorUtil.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package
org.apache.streampipes.processors.imageprocessing.jvm.processor.imageenrichment;
+
+import java.awt.*;
+
+public enum ColorUtil {
+
+ DARK_GREY(Color.DARK_GRAY),
+ BLACK(Color.BLACK),
+ RED(Color.RED),
+ PINK(Color.PINK),
+ ORANGE(Color.ORANGE),
+ YELLO(Color.YELLOW),
+ GREEN(Color.GREEN),
+ MAGENTA(Color.MAGENTA),
+ CYAN(Color.CYAN),
+ BLUE(Color.BLUE);
+
+
+ Color color;
+
+ ColorUtil(Color color) {
+ this.color = color;
+ }
+
+ static public Color getColor(int num) {
+ int index = num % ColorUtil.values().length;
+ return ColorUtil.values()[index].color;
+ }
+}
diff --git
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnricher.java
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnricher.java
index 7ee3240..ab144da 100644
---
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnricher.java
+++
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnricher.java
@@ -23,6 +23,7 @@ import
org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;
import java.awt.*;
+import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.Base64;
import java.util.List;
@@ -45,20 +46,43 @@ public class ImageEnricher implements
EventProcessor<ImageEnrichmentParameters>
Optional<BufferedImage> imageOpt =
imageTransformer.getImage();
+ List<Double> scores =
in.getFieldBySelector(params.getScoresArray()).getAsList().castItems(Double.class);
+ List<String> labels =
in.getFieldBySelector(params.getLabelsArray()).getAsList().castItems(String.class);
+
+
if (imageOpt.isPresent()) {
BufferedImage image = imageOpt.get();
List<Map<String, Object>> allBoxesMap =
imageTransformer.getAllBoxCoordinates();
- for (Map<String, Object> box : allBoxesMap) {
+ for (int i = 0; i < allBoxesMap.size(); i++) {
- BoxCoordinates boxCoordinates =
imageTransformer.getBoxCoordinates(image, box);
+ BoxCoordinates boxCoordinates =
imageTransformer.getBoxCoordinates(image, allBoxesMap.get(i));
Graphics2D graph = image.createGraphics();
- int alpha = 180;
- Color color = new Color(133, 148, 229, alpha);
+
+ //set color
+ Color color = ColorUtil.getColor(labels.get(i).hashCode());
graph.setColor(color);
- graph.fill(new Rectangle(boxCoordinates.getX(), boxCoordinates.getY(),
boxCoordinates.getWidth(),
+
+ //Box
+ graph.setStroke(new BasicStroke(5));
+ graph.draw(new Rectangle(boxCoordinates.getX(), boxCoordinates.getY(),
boxCoordinates.getWidth(),
boxCoordinates.getHeight()));
+
+ //Label
+ String str = labels.get(i) + ": " + scores.get(i);
+
+ FontMetrics fm = graph.getFontMetrics();
+ Rectangle2D rect = fm.getStringBounds(str, graph);
+
+ graph.fillRect(boxCoordinates.getX(),
+ boxCoordinates.getY() - fm.getAscent(),
+ (int) rect.getWidth(),
+ (int) rect.getHeight());
+
+ graph.setColor(Color.white);
+ graph.drawString(str, boxCoordinates.getX(), boxCoordinates.getY());
+
graph.dispose();
}
diff --git
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentController.java
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentController.java
index c6f70b4..b301c86 100644
---
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentController.java
+++
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentController.java
@@ -44,7 +44,6 @@ public class ImageEnrichmentController extends
StandaloneEventProcessingDeclarer
.requiredStream(RequiredBoxStream.getBoxStream())
.outputStrategy(OutputStrategies.fixed(
EpProperties.stringEp(Labels.empty(), "image",
"https://image.com")
-
))
.build();
}
@@ -53,9 +52,11 @@ public class ImageEnrichmentController extends
StandaloneEventProcessingDeclarer
public ConfiguredEventProcessor<ImageEnrichmentParameters>
onInvocation(DataProcessorInvocation dataProcessorInvocation,
ProcessingElementParameterExtractor extractor) {
String imageProperty = extractor.mappingPropertyValue(IMAGE_PROPERTY);
String boxArray =
extractor.mappingPropertyValue(RequiredBoxStream.BOX_ARRAY_PROPERTY);
+ String scoreArray =
extractor.mappingPropertyValue(RequiredBoxStream.SCORE_ARRAY_PROPERTY);
+ String labelsArray =
extractor.mappingPropertyValue(RequiredBoxStream.LABEL_ARRAY_PROPERTY);
ImageEnrichmentParameters params = new
ImageEnrichmentParameters(dataProcessorInvocation, imageProperty,
- boxArray, "box_width", "box_height", "box_x", "box_y");
+ boxArray, "box_width", "box_height", "box_x", "box_y", scoreArray,
labelsArray);
return new ConfiguredEventProcessor<>(params, ImageEnricher::new);
diff --git
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentParameters.java
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentParameters.java
index 6283e6b..b16628a 100644
---
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentParameters.java
+++
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/ImageEnrichmentParameters.java
@@ -24,13 +24,15 @@ public class ImageEnrichmentParameters extends
EventProcessorBindingParams {
private String imageProperty;
private String boxArray;
+ private String scoresArray;
+ private String labelsArray;
private String boxWidth;
private String boxHeight;
private String boxX;
private String boxY;
- public ImageEnrichmentParameters(DataProcessorInvocation graph, String
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX,
String boxY) {
+ public ImageEnrichmentParameters(DataProcessorInvocation graph, String
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX,
String boxY, String scoresArray, String labelsArray) {
super(graph);
this.imageProperty = imageProperty;
this.boxArray = boxArray;
@@ -38,8 +40,19 @@ public class ImageEnrichmentParameters extends
EventProcessorBindingParams {
this.boxHeight = boxHeight;
this.boxX = boxX;
this.boxY = boxY;
+ this.scoresArray = scoresArray;
+ this.labelsArray = labelsArray;
}
+ public ImageEnrichmentParameters(DataProcessorInvocation graph, String
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX,
String boxY) {
+ super(graph);
+ this.imageProperty = imageProperty;
+ this.boxArray = boxArray;
+ this.boxWidth = boxWidth;
+ this.boxHeight = boxHeight;
+ this.boxX = boxX;
+ this.boxY = boxY;
+ }
public ImageEnrichmentParameters(DataProcessorInvocation graph, String
imageProperty, String boxWidth, String boxHeight, String boxX, String boxY) {
super(graph);
@@ -74,4 +87,11 @@ public class ImageEnrichmentParameters extends
EventProcessorBindingParams {
return boxY;
}
+ public String getScoresArray() {
+ return scoresArray;
+ }
+
+ public String getLabelsArray() {
+ return labelsArray;
+ }
}
diff --git
a/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/documentation.md
b/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/documentation.md
index 5456e6f..8114626 100644
---
a/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/documentation.md
+++
b/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/documentation.md
@@ -29,8 +29,9 @@
Image Enrichment: Enriches an + image with + given bounding box coordinates
## Required input
-An image and an array with bounding boxes.
+An image and an array with bounding boxes, an array with scores and an array
with labels.
A box consists of the x and y coordinates in the image as well as the height
and width
+
## Output
A new event containing the image with bounding boxes rendered according to the
boxes of the input event
\ No newline at end of file
diff --git
a/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/strings.en
b/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/strings.en
index e01a9c7..8ba8585 100644
---
a/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/strings.en
+++
b/streampipes-processors-image-processing-jvm/src/main/resources/org.apache.streampipes.processor.imageclassification.jvm.image-enricher/strings.en
@@ -5,4 +5,10 @@ image-property.title=Image Field
image-property.description=The field containing the image.
box-array-property.title=Bounding box field
-box-array-property.description=The field containing a list of bounding boxes.
\ No newline at end of file
+box-array-property.description=The field containing a list of bounding boxes.
+
+score-array-property.title=Scores field
+score-array-property.description=The field containing a list of scores.
+
+label-array-property.title=Labels field
+label-array-property.description=The field containing a list of labels.
\ No newline at end of file