-
Notifications
You must be signed in to change notification settings - Fork 5
/
LayoutAnalyzer.java
53 lines (42 loc) · 2.36 KB
/
LayoutAnalyzer.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
package org.genericsystem.layout;
import org.genericsystem.cv.AbstractApp;
import org.genericsystem.cv.Img;
import org.opencv.core.Core;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
public class LayoutAnalyzer extends AbstractApp {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
launch(args);
}
@Override
protected void fillGrid(GridPane mainGrid) {
int columnIndex = 0;
int rowIndex = 0;
rowIndex = 0;
columnIndex++;
Img img = new Img("resources/14342661748973931.jpg");
Img adaptivSplit = img.bgr2Gray().adaptativeThresHold(255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 17, 15);
Layout layout = img.buildLayout(new Size(0.036, 0.008), 5, 0.008f, img, adaptivSplit);
layout.draw(layout.getRoi(img), new Scalar(0, 255, 0), 1);
mainGrid.add(new ImageView(img.toJfxImage()), columnIndex, rowIndex++);
mainGrid.add(new ImageView(adaptivSplit.toJfxImage()), columnIndex, rowIndex++);
Img hImg = new Img("resources/14342661748973931.jpg").bgr2Gray().adaptativeThresHold(255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 17, 15).morphologyEx(Imgproc.MORPH_CLOSE, Imgproc.MORPH_RECT, new Size(20, 1));
Img vImg = new Img("resources/14342661748973931.jpg").bgr2Gray().adaptativeThresHold(255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 17, 15).morphologyEx(Imgproc.MORPH_CLOSE, Imgproc.MORPH_RECT, new Size(1, 20));
mainGrid.add(new ImageView(hImg.toJfxImage()), columnIndex, rowIndex++);
mainGrid.add(new ImageView(vImg.toJfxImage()), columnIndex, rowIndex++);
mainGrid.add(new ImageView(hImg.bitwise_and(vImg).toJfxImage()), columnIndex, rowIndex++);
Img ultimate = new Img("resources/14342661748973931.jpg").bgr2Gray().adaptativeThresHold(255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 17, 15).bitwise_xor(hImg.bitwise_and(vImg).bitwise_not());
mainGrid.add(new ImageView(ultimate.toJfxImage()), columnIndex, rowIndex++);
img = new Img("resources/14342661748973931.jpg");
layout = img.buildLayout(new Size(0.036, 0.008), 7, 0.008f, img, ultimate);
layout.draw(layout.getRoi(img), new Scalar(0, 255, 0), 1);
mainGrid.add(new ImageView(img.toJfxImage()), columnIndex, rowIndex++);
System.out.println(layout.recursivToString());
}
}