aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoDetector.py46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoDetector.py b/src/argaze/ArUcoMarkers/ArUcoDetector.py
index 490b75b..3ef7fa6 100644
--- a/src/argaze/ArUcoMarkers/ArUcoDetector.py
+++ b/src/argaze/ArUcoMarkers/ArUcoDetector.py
@@ -149,8 +149,6 @@ class ArUcoDetector():
# Init detected markers data
self.__detected_markers = {}
- self.__detected_markers_corners = []
- self.__detected_markers_ids = []
# Init detected board data
self.__board = None
@@ -267,31 +265,31 @@ class ArUcoDetector():
"""
# Reset detected markers data
- self.__detected_markers, self.__detected_markers_corners, self.__detected_markers_ids = {}, [], []
+ self.__detected_markers, detected_markers_corners, detected_markers_ids = {}, [], []
# Store marker detection start date
detection_start = time.perf_counter()
# Detect markers into gray picture
- self.__detected_markers_corners, self.__detected_markers_ids, _ = aruco.detectMarkers(cv.cvtColor(image, cv.COLOR_BGR2GRAY), self.dictionary.markers, parameters = self.parameters.internal)
+ detected_markers_corners, detected_markers_ids, _ = aruco.detectMarkers(cv.cvtColor(image, cv.COLOR_BGR2GRAY), self.dictionary.markers, parameters = self.parameters.internal)
# Assess marker detection time in ms
detection_time = (time.perf_counter() - detection_start) * 1e3
# Is there detected markers ?
- if len(self.__detected_markers_corners) > 0:
+ if len(detected_markers_corners) > 0:
# Transform markers ids array into list
- self.__detected_markers_ids = self.__detected_markers_ids.T[0]
+ detected_markers_ids = detected_markers_ids.T[0]
# Gather detected markers data and update metrics
self.__detection_count += 1
- for i, marker_id in enumerate(self.__detected_markers_ids):
+ for i, marker_id in enumerate(detected_markers_ids):
marker = ArUcoMarker.ArUcoMarker(self.dictionary, marker_id, self.marker_size)
- marker.corners = self.__detected_markers_corners[i]
+ marker.corners = detected_markers_corners[i]
# No pose estimation: call estimate_markers_pose to get one
marker.translation = numpy.empty([0])
@@ -300,6 +298,7 @@ class ArUcoDetector():
self.__detected_markers[marker_id] = marker
+ # Update metrics
self.__detected_ids.append(marker_id)
return detection_time
@@ -308,26 +307,23 @@ class ArUcoDetector():
"""Estimate pose of current detected markers or of given markers id list."""
# Is there detected markers ?
- if len(self.__detected_markers_corners) > 0:
+ if len(self.__detected_markers) > 0:
- # Is there a marker selection ?
- if len(markers_ids) > 0:
+ # Select all markers by default
+ if len(markers_ids) == 0:
- selected_markers_corners = tuple()
- selected_markers_ids = []
+ markers_ids = self.__detected_markers.keys()
- for i, marker_id in enumerate(self.__detected_markers_ids):
+ # Prepare data for aruco.estimatePoseSingleMarkers function
+ selected_markers_corners = tuple()
+ selected_markers_ids = []
- if marker_id in markers_ids:
-
- selected_markers_corners += (self.__detected_markers_corners[i],)
- selected_markers_ids.append(marker_id)
+ for marker_id, marker in self.__detected_markers.items():
- # Otherwise, estimate pose of all markers
- else:
+ if marker_id in markers_ids:
- selected_markers_corners = self.__detected_markers_corners
- selected_markers_ids = self.__detected_markers_ids
+ selected_markers_corners += (marker.corners,)
+ selected_markers_ids.append(marker_id)
# Estimate pose of selected markers
if len(selected_markers_corners) > 0:
@@ -377,13 +373,13 @@ class ArUcoDetector():
# detect markers from gray picture
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
- self.__detected_markers_corners, self.__detected_markers_ids, _ = aruco.detectMarkers(gray, self.dictionary.markers, parameters = self.parameters.internal)
+ detected_markers_corners, detected_markers_ids, _ = aruco.detectMarkers(gray, self.dictionary.markers, parameters = self.parameters.internal)
# if all board markers are detected
- if len(self.__detected_markers_corners) == expected_markers_number:
+ if len(detected_markers_corners) == expected_markers_number:
self.__board = board
- self.__board_corners_number, self.__board_corners, self.__board_corners_ids = aruco.interpolateCornersCharuco(self.__detected_markers_corners, self.__detected_markers_ids, gray, self.__board.model)
+ self.__board_corners_number, self.__board_corners, self.__board_corners_ids = aruco.interpolateCornersCharuco(detected_markers_corners, detected_markers_ids, gray, self.__board.model)
else: