-
Notifications
You must be signed in to change notification settings - Fork 5
/
ClassifierVerticle.java
50 lines (41 loc) · 1.43 KB
/
ClassifierVerticle.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
package org.genericsystem.watch.gamma;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.genericsystem.cv.Classifier;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
public class ClassifierVerticle extends ActionVerticle {
public ClassifierVerticle(String ip) {
super(ip);
}
public static final String ACTION = "classification";
@Override
public String getAction() {
return ACTION;
}
@Override
protected void handle(Future<Object> future, JsonObject task) {
File file = new File(DistributedVerticle.BASE_PATH + task.getString(DistributedVerticle.FILENAME));
Path savedFile;
synchronized (ClassifierVerticle.class) {
savedFile = Classifier.classify(Paths.get("../gs-cv/classes/"), file.toPath());
}
if (savedFile != null)
future.complete(savedFile);
else
future.fail("Impossible to classify image.");
}
@Override
protected void handleResult(AsyncResult<Object> res, JsonObject task) {
if (res.succeeded()) {
// long id = System.currentTimeMillis();
// messages.add(new JsonObject().put(ID, id).put("task", new JsonObject().put(ID, id).put(FILENAME, newPng).put(IP, ip).put(TYPE, CLASSIFY)));
System.out.println("Image classified : " + res.result());
} else {
System.out.println("Impossible to classify image : " + task.getString(DistributedVerticle.FILENAME));
res.cause().printStackTrace();
}
}
}