forked from sheydinger/opencv-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowWebcam.cpp
38 lines (27 loc) · 981 Bytes
/
ShowWebcam.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
#include <time.h>
#include "opencv2/opencv.hpp"
/*
* Objective: Show how to read and display frames captured from a webcam,
* and compute and show the meaasured frame rate. Press ESC to exit the program.
*/
int main(int argc, const char * argv[]) {
int frameCount = 0;
clock_t start = clock();
cv::Mat frame;
cv::VideoCapture cap(0);
std::cout << "FPS " << cap.get(CV_CAP_PROP_FPS) << " FPS\n";
std::cout << "WIDTH " << cap.get(CV_CAP_PROP_FRAME_WIDTH) << "\n";
std::cout << "HEIGHT " << cap.get(CV_CAP_PROP_FRAME_HEIGHT) << "\n";
while (1)
{
cap.read(frame);
cv::imshow("Camera", frame);
// Press ESC to exit.
if (cv::waitKey(1) == 27)
exit(0);
frameCount++;
if (frameCount % 20 == 0)
std::cout << ((float) frameCount / ((float) (clock() - start) / (float) 1000000.f)) << "\n";
};
return 0;
}