-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.cpp
30 lines (26 loc) · 856 Bytes
/
camera.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
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
// open the first webcam plugged in the computer
cv::VideoCapture camera(0); // in linux check $ ls /dev/video0
if (!camera.isOpened()) {
std::cerr << "ERROR: Could not open camera" << std::endl;
return 1;
}
// create a window to display the images from the webcam
cv::namedWindow("Webcam", cv::WINDOW_AUTOSIZE);
// array to hold image
cv::Mat frame;
// display the frame until you press a key
while (1) {
// capture the next frame from the webcam
camera >> frame;
// show the image on the window
cv::imshow("Webcam", frame);
// wait (10ms) for esc key to be pressed to stop
if (cv::waitKey(10) == 27)
break;
}
imwrite("test.jpg", frame);
return 0;
}