-
Notifications
You must be signed in to change notification settings - Fork 0
/
framerate.py
46 lines (30 loc) · 1.17 KB
/
framerate.py
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
#!/usr/bin/env python
import cv2
import time
import argparse
if __name__ == '__main__' :
ap = argparse.ArgumentParser()
ap.add_argument("-l","--location", help="Lokasi File")
ap.add_argument("-f","--frames", help="Jumlah Frame untuk dianalisa")
args = ap.parse_args()
video = cv2.VideoCapture(args.location or 0);
(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): {0}".format(fps))
else :
fps = video.get(cv2.CAP_PROP_FPS)
print ("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
num_frames = int(args.frames) ;
print ("Capturing {0} frames".format(num_frames))
start = time.time()
xrange = (0,num_frames)
for i in xrange :
ret, frame = video.read()
end = time.time()
seconds = end - start
print ("Time taken : {0} seconds".format(seconds))
proc_time = num_frames / seconds
fps = proc_time / 100
print ("Estimated frames per second : {0}".format(fps))
video.release()