From c65f157341e2d0afee88d462c819e660d46c683b Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 28 Sep 2022 11:09:14 +0200 Subject: Using TimeProbe class to asses loop performance. --- src/argaze/utils/tobii_stream_aruco_aoi_display.py | 18 +++++++++--------- src/argaze/utils/tobii_stream_display.py | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/argaze/utils/tobii_stream_aruco_aoi_display.py b/src/argaze/utils/tobii_stream_aruco_aoi_display.py index c57bba3..d619faa 100644 --- a/src/argaze/utils/tobii_stream_aruco_aoi_display.py +++ b/src/argaze/utils/tobii_stream_aruco_aoi_display.py @@ -100,10 +100,9 @@ def main(): # Live video stream capture loop try: - # Assess temporal preformance + # Assess loop performance + loop_chrono = MiscFeatures.TimeProbe() fps = 0 - current_time = time.time() - frame_counter = 0 # Detect head movement head_moving = False @@ -236,13 +235,14 @@ def main(): except KeyError: pass - # Assess temporal performance - frame_counter += 1 + # Assess loop performance + loop_time, loop_counter, elapsed_time = loop_chrono.lap() - if frame_counter == 25: - fps = 25 / (time.time() - current_time) - current_time = time.time() - frame_counter = 0 + # Update fps each 10 loops + if loop_counter >= 10: + + fps = loop_counter / elapsed_time + loop_chrono.restart() # Draw focus area cv.rectangle(visu_frame.matrix, (int(video_frame.width/6), 0), (int(visu_frame.width*(1-1/6)), int(visu_frame.height)), (255, 150, 150), 1) diff --git a/src/argaze/utils/tobii_stream_display.py b/src/argaze/utils/tobii_stream_display.py index 006cf81..8dd2341 100644 --- a/src/argaze/utils/tobii_stream_display.py +++ b/src/argaze/utils/tobii_stream_display.py @@ -1,10 +1,10 @@ #!/usr/bin/env python import argparse -import os, time from argaze import DataStructures, GazeFeatures from argaze.TobiiGlassesPro2 import * +from argaze.utils import MiscFeatures import cv2 as cv import numpy @@ -44,17 +44,16 @@ def main(): # Live video and data stream capture loop try: - # Assess temporal preformance + # Assess loop performance + loop_chrono = MiscFeatures.TimeProbe() fps = 0 - current_time = time.time() - frame_counter = 0 while tobii_video_stream.is_alive(): # Read video stream video_ts, video_frame = tobii_video_stream.read() video_ts_ms = video_ts / 1e3 - + # Read data stream data_ts, data_stream = tobii_data_stream.read() data_ts_ms = data_ts / 1e3 @@ -118,14 +117,15 @@ def main(): # Wait for gaze position except KeyError: pass + + # Assess loop performance + loop_time, loop_counter, elapsed_time = loop_chrono.lap() - # Assess temporal performance - frame_counter += 1 + # Update fps each 10 loops + if loop_counter >= 10: - if frame_counter == 25: - fps = 25 / (time.time() - current_time) - current_time = time.time() - frame_counter = 0 + fps = loop_counter / elapsed_time + loop_chrono.restart() # Draw center cv.line(video_frame.matrix, (int(video_frame.width/2) - 50, int(video_frame.height/2)), (int(video_frame.width/2) + 50, int(video_frame.height/2)), (255, 150, 150), 1) -- cgit v1.1