-
Notifications
You must be signed in to change notification settings - Fork 5
/
OcrParametersVerticle.java
57 lines (46 loc) · 1.55 KB
/
OcrParametersVerticle.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
56
57
package org.genericsystem.watch;
import java.nio.file.Paths;
import org.genericsystem.common.Root;
import org.genericsystem.cv.comparator.FillModelWithData;
import com.sun.xml.internal.ws.api.pipe.Engine;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
/**
* The OcrParametersVerticle computes the OCR parameters and send them to the event bus as a {@link JsonObject}.
*
* @author Pierrik Lassalas
*/
public class OcrParametersVerticle extends ActionVerticle {
public static final String ACTION = "ocr";
@Override
public String getAction() {
return ACTION;
}
private Root engine;
/**
* Default constructor. A reference to an {@link Engine} must be provided.
*
* @param engine - the engine used to store the data
*/
public OcrParametersVerticle(Root engine) {
this.engine = engine;
}
@Override
protected void handle(Future<Object> future, JsonObject task) {
String imagePath = task.getString(DistributedVerticle.FILENAME);
JsonObject params = FillModelWithData.getOcrParameters(engine, Paths.get(imagePath));
if (null != params)
future.complete(params);
else
future.fail("Unable to get the OCR parameters");
}
@Override
protected void handleResult(AsyncResult<Object> res, JsonObject task) {
if (res.succeeded()) {
if (!((JsonObject) res.result()).isEmpty())
addTask(task.getString(DistributedVerticle.FILENAME), (JsonObject) res.result(), OcrWorkerVerticle.ACTION);
} else
throw new IllegalStateException("Exception in OcrParametersVerticle.", res.cause());
}
}