From 47ba346d89774c7da85412efcdb9e01e29b7c37b Mon Sep 17 00:00:00 2001 From: Suprito Dey Sarkar Date: Tue, 31 Aug 2021 14:01:29 +0530 Subject: [PATCH] Added fps counter to show the fps when the detector runs on video --- Object_detection_video.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Object_detection_video.py b/Object_detection_video.py index a6ca6d5d..9578ea75 100644 --- a/Object_detection_video.py +++ b/Object_detection_video.py @@ -90,8 +90,15 @@ # Open video file video = cv2.VideoCapture(PATH_TO_VIDEO) +#additional_code +start_time = time.time() +flag=0 + while(video.isOpened()): + start = time.time() + flag = flag + 1 + # Acquire frame and expand frame dimensions to have shape: [1, None, None, 3] # i.e. a single-column array, where each item in the column has the pixel RGB value ret, frame = video.read() @@ -113,6 +120,11 @@ use_normalized_coordinates=True, line_thickness=8, min_score_thresh=0.60) + + #Shows the fps in the terminal + cv2.imshow('Object detector', frame) + fps1 = 1/(time.time() - start) + print("fps: ",fps1) # All the results have been drawn on the frame, so it's time to display it. cv2.imshow('Object detector', frame) @@ -121,6 +133,11 @@ if cv2.waitKey(1) == ord('q'): break +#Average fps +end_time = time.time() +fps = flag/(end_time - start_time) +print("Average FPS: ",fps) + # Clean up video.release() cv2.destroyAllWindows()