-
Notifications
You must be signed in to change notification settings - Fork 5
/
DezonerVerticle.java
55 lines (46 loc) · 1.89 KB
/
DezonerVerticle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.genericsystem.ir;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.genericsystem.common.Root;
import org.genericsystem.cv.classifier.FillNewModelWithData;
import org.genericsystem.cv.utils.ModelTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
/**
* The DezonerVerticle receives a message from the event bus when a new image has been added to a class. If this class has already been dezoned, a message will be sent to the {@link OcrParametersVerticle}.
*
* @author Pierrik Lassalas
*/
public class DezonerVerticle extends ActionPersistentVerticle {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String ACTION = "dezoner";
public DezonerVerticle(Root engine) {
super(engine);
}
@Override
public String getAction() {
return ACTION;
}
@Override
protected void handle(Future<Object> future, JsonObject task) {
Path imagePath = Paths.get(DistributedVerticle.BASE_PATH + task.getString(DistributedVerticle.FILENAME));
JsonObject fields = FillNewModelWithData.detectFields(imagePath);
if (null == fields || fields.isEmpty())
future.fail("No fields detected for image " + task.getString(DistributedVerticle.FILENAME));
else
future.complete(fields);
}
@Override
protected void handleResult(AsyncResult<Object> res, JsonObject task) {
if (res.succeeded()) {
// TODO: add another task that will annotate the image with the new zones (draw rect + nums) and copy it to the resources folder
addTask(task.getString(DistributedVerticle.FILENAME), (JsonObject) res.result(), OcrWorkerVerticle.ACTION);
} else {
logger.info(String.format("No zones defined for file {}.", task.getString(DistributedVerticle.FILENAME)), res.cause());
}
}
}