-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaptureCamera.java
60 lines (35 loc) · 1.49 KB
/
CaptureCamera.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
// ********************************************************
// Example : displaying image from attached camera
// Author : Toby Breckon, toby.breckon@durham.ac.uk
// Copyright (c) 2015 Durham University
// License : LGPL - http://www.gnu.org/licenses/lgpl.html
// ********************************************************
// import required OpenCV components
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.VideoCapture;
// ********************************************************
public class CaptureCamera {
public static void main(String[] args) {
// load the Core OpenCV library by name
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// create video capture device object (camera index = 0)
VideoCapture cap = new VideoCapture(0);
if (!cap.isOpened())
System.out.println("error cannot any open camera");
else
System.out.println("found webcam: " + cap.toString());
Mat matFrame = new Mat();
// Grabs the next frame from video file or capturing device
cap.grab(); // First frame maybe empty frame so skip it
cap.grab();
// Decodes and returns the grabbed video frame.
cap.retrieve(matFrame);
// display image
Imshow ims = new Imshow("From Camera ....");
ims.showImage(matFrame);
// close down the camera correctly
cap.release();
}
}
// ********************************************************