Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/FPS/frame_rate.py
3118 views
1
#!/usr/bin/env python
2
3
import cv2
4
import time
5
6
if __name__ == '__main__' :
7
8
# Start default camera
9
video = cv2.VideoCapture(0);
10
11
# Find OpenCV version
12
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
13
14
# With webcam get(CV_CAP_PROP_FPS) does not work.
15
# Let's see for ourselves.
16
17
if int(major_ver) < 3 :
18
fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
19
print "Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps)
20
else :
21
fps = video.get(cv2.CAP_PROP_FPS)
22
print "Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps)
23
24
25
# Number of frames to capture
26
num_frames = 120;
27
28
29
print "Capturing {0} frames".format(num_frames)
30
31
# Start time
32
start = time.time()
33
34
# Grab a few frames
35
for i in xrange(0, num_frames) :
36
ret, frame = video.read()
37
38
39
# End time
40
end = time.time()
41
42
# Time elapsed
43
seconds = end - start
44
print "Time taken : {0} seconds".format(seconds)
45
46
# Calculate frames per second
47
fps = num_frames / seconds;
48
print "Estimated frames per second : {0}".format(fps);
49
50
# Release video
51
video.release()
52
53
54
55