Skip to content

Commit

Permalink
first cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanheller authored and faberf committed Jun 8, 2023
1 parent 55a147b commit 546b23c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.vitrivr.cineast.core.util.web.FeatureClient;

public abstract class AbstractFeatureClientWrapper {
protected final FeatureClient client;
Expand All @@ -18,7 +19,7 @@ protected AbstractFeatureClientWrapper(FeatureClient client) {

private static FeatureClient buildFeatureClient(Map<String,String> properties){
if(!properties.containsKey("endpoint")){
throw new IllegalStateException("No endpoint specified for external client"); //throw better exception
throw new IllegalArgumentException("No endpoint specified for external client"); //throw better exception
}
String endpoint = properties.get("endpoint");
return new FeatureClient(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@
import org.apache.logging.log4j.Logger;
import org.vitrivr.cineast.core.data.entities.SimpleFulltextFeatureDescriptor;
import org.vitrivr.cineast.core.data.entities.SimplePrimitiveTypeProviderFeatureDescriptor;
import org.vitrivr.cineast.core.data.frames.VideoFrame;
import org.vitrivr.cineast.core.data.segments.SegmentContainer;
import org.vitrivr.cineast.core.features.abstracts.AbstractTextRetriever;
import org.vitrivr.cineast.core.util.CineastConstants;

public class ExternalTextFeature extends AbstractTextRetriever {

public static final String DEFAULT_TABLE_NAME = "features_externalText";

final AbstractFeatureClientWrapper client;

public ExternalTextFeature() {
super(DEFAULT_TABLE_NAME);
throw new IllegalArgumentException("no properties specified");
}

public ExternalTextFeature(Map<String, String> properties) throws Exception {
super("externalText", properties); // get or default tablenamekey (oder so)
super(properties.getOrDefault(CineastConstants.ENTITY_NAME_KEY, DEFAULT_TABLE_NAME), properties);
this.client = AbstractFeatureClientWrapper.build(properties);
}

private static final Logger LOGGER = LogManager.getLogger();

@Override
public void processSegment(SegmentContainer sc){
BufferedImage img = sc.getMostRepresentativeFrame().getImage().getBufferedImage();
public void processSegment(SegmentContainer sc) {
if (sc.getMostRepresentativeFrame() == null || sc.getMostRepresentativeFrame() == VideoFrame.EMPTY_VIDEO_FRAME) {
return;
}
try {
BufferedImage img = sc.getMostRepresentativeFrame().getImage().getBufferedImage();
String feature = client.extractTextFromImage(img);
var descriptor = new SimpleFulltextFeatureDescriptor(sc.getId(), feature);
this.writer.write(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.vitrivr.cineast.core.util.web.FeatureClient;
import org.vitrivr.cineast.core.util.web.ImageParser;

public class SimpleFESWrapper extends AbstractFeatureClientWrapper{
public class SimpleFESWrapper extends AbstractFeatureClientWrapper {

private final JsonMapper mapper = new JsonMapper();
private final JsonNode config;

public SimpleFESWrapper(FeatureClient client, JsonNode config) throws Exception {
super(client);
this.config = config;
Expand Down Expand Up @@ -42,7 +41,7 @@ public String extractTextFromImage(BufferedImage bufImg) throws IOException, Int
// String body = gson.toJson(map);

String responseBody = this.client.getResponse(requestBody);
return mapper.readValue(responseBody,String[].class)[0]; // change this
return mapper.readValue(responseBody, String[].class)[0]; // change this
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vitrivr.cineast.core.features;
package org.vitrivr.cineast.core.util.web;

import java.io.IOException;
import java.net.URI;
Expand All @@ -9,9 +9,9 @@

public class FeatureClient {

private String endpoint;
private final String endpoint;

public FeatureClient(String endpoint){
public FeatureClient(String endpoint) {
this.endpoint = endpoint;
}

Expand Down

0 comments on commit 546b23c

Please sign in to comment.