Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/FPS/frame_rate.cpp
3118 views
1
#include "opencv2/opencv.hpp"
2
#include <time.h>
3
4
using namespace cv;
5
using namespace std;
6
7
int main(int argc, char** argv)
8
{
9
10
// Start default camera
11
VideoCapture video(0);
12
13
// With webcam get(CV_CAP_PROP_FPS) does not work.
14
// Let's see for ourselves.
15
16
double fps = video.get(cv::CAP_PROP_FPS);
17
// If you do not care about backward compatibility
18
// You can use the following instead for OpenCV 3
19
// double fps = video.get(CAP_PROP_FPS);
20
cout << "Frames per second using video.get(CV_CAP_PROP_FPS) : " << fps << endl;
21
22
// Number of frames to capture
23
int num_frames = 120;
24
25
// Start and end times
26
time_t start, end;
27
28
// Variable for storing video frames
29
Mat frame;
30
31
cout << "Capturing " << num_frames << " frames" << endl ;
32
33
// Start time
34
time(&start);
35
36
// Grab a few frames
37
for(int i = 0; i < num_frames; i++)
38
{
39
video >> frame;
40
}
41
42
// End Time
43
time(&end);
44
45
// Time elapsed
46
double seconds = difftime (end, start);
47
cout << "Time taken : " << seconds << " seconds" << endl;
48
49
// Calculate frames per second
50
fps = num_frames / seconds;
51
cout << "Estimated frames per second : " << fps << endl;
52
53
// Release video
54
video.release();
55
return 0;
56
}
57
58