aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/utils/demo_ar_features_run.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/argaze/utils/demo_ar_features_run.py b/src/argaze/utils/demo_ar_features_run.py
index 4619e80..0fa275b 100644
--- a/src/argaze/utils/demo_ar_features_run.py
+++ b/src/argaze/utils/demo_ar_features_run.py
@@ -13,6 +13,7 @@ import os
from argaze import ArFeatures, GazeFeatures
import cv2
+import numpy
def main():
"""
@@ -38,6 +39,27 @@ def main():
# Create a window to display AR environment
cv2.namedWindow(demo_environment.name, cv2.WINDOW_AUTOSIZE)
+ # Prepare screen AOI projection
+ screen_name = "Screen"
+ screen_size = (320, 240)
+
+ # Create a window to display screen projection
+ cv2.namedWindow(screen_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)
@@ -51,13 +73,16 @@ def main():
if success:
+ # Create screen frame
+ screen_frame = numpy.zeros((240, 320, 3)).astype(numpy.uint8)
+
# Detect markers
demo_environment.aruco_detector.detect_markers(video_frame)
# Draw detected markers
demo_environment.aruco_detector.draw_detected_markers(video_frame)
- # Try to project scene
+ # Try to project scene
try:
try:
@@ -72,21 +97,30 @@ def main():
# Estimate scene pose from detected scene markers
tvec, rmat, _, _ = demo_scene.estimate_pose(demo_environment.aruco_detector.detected_markers)
- # Project AOI scene into frame according estimated pose
+ # Project AOI scene into video frame according estimated pose
aoi_scene_projection = demo_scene.project(tvec, rmat)
# Draw AOI scene projection
aoi_scene_projection.draw(video_frame, color=(255, 255, 255))
+ # Reframe AOI scene to screen AOI
+ screen_projection = aoi_scene_projection.reframe("Screen", screen_size)
+
+ # Draw screen projection
+ screen_projection.draw(screen_frame, color=(255, 255, 255))
+
# Catch exceptions raised by estimate_pose and project methods
except (ArFeatures.PoseEstimationFailed, ArFeatures.SceneProjectionFailed) as e:
cv2.rectangle(video_frame, (0, 50), (700, 100), (127, 127, 127), -1)
cv2.putText(video_frame, f'Error: {e}', (20, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
- # Draw frame
+ # Draw video frame
cv2.imshow(demo_environment.name, video_frame)
+ # Draw screen frame
+ cv2.imshow(screen_name, screen_frame)
+
# Stop calibration by pressing 'Esc' key
if cv2.waitKey(10) == 27:
break