-
Notifications
You must be signed in to change notification settings - Fork 5
/
AlgoViewer.java
80 lines (65 loc) · 2.41 KB
/
AlgoViewer.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
package org.genericsystem.cv;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import org.genericsystem.layout.Layout;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;
public class AlgoViewer extends AbstractApp {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
launch(args);
}
private final VideoCapture capture = new VideoCapture(0);
private ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
@Override
protected void fillGrid(GridPane mainGrid) {
Mat frame = new Mat();
capture.read(frame);
ImageView src = new ImageView(Tools.mat2jfxImage(frame));
mainGrid.add(src, 0, 0);
ImageView src1 = new ImageView(Tools.mat2jfxImage(frame));
mainGrid.add(src1, 1, 0);
ImageView src2 = new ImageView(Tools.mat2jfxImage(frame));
mainGrid.add(src2, 0, 1);
ImageView src3 = new ImageView(Tools.mat2jfxImage(frame));
mainGrid.add(src3, 1, 1);
timer.scheduleAtFixedRate(() -> {
capture.read(frame);
Img frameImg = new Img(frame, false);
Img img0 = frameImg.bgr2Gray().adaptativeThresHold(255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 17, 15);
Img img1 = frameImg.canny(60, 200).bitwise_not();
Img img2 = frameImg.bgr2Gray().grad(3, 3).thresHold(0, 255, Imgproc.THRESH_BINARY_INV + Imgproc.THRESH_OTSU);
Img img3 = frameImg.sauvolaThreshold().bitwise_not();
Layout layout = frameImg.buildLayout(img0);
Layout layout1 = frameImg.buildLayout(img1);
Layout layout2 = frameImg.buildLayout(img2);
Layout layout3 = frameImg.buildLayout(img3);
Img out = new Img(frame, true);
layout.draw(img0, new Scalar(0), 1);
Img out1 = new Img(frame, true);
layout1.draw(img1, new Scalar(0), 1);
Img out2 = new Img(frame, true);
layout2.draw(img2, new Scalar(0), 1);
Img out3 = new Img(frame, true);
layout3.draw(img3, new Scalar(0), 1);
src.setImage(img0.toJfxImage());
src1.setImage(img1.toJfxImage());
src2.setImage(img2.toJfxImage());
src3.setImage(img3.toJfxImage());
}, 400, 10, TimeUnit.MILLISECONDS);
}
@Override
public void stop() throws Exception {
timer.shutdown();
capture.release();
super.stop();
}
}