-
Notifications
You must be signed in to change notification settings - Fork 5
/
OcrVerticle.java
49 lines (42 loc) · 1.58 KB
/
OcrVerticle.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
package org.genericsystem.watch;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.genericsystem.cv.DidjvuScript;
import org.genericsystem.cv.Ocr;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
public class OcrVerticle extends AbstractVerticle {
private static Logger log = LoggerFactory.getLogger(ClassifierVerticle.class);
public static void main(String[] args) {
VerticleDeployer.deployVerticle(new OcrVerticle());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Added a simple Verticle that will publish an example string on the event bus
VerticleDeployer.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
Path imagePath = Paths.get(System.getProperty("user.dir") + "/../gs-cv/classes/id-fr-front/image-1.png");
vertx.eventBus().publish(VerticleDeployer.IMAGE_ADDED_TO_CLASS_ADDRESS, imagePath.toString());
}
});
}
@Override
public void start() throws Exception {
MessageConsumer<String> consumer = vertx.eventBus().consumer(VerticleDeployer.IMAGE_ADDED_TO_CLASS_ADDRESS);
consumer.handler(message -> vertx.executeBlocking(future -> {
String imagePath = message.body();
System.out.println(">>>>> New image to OCR: " + imagePath);
Ocr.ocrNewClassifiedImg(Paths.get(imagePath));
future.complete();
}, res -> {
if (res.failed())
throw new IllegalStateException(res.cause());
}));
}
}