diff options
author | Théo de la Hogue | 2023-03-29 15:38:20 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-03-29 15:38:20 +0200 |
commit | 84a89d804180a816060fbd5b85bdb2342c6a1063 (patch) | |
tree | 6b0555fce89857fb8b14b43b5985b7d2032afc8a /src | |
parent | 2f1c506f1dd8c46571d53daf91534c60ccb8758f (diff) | |
download | argaze-84a89d804180a816060fbd5b85bdb2342c6a1063.zip argaze-84a89d804180a816060fbd5b85bdb2342c6a1063.tar.gz argaze-84a89d804180a816060fbd5b85bdb2342c6a1063.tar.bz2 argaze-84a89d804180a816060fbd5b85bdb2342c6a1063.tar.xz |
Adding mouse interaction to simulate gaze position.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/utils/demo_environment_run.py | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/argaze/utils/demo_environment_run.py b/src/argaze/utils/demo_environment_run.py index b2cd1e7..db21cbb 100644 --- a/src/argaze/utils/demo_environment_run.py +++ b/src/argaze/utils/demo_environment_run.py @@ -4,7 +4,7 @@ import argparse import os import time -from argaze import ArFeatures +from argaze import ArFeatures, GazeFeatures import cv2 @@ -28,31 +28,52 @@ def main(): # Access to main AR scene demo_scene = demo_environment.scenes["AR Scene Demo"] + # Create a window to display AR environment + cv2.namedWindow(demo_environment.name, cv2.WINDOW_AUTOSIZE) + + # Init mouse interaction + pointer = (0, 0) + + # Update pointer position + def on_mouse_event(event, x, y, flags, param): + + nonlocal pointer + + # Update pointer + pointer = (x, y) + + # Attach mouse callback to window + cv2.setMouseCallback(demo_environment.name, on_mouse_event) + # Enable camera video capture video_capture = cv2.VideoCapture(args.device) - # Capture loop + # Waiting for 'ctrl+C' interruption try: - # Capture frames with a full displayed board inside + # Capture frames while video_capture.isOpened(): success, video_frame = video_capture.read() if success: + # Draw pointer as gaze position + gaze_position = GazeFeatures.GazePosition(pointer, precision=10) + gaze_position.draw(video_frame) + # Detect markers demo_environment.aruco_detector.detect_markers(video_frame) # Draw detected markers demo_environment.aruco_detector.draw_detected_markers(video_frame) - # Process detected markers for Matsuri scene + # Try to project scene try: try: # Try to build AOI scene from detected ArUco marker corners - scene_projection = demo_scene.build_aruco_aoi_scene(demo_environment.aruco_detector.detected_markers) + aoi_scene_projection = demo_scene.build_aruco_aoi_scene(demo_environment.aruco_detector.detected_markers) except: @@ -63,10 +84,10 @@ def main(): tvec, rmat, _ = demo_scene.estimate_pose(demo_environment.aruco_detector.detected_markers) # Project AOI scene into frame according estimated pose - scene_projection = demo_scene.project(tvec, rmat) + aoi_scene_projection = demo_scene.project(tvec, rmat) - # Draw AOI - scene_projection.draw(video_frame, (0, 0), color=(0, 255, 255)) + # Draw AOI scene projection with gaze + aoi_scene_projection.draw_circlecast(video_frame, gaze_position) # Catch exceptions raised by estimate_pose and project methods except (ArFeatures.PoseEstimationFailed, ArFeatures.SceneProjectionFailed) as e: @@ -78,13 +99,16 @@ def main(): cv2.imshow(demo_environment.name, video_frame) # Stop calibration by pressing 'Esc' key - if cv2.waitKey(1) == 27: + if cv2.waitKey(10) == 27: break # Stop calibration on 'ctrl+C' interruption except KeyboardInterrupt: pass + # Close camera video capture + video_capture.release() + # Stop frame display cv2.destroyAllWindows() |