-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathadjust_camera.java
47 lines (39 loc) · 1.41 KB
/
adjust_camera.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
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.videoio.VideoCapture;
import org.opencv.highgui.HighGui;
public class VideoCaptureExample {
public static void main(String[] args) {
// Load the OpenCV library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Create a VideoCapture object
VideoCapture capture = new VideoCapture(0); // Adjust the camera index if needed
if (!capture.isOpened()) {
System.out.println("Failed to open video capture.");
return;
}
// Create a Mat object to store the frame
Mat frame = new Mat();
// Main loop for video capture
while (true) {
// Read a frame from the video capture
if (capture.read(frame)) {
// Print the shape of the frame (height, width, channels)
System.out.println("Shape: " + frame.size());
// Display the frame
HighGui.imshow("Frame", frame);
} else {
System.out.println("Failed to read frame");
break;
}
// Exit the loop if 'q' is pressed
if (HighGui.waitKey(1) == 'q') {
break;
}
}
// Release the video capture and close the window
capture.release();
HighGui.destroyAllWindows();
}
}