-
Notifications
You must be signed in to change notification settings - Fork 0
/
F6.cpp
84 lines (42 loc) · 1.19 KB
/
F6.cpp
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
81
82
83
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
// Create a window to display the camera feed.
namedWindow("Camera", WINDOW_AUTOSIZE);
// Create a video capture object.
VideoCapture cap(0);
// Check if the camera is opened successfully.
if (!cap.isOpened()) {
cout << "Error opening the camera!" << endl;
return -1;
}
// Create a timer to capture frames from the camera.
int frame_rate = 30;
int delay = 1000 / frame_rate;
// Create a while loop to capture frames from the camera and display them on the window.
while (true) {
// Capture a frame from the camera.
Mat frame;
cap >> frame;
// If the frame is empty, break out of the loop.
if (frame.empty()) {
break;
}
// Display the frame on the window.
imshow("Camera", frame);
// Wait for the user to press a key.
int key = waitKey(delay);
// If the user presses the Esc key, break out of the loop.
if (key == 27) {
break;
}
}
// Close the window.
destroyWindow("Camera");
// Release the video capture object.
cap.release();
return 0;
}