aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/utils/environment_edit.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/argaze/utils/environment_edit.py b/src/argaze/utils/environment_edit.py
index 7b6c2fd..fc17f37 100644
--- a/src/argaze/utils/environment_edit.py
+++ b/src/argaze/utils/environment_edit.py
@@ -32,7 +32,7 @@ def main():
parser.add_argument('environment', metavar='ENVIRONMENT', type=str, help='ar environment filepath')
parser.add_argument('movie', metavar='MOVIE', type=str, default=None, help='movie path')
parser.add_argument('-s','--start', metavar='START', type=float, default=0., help='start time in second')
- parser.add_argument('-o', '--output', metavar='OUT', type=str, default='environment.json', help='edited ar environment file path')
+ parser.add_argument('-o', '--output', metavar='OUT', type=str, default='edited_environment.json', help='edited ar environment file path')
args = parser.parse_args()
# Load AR enviroment
@@ -113,6 +113,7 @@ def main():
refresh = False
# Init marker selection
+ scene_markers = {}
selected_marker_id = -1
hovered_marker_id = -1
@@ -151,11 +152,14 @@ def main():
# Detect markers
ar_environment.aruco_detector.detect_markers(video_frame)
- # Estimate all marker's pose
- ar_environment.aruco_detector.estimate_markers_pose()
+ # Filter scene markers
+ scene_markers, _ = ar_scene.aruco_scene.filter_markers(ar_environment.aruco_detector.detected_markers)
- # Write detected markers
- cv2.putText(video_frame, f'{list(ar_environment.aruco_detector.detected_markers.keys())}', (20, frame_height-80), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ # Estimate scene marker's pose
+ ar_environment.aruco_detector.estimate_markers_pose(scene_markers.keys())
+
+ # Write scene detected markers
+ cv2.putText(video_frame, f'{list(scene_markers.keys())}', (20, frame_height-80), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
# Draw gray panel on top
cv2.rectangle(video_frame, (0, 0), (frame_width, 50), (63, 63, 63), -1)
@@ -177,13 +181,13 @@ def main():
video_frame = current_frame.copy()
- # Handle marker selection on left click
- if len(ar_environment.aruco_detector.detected_markers) > 0:
+ # Handle scene marker selection on left click
+ if len(scene_markers) > 0:
# Update selected and hovered markers id
selected_marker_id = -1
hovered_marker_id = -1
- for (marker_id, marker) in ar_environment.aruco_detector.detected_markers.items():
+ for (marker_id, marker) in scene_markers.items():
marker_aoi = marker.corners.reshape(4, 2).view(AOIFeatures.AreaOfInterest)
@@ -200,7 +204,7 @@ def main():
# Edit marker's color
color_list = list(itertools.permutations([0, 255, 255]))
- for i, m in ar_environment.aruco_detector.detected_markers.items():
+ for i, m in scene_markers.items():
m.color = color_list[i%len(color_list)]
@@ -223,7 +227,7 @@ def main():
try:
# Retreive selected marker
- selected_marker = ar_environment.aruco_detector.detected_markers[selected_marker_id]
+ selected_marker = scene_markers[selected_marker_id]
# Write selected marker id
cv2.rectangle(info_frame, (0, 0), (500, 50), selected_marker.color, -1)
@@ -285,7 +289,7 @@ def main():
if hovered_marker_id >= 0 and hovered_marker_id != selected_marker_id:
# Retreive hovered marker
- hovered_marker = ar_environment.aruco_detector.detected_markers[hovered_marker_id]
+ hovered_marker = scene_markers[hovered_marker_id]
# Write hovered marker id
cv2.rectangle(info_frame, (500, 0), (1000, 50), hovered_marker.color, -1)
@@ -421,7 +425,7 @@ def main():
# Estimate scene pose from each marker
cv2.putText(video_frame, f'Single marker scene pose estimation', (20, frame_height - 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
- for i, m in ar_environment.aruco_detector.detected_markers.items():
+ for i, m in scene_markers.items():
tvec, rmat = ar_scene.aruco_scene.estimate_pose_from_single_marker(m)
@@ -431,7 +435,7 @@ def main():
if i == selected_marker_id:
# Draw AOI scene projection with gaze
- aoi_scene_projection.draw_circlecast(video_frame, gaze_position, base_color=m.color, looked_color=(255, 255, 255))
+ aoi_scene_projection.draw_circlecast(video_frame, gaze_position, 1, base_color=m.color, matching_color=(255, 255, 255))
else:
@@ -450,17 +454,17 @@ def main():
else:
cv2.putText(info_frame, f'Left click on marker to select it', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
-
- if len(ar_environment.aruco_detector.detected_markers) > 1:
+
+ if len(scene_markers) > 1:
# Check markers consistency
- consistent_markers, unconsistent_markers, unconsistencies = ar_scene.aruco_scene.check_markers_consistency(ar_environment.aruco_detector.detected_markers, ar_scene.angle_tolerance, ar_scene.distance_tolerance)
+ consistent_markers, unconsistent_markers, unconsistencies = ar_scene.aruco_scene.check_markers_consistency(scene_markers, ar_scene.angle_tolerance, ar_scene.distance_tolerance)
# No marker hovered
if hovered_marker_id < 0:
# Set unconsistent marker color to red
- for i, m in ar_environment.aruco_detector.detected_markers.items():
+ for i, m in scene_markers.items():
if i in list(unconsistent_markers.keys()) and i != hovered_marker_id:
m.color = (0, 0, 255)
@@ -498,7 +502,7 @@ def main():
cv2.putText(video_frame, f'Single marker scene pose estimation', (20, frame_height - 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
- for i, m in ar_environment.aruco_detector.detected_markers.items():
+ for i, m in scene_markers.items():
tvec, rmat = ar_scene.aruco_scene.estimate_pose_from_single_marker(m)
@@ -531,9 +535,9 @@ def main():
try:
- origin_marker = ar_environment.aruco_detector.detected_markers[axis_markers['origin_marker']]
- horizontal_axis_marker = ar_environment.aruco_detector.detected_markers[axis_markers['horizontal_axis_marker']]
- vertical_axis_marker = ar_environment.aruco_detector.detected_markers[axis_markers['vertical_axis_marker']]
+ origin_marker = scene_markers[axis_markers['origin_marker']]
+ horizontal_axis_marker = scene_markers[axis_markers['horizontal_axis_marker']]
+ vertical_axis_marker = scene_markers[axis_markers['vertical_axis_marker']]
tvec, rmat = ar_scene.aruco_scene.estimate_pose_from_axis_markers(origin_marker, horizontal_axis_marker, vertical_axis_marker)
@@ -557,7 +561,7 @@ def main():
try :
# Try to build AOI scene from detected ArUco marker corners
- aoi_scene_projection = ar_scene.build_aruco_aoi_scene(ar_environment.aruco_detector.detected_markers)
+ aoi_scene_projection = ar_scene.build_aruco_aoi_scene(scene_markers)
# Draw AOI scene
aoi_scene_projection.draw(video_frame, color=(255, 255, 255))