-
Notifications
You must be signed in to change notification settings - Fork 5
/
ClassImgFieldsDetector.java
92 lines (82 loc) · 3.12 KB
/
ClassImgFieldsDetector.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package org.genericsystem.cv;
import java.io.File;
import java.util.stream.Stream;
import org.opencv.core.Core;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import javafx.scene.layout.GridPane;
public class ClassImgFieldsDetector extends AbstractApp {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
private final static String imgClassDirectory = "classes/passport-fr";
public static void main(String[] args) {
launch(args);
}
@Override
protected void fillGrid(GridPane mainGrid) {
int columnIndex = 0;
int rowIndex = 0;
//
// mainGrid.add(imgClass.getMean().getImageView(), columnIndex,
// rowIndex++);
// mainGrid.add(imgClass.getVariance().getImageView(), columnIndex,
// rowIndex++);
//
// imgClass.addMapper(img -> img.eraseCorners(0.1).dilateBlacks(86, 255,
// 76, new Size(20, 3)));
// mainGrid.add(imgClass.getMean().getImageView(), columnIndex,
// rowIndex++);
// mainGrid.add(imgClass.getVariance().getImageView(), columnIndex,
// rowIndex++);
//
// Img img1 = Tools.firstImg(imgClassDirectory);
// Zones.get(img1.sobel(), 300).draw(img1, new Scalar(0, 255, 0), 3);
// mainGrid.add(img1.getImageView(), columnIndex, rowIndex++);
//
// Img img2 = Tools.firstImg(imgClassDirectory);
// Zones.get(img2.mser(), 300).draw(img2, new Scalar(255, 0, 0), 3);
// mainGrid.add(img2.getImageView(), columnIndex, rowIndex++);
//
// Img img3 = Tools.firstImg(imgClassDirectory);
// Zones.get(img3.grad(), 300).draw(img3, new Scalar(0, 0, 255), 3);
// mainGrid.add(img3.getImageView(), columnIndex, rowIndex++);
ImgClass imgClass = ImgClass.fromDirectory(imgClassDirectory);
Zones zones;
try {
zones = Zones.load(imgClassDirectory);
} catch (RuntimeException e) {
System.out.println("could not load accurate zones");
zones = Zones.get(imgClass.getClosedVarianceZones(new Size(9, 10)), 300, 6, 6);
}
Img model = imgClass.getMean();
zones.draw(model, new Scalar(0, 255, 0), 3);
mainGrid.add(model.getImageView(), columnIndex, rowIndex++);
int i = 0;
for (File file : new File(imgClassDirectory).listFiles())
if (file.getName().endsWith(".png")) {
System.out.println("File : " + file.getName());
// if (i++ > 2)
// continue;
// System.out.println("File : " + file.getName());
Img img = new Img(Imgcodecs.imread(file.getPath()));
for (Zone zone : zones.get()) {
System.out.println("Zone n°" + zone.getNum());
zone.draw(img, new Scalar(0, 255, 0), -1);
ZoneScorer scorer = zone.newUnsupervisedScorer(Stream.concat(
Tools.classImgsStream(imgClassDirectory, file.getName()),
Tools.classImgsStream(imgClassDirectory + "/mask/" + file.getName().replace(".png", ""))));
// // zone.write(img,
// // scorer.getBestText() + " " +
// // Math.floor((scorer.getBestScore() * 10000)) / 100 +
// "%",
// // 2.5,
// // new Scalar(0, 0, 255), 2);
zone.write(img, scorer.getBestText2(), 2.5, new Scalar(0, 0, 255), 2);
System.out.println("Best text : " + scorer.getBestText2());
}
mainGrid.add(img.getImageView(), columnIndex, rowIndex++);
}
}
}