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

commit dc5774f75989bff0a48e30e516e2800dda94a251
Author: tex <[email protected]>
AuthorDate: Tue Jul 21 14:23:15 2020 +0200

    [STREAMPIPES-184] change stream requirements
---
 .../jvm/processor/commons/ImageTransformer.java    | 18 +++++++++++++-
 .../jvm/processor/commons/RequiredBoxStream.java   |  8 -------
 .../processor/imageenrichment/BoxCoordinates.java  | 28 ++++++++++++++++++++++
 .../processor/imageenrichment/ImageEnricher.java   | 11 ++++-----
 .../imageenrichment/ImageEnrichmentController.java |  4 +---
 .../imageenrichment/ImageEnrichmentParameters.java | 18 +++++++-------
 .../documentation.md                               |  2 +-
 .../strings.en                                     |  8 +------
 8 files changed, 61 insertions(+), 36 deletions(-)

diff --git 
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/ImageTransformer.java
 
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/ImageTransformer.java
index 220df4f..03fca60 100644
--- 
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/ImageTransformer.java
+++ 
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/commons/ImageTransformer.java
@@ -65,11 +65,27 @@ public class ImageTransformer extends 
PlainImageTransformer<ImageEnrichmentParam
     Float width = toFloat(box.get(params.getBoxWidth()));
     Float height = toFloat(box.get(params.getBoxHeight()));
 
+
     return BoxCoordinates.make(width, height, x, y);
   }
 
+  public BoxCoordinates getBoxCoordinatesWithAnnotations(BufferedImage image, 
Map<String, Object> box) {
+    Float x = toFloat(box.get(params.getBoxX()));
+    Float y = toFloat(box.get(params.getBoxY()));
+    Float width = toFloat(box.get(params.getBoxWidth()));
+    Float height = toFloat(box.get(params.getBoxHeight()));
+    Float score = toFloat(box.get(params.getScore()));
+    String classesindex = toString(box.get(params.getClassesindex()));
+
+    return BoxCoordinates.make(width, height, x, y, score, classesindex);
+  }
+
   private Float toFloat(Object obj) {
-    return Float.parseFloat(String.valueOf(obj));
+    return Float.parseFloat(toString(obj));
+  }
+
+  private String toString(Object obj) {
+    return String.valueOf(obj);
   }
 
 
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 49be114..84b2169 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
@@ -28,8 +28,6 @@ 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
@@ -40,12 +38,6 @@ 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/BoxCoordinates.java
 
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/BoxCoordinates.java
index 74a82fb..8f73696 100644
--- 
a/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/BoxCoordinates.java
+++ 
b/streampipes-processors-image-processing-jvm/src/main/java/org/apache/streampipes/processors/imageprocessing/jvm/processor/imageenrichment/BoxCoordinates.java
@@ -23,6 +23,8 @@ public class BoxCoordinates {
   private int height;
   private int x;
   private int y;
+  private float score;
+  private String classesindex;
 
   public static BoxCoordinates make(Float width, Float height, Float x, Float
           y) {
@@ -32,6 +34,15 @@ public class BoxCoordinates {
             Math.round(y));
   }
 
+  public static BoxCoordinates make(Float width, Float height, Float x, Float 
y, float score, String classesindex) {
+    return new BoxCoordinates(Math.round(width),
+            Math.round(height),
+            Math.round(x),
+            Math.round(y),
+            Math.round(score),
+            classesindex);
+  }
+
   public BoxCoordinates(int width, int height, int x, int y) {
     this.width = width;
     this.height = height;
@@ -39,6 +50,15 @@ public class BoxCoordinates {
     this.y = y;
   }
 
+  public BoxCoordinates(int width, int height, int x, int y, float score, 
String classesindex) {
+    this.width = width;
+    this.height = height;
+    this.x = x;
+    this.y = y;
+    this.score = score;
+    this.classesindex = classesindex;
+  }
+
   public int getWidth() {
     return width;
   }
@@ -54,4 +74,12 @@ public class BoxCoordinates {
   public int getY() {
     return y;
   }
+
+  public float getScore() {
+    return score;
+  }
+
+  public String getClassesindex() {
+    return classesindex;
+  }
 }
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 ab144da..18fb1a1 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
@@ -46,22 +46,19 @@ 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 (int i = 0; i < allBoxesMap.size(); i++) {
+      for (Map<String, Object> box : allBoxesMap) {
 
-        BoxCoordinates boxCoordinates = 
imageTransformer.getBoxCoordinates(image, allBoxesMap.get(i));
+        BoxCoordinates boxCoordinates = 
imageTransformer.getBoxCoordinatesWithAnnotations(image, box);
 
         Graphics2D graph = image.createGraphics();
 
         //set color
-        Color color = ColorUtil.getColor(labels.get(i).hashCode());
+        Color color = 
ColorUtil.getColor(boxCoordinates.getClassesindex().hashCode());
         graph.setColor(color);
 
         //Box
@@ -70,7 +67,7 @@ public class ImageEnricher implements 
EventProcessor<ImageEnrichmentParameters>
                 boxCoordinates.getHeight()));
 
         //Label
-        String str = labels.get(i) + ": " + scores.get(i);
+        String str = boxCoordinates.getClassesindex() + ": " + 
boxCoordinates.getScore();
 
         FontMetrics fm = graph.getFontMetrics();
         Rectangle2D rect = fm.getStringBounds(str, graph);
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 b301c86..5aea05c 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
@@ -52,11 +52,9 @@ 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", scoreArray, 
labelsArray);
+            boxArray, "box_width", "box_height", "box_x", "box_y", "score", 
"classesindex");
 
     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 b16628a..32b3642 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,15 +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;
+  private String score;
+  private String classesindex;
 
-  public ImageEnrichmentParameters(DataProcessorInvocation graph, String 
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX, 
String boxY, String scoresArray, String labelsArray) {
+  public ImageEnrichmentParameters(DataProcessorInvocation graph, String 
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX, 
String boxY, String score, String classesindex) {
     super(graph);
     this.imageProperty = imageProperty;
     this.boxArray = boxArray;
@@ -40,8 +40,8 @@ public class ImageEnrichmentParameters extends 
EventProcessorBindingParams {
     this.boxHeight = boxHeight;
     this.boxX = boxX;
     this.boxY = boxY;
-    this.scoresArray = scoresArray;
-    this.labelsArray = labelsArray;
+    this.score = score;
+    this.classesindex = classesindex;
   }
 
   public ImageEnrichmentParameters(DataProcessorInvocation graph, String 
imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX, 
String boxY) {
@@ -87,11 +87,11 @@ public class ImageEnrichmentParameters extends 
EventProcessorBindingParams {
     return boxY;
   }
 
-  public String getScoresArray() {
-    return scoresArray;
+  public String getScore() {
+    return score;
   }
 
-  public String getLabelsArray() {
-    return labelsArray;
+  public String getClassesindex() {
+    return classesindex;
   }
 }
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 8114626..2301c69 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
@@ -30,7 +30,7 @@ Image Enrichment: Enriches an  + image with  + given bounding 
box coordinates
 
 ## Required input
 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 
+A box consists of the x and y coordinates in the image as well as the height 
and width, and the classindex with score
 
 
 ## Output
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 8ba8585..e01a9c7 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,10 +5,4 @@ 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.
-
-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
+box-array-property.description=The field containing a list of bounding boxes.
\ No newline at end of file

Reply via email to