aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/utils/demo_aruco_markers_run.py71
1 files changed, 61 insertions, 10 deletions
diff --git a/src/argaze/utils/demo_aruco_markers_run.py b/src/argaze/utils/demo_aruco_markers_run.py
index 6dc081d..6c22695 100644
--- a/src/argaze/utils/demo_aruco_markers_run.py
+++ b/src/argaze/utils/demo_aruco_markers_run.py
@@ -14,6 +14,7 @@ import time
from argaze import ArFeatures, GazeFeatures
from argaze.ArUcoMarkers import ArUcoCamera
+from argaze.utils import UtilsFeatures
import cv2
import numpy
@@ -40,9 +41,29 @@ def main():
# Init timestamp
start_time = time.time()
+ # Prepare gaze analysis assessment
+ call_chrono = UtilsFeatures.TimeProbe()
+ call_chrono.start()
+
+ gaze_positions_frequency = 0
+ gaze_analysis_time = 0
+
# Fake gaze position with mouse pointer
def on_mouse_event(event, x, y, flags, param):
+ nonlocal gaze_positions_frequency
+ nonlocal gaze_analysis_time
+
+ # Assess gaze analysis
+ lap_time, nb_laps, elapsed_time = call_chrono.lap()
+
+ if elapsed_time > 1e3:
+
+ gaze_positions_frequency = nb_laps
+ call_chrono.restart()
+
+ gaze_analysis_time = 0
+
# Edit millisecond timestamp
timestamp = int((time.time() - start_time) * 1e3)
@@ -54,12 +75,20 @@ def main():
gaze_movement, scan_step_analysis, layer_analysis, execution_times, exception = look_data
- # Do something with look data
- # ...
+ # Assess gaze analysis
+ gaze_analysis_time += execution_times['total']
# Attach mouse callback to window
cv2.setMouseCallback(aruco_camera.name, on_mouse_event)
+ # Prepare video fps assessment
+ video_fps = 0
+ video_chrono = UtilsFeatures.TimeProbe()
+ video_chrono.start()
+
+ # Prepare visualisation time assessment
+ visualisation_time = 0
+
# Enable camera video capture into separate thread
video_capture = cv2.VideoCapture(int(args.source) if args.source.isdecimal() else args.source)
@@ -69,30 +98,48 @@ def main():
# Capture images
while video_capture.isOpened():
+ # Assess capture time
+ capture_start = time.time()
+
# Read video image
success, video_image = video_capture.read()
+ # Assess capture time
+ capture_time = int((time.time() - capture_start) * 1e3)
+
if success:
+ # Assess video fps
+ lap_time, nb_laps, elapsed_time = video_chrono.lap()
+
+ if elapsed_time > 1e3:
+
+ video_fps = nb_laps
+ video_chrono.restart()
+
# Detect and project AR features
- detection_time, exceptions = aruco_camera.watch(video_image)
+ detection_time, projection_time, exceptions = aruco_camera.watch(video_image)
+
+ # Assess visualisation time
+ visualisation_start = time.time()
# Get ArUcoCamera frame image
aruco_camera_image = aruco_camera.image()
- # Write detection fps
- cv2.rectangle(aruco_camera_image, (0, 0), (420, 50), (63, 63, 63), -1)
- cv2.putText(aruco_camera_image, f'Detection fps: {1e3/detection_time:.1f}', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ # Write time info
+ cv2.rectangle(aruco_camera_image, (0, 0), (aruco_camera.size[0], 100), (63, 63, 63), -1)
+ cv2.putText(aruco_camera_image, f'{video_fps} FPS | Capture {capture_time}ms | Detection {int(detection_time)}ms | Projection {int(projection_time)}ms | Visualisation {visualisation_time}ms', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(aruco_camera_image, f'{gaze_positions_frequency} gaze positions/s | Gaze analysis {gaze_analysis_time:.2f}ms', (20, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
# Handle exceptions
for i, (scene_name, e) in enumerate(exceptions.items()):
# Write errors
- cv2.rectangle(aruco_camera_image, (0, (i+1)*50), (720, (i+2)*50), (127, 127, 127), -1)
- cv2.putText(aruco_camera_image, f'{scene_name} error: {e}', (20, (i+1)*90), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.rectangle(aruco_camera_image, (0, (i+1)*100), (aruco_camera.size[0], (i+2)*80), (127, 127, 127), -1)
+ cv2.putText(aruco_camera_image, f'{scene_name} error: {e}', (20, (i+1)*140), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
# Write hint
- cv2.putText(aruco_camera_image, 'Mouve mouse pointer over gray rectangle area', (450, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(aruco_camera_image, 'Mouve mouse pointer over gray rectangle area', (20, aruco_camera.size[1]-40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
# Display ArUcoCamera frame image
cv2.imshow(aruco_camera.name, aruco_camera_image)
@@ -104,11 +151,15 @@ def main():
cv2.imshow(f'{scene_frame.parent.name}:{scene_frame.name}', scene_frame.image())
# Stop by pressing 'Esc' key
- if cv2.waitKey(10) == 27:
+ # NOTE: on MacOS, cv2.waitKey(1) waits ~40ms
+ if cv2.waitKey(1) == 27:
# Close camera video capture
video_capture.release()
+ # Assess visualisation time
+ visualisation_time = int((time.time() - visualisation_start) * 1e3)
+
# Stop image display
cv2.destroyAllWindows()