-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
74 lines (54 loc) · 1.55 KB
/
App.java
File metadata and controls
74 lines (54 loc) · 1.55 KB
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
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
public class App {
ImageProcessor imageprocessor = new ImageProcessor();
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
private JFrame frame;
private JLabel imageLabel;
public static void main(String[] args) {
// TODO Auto-generated method stub
App app = new App();
app.initGUI();
app.runMainLoop(args);
}
private void initGUI() {
frame = new JFrame("Camera Input Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
imageLabel = new JLabel();
frame.add(imageLabel);
frame.setVisible(true);
}
private void runMainLoop(String[] args) {
Mat mat = new Mat();
Image tempImage;
VideoCapture cap = new VideoCapture(0);
cap.set(Videoio.CAP_PROP_FRAME_WIDTH, 320);
cap.set(Videoio.CAP_PROP_FRAME_HEIGHT, 240);
if(cap.isOpened()) {
while(true) {
cap.read(mat);
if(!mat.empty()) {
tempImage= imageprocessor.toBufferedImage(mat);
ImageIcon imageIcon = new ImageIcon(tempImage, "Captured video");
imageLabel.setIcon(imageIcon);
frame.pack();
}
else {
System.out.println("-- Frame not captured -- Break!");
}
}
}
else {
System.out.println("Couldn't open capture.");
}
}
}