Skip to content

Commit

Permalink
[#820] enable checkstyle for three more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Dec 6, 2022
1 parent 647ae8f commit 7da2c1f
Show file tree
Hide file tree
Showing 68 changed files with 786 additions and 658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@
<artifactId>ddogleg</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ public SpServiceDefinition provideServiceDefinition() {
"Processors Image Processing JVM",
"",
8090)
.registerPipelineElements(
new ImageEnrichmentController(),
new ImageCropperController(),
new QrCodeReaderController(),
new GenericImageClassificationController())
.registerMessagingFormats(
new JsonDataFormatFactory(),
new CborDataFormatFactory(),
new SmileDataFormatFactory(),
new FstDataFormatFactory())
.registerMessagingProtocols(
new SpKafkaProtocolFactory(),
new SpJmsProtocolFactory(),
new SpMqttProtocolFactory())
.build();
.registerPipelineElements(
new ImageEnrichmentController(),
new ImageCropperController(),
new QrCodeReaderController(),
new GenericImageClassificationController())
.registerMessagingFormats(
new JsonDataFormatFactory(),
new CborDataFormatFactory(),
new SmileDataFormatFactory(),
new FstDataFormatFactory())
.registerMessagingProtocols(
new SpKafkaProtocolFactory(),
new SpJmsProtocolFactory(),
new SpMqttProtocolFactory())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.streampipes.processors.imageprocessing.jvm.processor.imageenrichment.BoxCoordinates;
import org.apache.streampipes.processors.imageprocessing.jvm.processor.imageenrichment.ImageEnrichmentParameters;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -31,8 +33,6 @@
import java.util.Map;
import java.util.Optional;

import javax.imageio.ImageIO;

public class ImageTransformer extends PlainImageTransformer<ImageEnrichmentParameters> {

public ImageTransformer(Event in, ImageEnrichmentParameters params) {
Expand All @@ -46,8 +46,8 @@ public Optional<BufferedImage> getImage() {

public List<Map<String, Object>> getAllBoxCoordinates() {
List<Map<String, AbstractField>> allBoxes = in.getFieldBySelector(params.getBoxArray())
.getAsList()
.parseAsCustomType(value -> value.getAsComposite().getRawValue());
.getAsList()
.parseAsCustomType(value -> value.getAsComposite().getRawValue());

List<Map<String, Object>> allBoxesMap = new ArrayList<>();
allBoxes.forEach(box -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import org.apache.streampipes.model.runtime.Event;
import org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.Optional;

import javax.imageio.ImageIO;

public class PlainImageTransformer<T extends EventProcessorBindingParams> {

protected Event in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@
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 CollectedStreamRequirements getBoxStream() {
return StreamRequirementsBuilder
.create()
.requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq("https://image.com"), Labels
.withId(IMAGE_PROPERTY),
PropertyScope.NONE)
.requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReqList("https://streampipes.org/boundingboxes"),
Labels.withId(BOX_ARRAY_PROPERTY),
PropertyScope.NONE)
.build();
return StreamRequirementsBuilder
.create()
.requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReq("https://image.com"), Labels
.withId(IMAGE_PROPERTY),
PropertyScope.NONE)
.requiredPropertyWithUnaryMapping(EpRequirements.domainPropertyReqList("https://streampipes.org/boundingboxes"),
Labels.withId(BOX_ARRAY_PROPERTY),
PropertyScope.NONE)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
*/
package org.apache.streampipes.processors.imageprocessing.jvm.processor.genericclassification;

import org.apache.streampipes.model.runtime.Event;
import org.apache.streampipes.processors.imageprocessing.jvm.processor.commons.PlainImageTransformer;
import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
import org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;

import boofcv.abst.scene.ImageClassifier;
import boofcv.factory.scene.ClassifierAndSource;
import boofcv.factory.scene.FactoryImageClassifier;
import boofcv.io.image.ConvertBufferedImage;
import boofcv.struct.image.GrayF32;
import boofcv.struct.image.Planar;
import deepboof.io.DeepBoofDataBaseOps;
import org.apache.streampipes.model.runtime.Event;
import org.apache.streampipes.processors.imageprocessing.jvm.processor.commons.PlainImageTransformer;
import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
import org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;

import java.awt.image.BufferedImage;
import java.io.File;
Expand All @@ -46,10 +47,11 @@ public class GenericImageClassification implements EventProcessor<GenericImageCl
private List<String> categories;

@Override
public void onInvocation(GenericImageClassificationParameters genericImageClassificationParameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) {
public void onInvocation(GenericImageClassificationParameters genericImageClassificationParameters,
SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) {
this.params = genericImageClassificationParameters;
//this.cs = FactoryImageClassifier.vgg_cifar10(); // Test set 89.9% for 10 categories
ClassifierAndSource cs = FactoryImageClassifier.nin_imagenet(); // Test set 62.6% for 1000 categories
ClassifierAndSource cs = FactoryImageClassifier.nin_imagenet(); // Test set 62.6% for 1000 categories

File path = DeepBoofDataBaseOps.downloadModel(cs.getSource(), new File("download_data"));

Expand All @@ -65,8 +67,8 @@ public void onInvocation(GenericImageClassificationParameters genericImageClassi
@Override
public void onEvent(Event in, SpOutputCollector out) {
PlainImageTransformer<GenericImageClassificationParameters> imageTransformer = new
PlainImageTransformer<>(in,
params);
PlainImageTransformer<>(in,
params);


Optional<BufferedImage> imageOpt = imageTransformer.getImage(params.getImagePropertyName());
Expand All @@ -86,7 +88,7 @@ public int compare(ImageClassifier.Score o1, ImageClassifier.Score o2) {
//Collections.reverse(scores);

if (scores.size() > 0) {
System.out.println(scores.get(0).score +":" +categories.get(scores.get(0).category));
System.out.println(scores.get(0).score + ":" + categories.get(scores.get(0).category));
//scores.forEach(score -> System.out.println(score.category +":" +categories.get(score.category) +":" +score));
in.addField("score", scores.get(0).score);
in.addField("category", categories.get(scores.get(0).category));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,45 @@
import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
import org.apache.streampipes.sdk.helpers.*;
import org.apache.streampipes.sdk.helpers.EpProperties;
import org.apache.streampipes.sdk.helpers.EpRequirements;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.helpers.OutputStrategies;
import org.apache.streampipes.sdk.utils.Assets;
import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;

public class GenericImageClassificationController extends StandaloneEventProcessingDeclarer<GenericImageClassificationParameters> {
public class GenericImageClassificationController
extends StandaloneEventProcessingDeclarer<GenericImageClassificationParameters> {

private static final String IMAGE = "image-mapping";

@Override
public DataProcessorDescription declareModel() {
return ProcessingElementBuilder.create("org.apache.streampipes.processor.imageclassification.jvm.generic-image-classification")
.category(DataProcessorType.IMAGE_PROCESSING)
.withAssets(Assets.DOCUMENTATION)
.withLocales(Locales.EN)
.requiredStream(StreamRequirementsBuilder
.create()
.requiredPropertyWithUnaryMapping(EpRequirements
.domainPropertyReq("https://image.com"), Labels.withId(IMAGE),
PropertyScope.NONE)
.build())
.outputStrategy(OutputStrategies.append(
EpProperties.doubleEp(Labels.empty(), "score", "https://schema.org/score"),
EpProperties.stringEp(Labels.empty(), "category", "https://schema.org/category")
return ProcessingElementBuilder.create(
"org.apache.streampipes.processor.imageclassification.jvm.generic-image-classification")
.category(DataProcessorType.IMAGE_PROCESSING)
.withAssets(Assets.DOCUMENTATION)
.withLocales(Locales.EN)
.requiredStream(StreamRequirementsBuilder
.create()
.requiredPropertyWithUnaryMapping(EpRequirements
.domainPropertyReq("https://image.com"), Labels.withId(IMAGE),
PropertyScope.NONE)
.build())
.outputStrategy(OutputStrategies.append(
EpProperties.doubleEp(Labels.empty(), "score", "https://schema.org/score"),
EpProperties.stringEp(Labels.empty(), "category", "https://schema.org/category")

))
.build();
))
.build();
}

@Override
public ConfiguredEventProcessor<GenericImageClassificationParameters> onInvocation(DataProcessorInvocation graph, ProcessingElementParameterExtractor extractor) {
public ConfiguredEventProcessor<GenericImageClassificationParameters> onInvocation(
DataProcessorInvocation graph,
ProcessingElementParameterExtractor extractor) {

String imageProperty = extractor.mappingPropertyValue(IMAGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class ImageCropper implements EventProcessor<ImageCropperParameters> {
private ImageCropperParameters params;

@Override
public void onInvocation(ImageCropperParameters imageCropperParameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) {
public void onInvocation(ImageCropperParameters imageCropperParameters, SpOutputCollector spOutputCollector,
EventProcessorRuntimeContext runtimeContext) {
this.params = imageCropperParameters;
}

Expand All @@ -52,7 +53,7 @@ public void onEvent(Event in, SpOutputCollector out) {
BoxCoordinates boxCoordinates = imageTransformer.getBoxCoordinates(image, box);

BufferedImage dest = image.getSubimage(boxCoordinates.getX(), boxCoordinates.getY(), boxCoordinates.getWidth(),
boxCoordinates.getHeight());
boxCoordinates.getHeight());

Optional<byte[]> finalImage = imageTransformer.makeImage(dest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,26 @@ public class ImageCropperController extends StandaloneEventProcessingDeclarer<Im
@Override
public DataProcessorDescription declareModel() {
return ProcessingElementBuilder.create("org.apache.streampipes.processor.imageclassification.jvm.image-cropper")
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.category(DataProcessorType.IMAGE_PROCESSING)
.requiredStream(RequiredBoxStream.getBoxStream())
.outputStrategy(OutputStrategies.append(
EpProperties.integerEp(Labels.empty(), "classname", "https://streampipes.org/classname"),
EpProperties.doubleEp(Labels.empty(), "score", "https://streampipes.org/Label")
))
.build();
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.category(DataProcessorType.IMAGE_PROCESSING)
.requiredStream(RequiredBoxStream.getBoxStream())
.outputStrategy(OutputStrategies.append(
EpProperties.integerEp(Labels.empty(), "classname", "https://streampipes.org/classname"),
EpProperties.doubleEp(Labels.empty(), "score", "https://streampipes.org/Label")
))
.build();
}

@Override
public ConfiguredEventProcessor<ImageCropperParameters> onInvocation(DataProcessorInvocation dataProcessorInvocation, ProcessingElementParameterExtractor extractor) {
public ConfiguredEventProcessor<ImageCropperParameters> onInvocation(DataProcessorInvocation dataProcessorInvocation,
ProcessingElementParameterExtractor extractor) {

String imageProperty = extractor.mappingPropertyValue(IMAGE_PROPERTY);
String boxArray = extractor.mappingPropertyValue(RequiredBoxStream.BOX_ARRAY_PROPERTY);

ImageCropperParameters params = new ImageCropperParameters(dataProcessorInvocation, imageProperty,
boxArray, "box_width", "box_height", "box_x", "box_y");
boxArray, "box_width", "box_height", "box_x", "box_y");

return new ConfiguredEventProcessor<>(params, ImageCropper::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

public class ImageCropperParameters extends ImageEnrichmentParameters {

public ImageCropperParameters(DataProcessorInvocation graph, String imageProperty, String boxArray, String boxWidth, String boxHeight, String boxX, String boxY) {
public ImageCropperParameters(DataProcessorInvocation graph, String imageProperty, String boxArray, String boxWidth,
String boxHeight, String boxX, String boxY) {
super(graph, imageProperty, boxArray, boxWidth, boxHeight, boxX, boxY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ public class BoxCoordinates {
private float score;
private String classesindex;

public static BoxCoordinates make(Float width, Float height, Float x, Float
y) {
public static BoxCoordinates make(
Float width,
Float height,
Float x,
Float y) {
return new BoxCoordinates(Math.round(width),
Math.round(height),
Math.round(x),
Math.round(y));
Math.round(height),
Math.round(x),
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),
score,
classesindex);
Math.round(height),
Math.round(x),
Math.round(y),
score,
classesindex);
}

public BoxCoordinates(int width, int height, int x, int y) {
Expand Down
Loading

0 comments on commit 7da2c1f

Please sign in to comment.