aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/utils/demo_aruco_markers_run.py
diff options
context:
space:
mode:
authorThéo de la Hogue2024-01-24 00:19:05 +0100
committerThéo de la Hogue2024-01-24 00:19:05 +0100
commit75e2e040edee78139ea5e60e9dcf8962fa54cb7c (patch)
tree33928564a219396e79885481a032a7310248a1c2 /src/argaze/utils/demo_aruco_markers_run.py
parentd904b99cc969c977f911d36cfeb2279544c528e5 (diff)
downloadargaze-75e2e040edee78139ea5e60e9dcf8962fa54cb7c.zip
argaze-75e2e040edee78139ea5e60e9dcf8962fa54cb7c.tar.gz
argaze-75e2e040edee78139ea5e60e9dcf8962fa54cb7c.tar.bz2
argaze-75e2e040edee78139ea5e60e9dcf8962fa54cb7c.tar.xz
Making look method as analysis iterator.
Diffstat (limited to 'src/argaze/utils/demo_aruco_markers_run.py')
-rw-r--r--src/argaze/utils/demo_aruco_markers_run.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/argaze/utils/demo_aruco_markers_run.py b/src/argaze/utils/demo_aruco_markers_run.py
index a0d044c..091b1e1 100644
--- a/src/argaze/utils/demo_aruco_markers_run.py
+++ b/src/argaze/utils/demo_aruco_markers_run.py
@@ -65,11 +65,19 @@ def main():
# Edit millisecond timestamp
timestamp = int((time.time() - start_time) * 1e3)
- # Project gaze position into camera
- aruco_camera.look(timestamp, GazeFeatures.GazePosition((x, y))):
+ try:
- # Assess gaze analysis
- gaze_analysis_time = aruco_camera.execution_times['look']
+ # Project gaze position into camera
+ for _ in aruco_camera.look(timestamp, GazeFeatures.GazePosition((x, y))):
+
+ pass
+
+ # Assess gaze analysis
+ gaze_analysis_time = aruco_camera.execution_times['look']
+
+ except Exception as e:
+
+ gaze_analysis_time = 0
# Attach mouse callback to window
cv2.setMouseCallback(aruco_camera.name, on_mouse_event)
@@ -88,12 +96,12 @@ def main():
# Waiting for 'ctrl+C' interruption
with contextlib.suppress(KeyboardInterrupt):
+ # Assess capture time
+ capture_start = time.time()
+
# Capture images
while video_capture.isOpened():
- # Assess capture time
- capture_start = time.time()
-
# Read video image
success, video_image = video_capture.read()
@@ -110,8 +118,17 @@ def main():
video_fps = nb_laps
video_chrono.restart()
- # Detect and project AR features
- detection_time, projection_time, exceptions = aruco_camera.watch(capture_time, video_image)
+ try:
+
+ # Detect and project AR features
+ aruco_camera.watch(capture_time, video_image)
+
+ exception = None
+
+ # Write errors
+ except Exception as e:
+
+ exception = e
# Assess visualisation time
visualisation_start = time.time()
@@ -119,17 +136,18 @@ def main():
# Get ArUcoCamera frame image
aruco_camera_image = aruco_camera.image()
+ # Get execution times
+ detection_time = aruco_camera.aruco_detector.execution_times['detect_markers']
+ projection_time = aruco_camera.execution_times['watch'] - detection_time
+
# 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)*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)
+ cv2.rectangle(aruco_camera_image, (0, 100), (aruco_camera.size[0], 80), (127, 127, 127), -1)
+ cv2.putText(aruco_camera_image, f'error: {exception}', (20, 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', (20, aruco_camera.size[1]-40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)