From 708284749da21b90094cfe876cd74970d3d69b20 Mon Sep 17 00:00:00 2001 From: Simon Pirkelmann Date: Sat, 14 Nov 2020 16:39:53 +0100 Subject: [PATCH] fps counter --- remote_control/aruco_estimator.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/remote_control/aruco_estimator.py b/remote_control/aruco_estimator.py index 275870f..fc0fee9 100644 --- a/remote_control/aruco_estimator.py +++ b/remote_control/aruco_estimator.py @@ -167,6 +167,9 @@ class ArucoEstimator: cv2.namedWindow('RoboRally', cv2.WINDOW_AUTOSIZE) cv2.setMouseCallback('RoboRally', self.mouse_callback) + fps_display_rate = 1 # displays the frame rate every 1 second + fps_counter = 0 + start_time = time.time() try: running = True while running: @@ -221,6 +224,16 @@ class ArucoEstimator: if self.drag_line_start is not None and self.drag_line_end is not None: color_image = cv2.line(color_image, self.drag_line_start, self.drag_line_end, color=(0, 0, 255), thickness=2) + # compute frame rate + fps_counter += 1 + delta_t = time.time() - start_time + if delta_t > fps_display_rate: + fps_counter = 0 + start_time = time.time() + color_image = cv2.putText(color_image, f"fps = {(fps_counter / delta_t):.2f}", (10, 25), cv2.FONT_HERSHEY_PLAIN, 2, + (0, 255, 255), + thickness=2) + # Show images cv2.imshow('RoboRally', color_image) key = cv2.waitKey(1)