From 97a76c5e5b36156ac4a04e894e3f613c5c9806d3 Mon Sep 17 00:00:00 2001 From: KRSHH <136873090+KRSHH@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:57:47 +0530 Subject: [PATCH] Revert "Update ui.py" This reverts commit df72a5431b36afccf25e53c4a057cbe8caf77673. --- modules/ui.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 983cc71..a748e8c 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1404,14 +1404,15 @@ def create_webcam_preview(camera_index: int): # FPS tracking variables prev_time = time.time() - fps_update_interval = 1.0 + fps_update_interval = 1.0 # Increased to 1 second for stability frame_count = 0 fps = 0 - fps_display = "FPS: --" + fps_display = "FPS: --" # Initialize fps display text - # Remove cached show_fps value - we'll check it in real-time instead + # Cache frequently accessed values live_mirror = modules.globals.live_mirror live_resizable = modules.globals.live_resizable + show_fps = modules.globals.show_fps map_faces = modules.globals.map_faces while camera.isOpened() and PREVIEW.state() != "withdrawn": @@ -1437,20 +1438,20 @@ def create_webcam_preview(camera_index: int): for frame_processor in frame_processors: temp_frame = frame_processor.process_frame_v2(temp_frame) - # FPS calculation (always calculate it) + # FPS calculation and display frame_count += 1 current_time = time.time() if current_time - prev_time >= fps_update_interval: fps = frame_count / (current_time - prev_time) - fps_display = f"FPS: {fps:.1f}" + fps_display = f"FPS: {fps:.1f}" # Update display text frame_count = 0 prev_time = current_time - # Check show_fps state in real-time - if modules.globals.show_fps: + # Always show the last calculated FPS value + if show_fps: cv2.putText( temp_frame, - fps_display, + fps_display, # Use stored fps display text (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1,