aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-06-26 11:00:01 +0200
committerThéo de la Hogue2024-06-26 11:00:01 +0200
commit9a461f8b585eae1fce67b0681bb990093b4384c1 (patch)
tree1ff48804d158d22083cefc191482e1c5c909ca9b
parent986c7e8d0b16f2b8e7f28824b3e1fbd5d5b2236e (diff)
downloadargaze-9a461f8b585eae1fce67b0681bb990093b4384c1.zip
argaze-9a461f8b585eae1fce67b0681bb990093b4384c1.tar.gz
argaze-9a461f8b585eae1fce67b0681bb990093b4384c1.tar.bz2
argaze-9a461f8b585eae1fce67b0681bb990093b4384c1.tar.xz
Fixing aruco marker export script.
-rw-r--r--src/argaze/ArUcoMarker/ArUcoDetector.py2
-rw-r--r--src/argaze/utils/aruco_marker_group_export.py49
2 files changed, 21 insertions, 30 deletions
diff --git a/src/argaze/ArUcoMarker/ArUcoDetector.py b/src/argaze/ArUcoMarker/ArUcoDetector.py
index 4a011d6..32a7f3f 100644
--- a/src/argaze/ArUcoMarker/ArUcoDetector.py
+++ b/src/argaze/ArUcoMarker/ArUcoDetector.py
@@ -193,7 +193,7 @@ class ArUcoDetector(DataFeatures.PipelineStepObject):
self.__detected_markers, detected_markers_corners, detected_markers_ids = {}, [], []
# Detect markers into gray picture
- detected_markers_corners, 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 if self.__parameters else None)
# Is there detected markers ?
if len(detected_markers_corners) > 0:
diff --git a/src/argaze/utils/aruco_marker_group_export.py b/src/argaze/utils/aruco_marker_group_export.py
index 5503747..47aba86 100644
--- a/src/argaze/utils/aruco_marker_group_export.py
+++ b/src/argaze/utils/aruco_marker_group_export.py
@@ -37,14 +37,11 @@ def main():
# Manage arguments
parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0])
parser.add_argument('movie', metavar='MOVIE', type=str, default=None, help='movie path')
- parser.add_argument('dictionary', metavar='DICTIONARY', type=str, default=None,
- help='expected ArUco markers dictionary')
+ parser.add_argument('dictionary', metavar='DICTIONARY', type=str, default=None, help='expected ArUco markers dictionary')
parser.add_argument('size', metavar='SIZE', type=float, default=None, help='expected ArUco markers size (in cm)')
- parser.add_argument('-p', '--parameters', metavar='PARAMETERS', type=str, default=None,
- help='ArUco detector parameters file')
- parser.add_argument('-op', '--optic_parameters', metavar='OPTIC_PARAMETERS', type=str, default=None,
- help='ArUco detector optic parameters file')
+ parser.add_argument('-p', '--parameters', metavar='PARAMETERS', type=str, default=None, help='ArUco detector parameters file')
+ parser.add_argument('-op', '--optic_parameters', metavar='OPTIC_PARAMETERS', type=str, default=None, help='ArUco detector optic parameters file')
parser.add_argument('-s', '--start', metavar='START', type=float, default=0., help='start time in second')
parser.add_argument('-o', '--output', metavar='OUTPUT', type=str, default='.', help='export folder path')
@@ -74,6 +71,12 @@ def main():
# Load ArUco detector configuration
aruco_detector = DataFeatures.from_dict(ArUcoDetector.ArUcoDetector, configuration)
+ # Create default optic parameters adapted to frame size
+ if aruco_detector.optic_parameters is None:
+
+ # Note: The choice of 1000 for default focal length should be discussed...
+ aruco_detector.optic_parameters = ArUcoOpticCalibrator.OpticParameters(rms=-1, dimensions=(image_width, image_height), K=ArUcoOpticCalibrator.K0(focal_length=(1000., 1000.), width=image_width, height=image_height))
+
if args.verbose:
print(aruco_detector)
@@ -111,13 +114,6 @@ def main():
video_height, video_width, _ = video_image.shape
- # Create default optic parameters adapted to frame size
- if aruco_detector.optic_parameters is None:
- # Note: The choice of 1000 for default focal length should be discussed...
- aruco_detector.optic_parameters = ArUcoOpticCalibrator.OpticParameters(rms=-1, dimensions=(
- video_width, video_height), K=ArUcoOpticCalibrator.K0(focal_length=(1000., 1000.),
- width=video_width, height=video_height))
-
if success:
# Refresh once
@@ -126,6 +122,9 @@ def main():
current_image_index = video_capture.get(cv2.CAP_PROP_POS_FRAMES) - 1
current_image_time = video_capture.get(cv2.CAP_PROP_POS_MSEC)
+ # Timestamp image
+ video_image = DataFeatures.TimestampedImage(video_image, timestamp=current_image_time)
+
try:
# Detect and project AR features
@@ -135,8 +134,7 @@ def main():
aruco_detector.estimate_markers_pose(args.size)
# Build aruco scene from detected markers
- aruco_markers_group = ArUcoMarkerGroup.ArUcoMarkerGroup(aruco_detector.dictionary,
- aruco_detector.detected_markers())
+ aruco_markers_group = ArUcoMarkerGroup.ArUcoMarkerGroup(dictionary=aruco_detector.dictionary, places=aruco_detector.detected_markers())
# Detection succeeded
exception = None
@@ -152,27 +150,20 @@ def main():
aruco_detector.draw_detected_markers(video_image, draw_parameters)
# Write detected markers
- cv2.putText(video_image, f'Detecting markers {list(aruco_detector.detected_markers().keys())}',
- (20, video_height - 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'Detecting markers {list(aruco_detector.detected_markers().keys())}', (20, video_height - 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
# Write timing
- cv2.putText(video_image, f'Frame at {int(current_image_time)}ms', (20, 40),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'Frame at {int(current_image_time)}ms', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
# Write exception
if exception is not None:
- cv2.putText(video_image, f'error: {exception}', (20, 80), cv2.FONT_HERSHEY_SIMPLEX, 1,
- (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'error: {exception}', (20, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
# Write documentation
- cv2.putText(video_image, f'<- previous image', (video_width - 500, video_height - 160),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
- cv2.putText(video_image, f'-> next image', (video_width - 500, video_height - 120),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
- cv2.putText(video_image, f'r: reload config', (video_width - 500, video_height - 80),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
- cv2.putText(video_image, f'Ctrl+s: export ArUco markers', (video_width - 500, video_height - 40),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'<- previous image', (video_width - 500, video_height - 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'-> next image', (video_width - 500, video_height - 120), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'r: reload config', (video_width - 500, video_height - 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
+ cv2.putText(video_image, f'Ctrl+s: export ArUco markers', (video_width - 500, video_height - 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA)
# Copy image
current_image = video_image.copy()