forked from anshulkhare7/python-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckFPS.py
More file actions
70 lines (48 loc) · 1.83 KB
/
checkFPS.py
File metadata and controls
70 lines (48 loc) · 1.83 KB
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
import cv2, time
def main():
checkVideoFPS()
checkCamFPS()
def checkVideoFPS():
video = cv2.VideoCapture("/Users/anshul/Freelancing/Innocule/data/dumping-webcamshots/North-15Apr-1600hrs/North-15Apr-1600hrs.mp4");
# Find OpenCV version
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
if int(major_ver) < 3 :
fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
print('Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): ', str(fps))
else :
fps = video.get(cv2.CAP_PROP_FPS)
print('Frames per second using video.get(cv2.CAP_PROP_FPS): ', str(fps))
video.release()
def checkCamFPS():
# Start default camera
video = cv2.VideoCapture(0);
# Find OpenCV version
(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')
# With webcam get(CV_CAP_PROP_FPS) does not work.
# Let's see for ourselves.
if int(major_ver) < 3 :
fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
print('Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): ', str(fps))
else :
fps = video.get(cv2.CAP_PROP_FPS)
print('Frames per second using video.get(cv2.CAP_PROP_FPS) : ', str(fps))
# Number of frames to capture
num_frames = 120;
print('Capturing ', str(num_frames), ' frames')
# Start time
start = time.time()
# Grab a few frames
for i in range(0, num_frames) :
ret, frame = video.read()
# End time
end = time.time()
# Time elapsed
seconds = end - start
print('Time taken : ', str(seconds) ,'seconds')
# Calculate frames per second
fps = num_frames / seconds;
print('Estimated frames per second : ', str(fps));
# Release video
video.release()
if __name__=="__main__":
main()