aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/ArUcoMarkers/ArUcoMarker.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze/ArUcoMarkers/ArUcoMarker.py')
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoMarker.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoMarker.py b/src/argaze/ArUcoMarkers/ArUcoMarker.py
index 3a13c10..57bd8bd 100644
--- a/src/argaze/ArUcoMarkers/ArUcoMarker.py
+++ b/src/argaze/ArUcoMarkers/ArUcoMarker.py
@@ -12,7 +12,7 @@ from dataclasses import dataclass, field
from argaze.ArUcoMarkers import ArUcoMarkersDictionary
import numpy
-import cv2 as cv
+import cv2
import cv2.aruco as aruco
@dataclass
@@ -40,9 +40,6 @@ class ArUcoMarker():
points: numpy.array = field(init=False, repr=False)
"""Estimated 3D corners positions in camera world referential."""
- color: tuple = field(init=False, repr=False, default_factory=lambda : (0, 255, 0))
- """Color used to draw marker on image."""
-
@property
def center(self) -> numpy.array:
"""Get 2D center position in camera image referential."""
@@ -59,15 +56,24 @@ class ArUcoMarker():
return numpy.repeat(matrix, 3).reshape(dimension, dimension, 3)
- def draw(self, image: numpy.array, K, D):
- """Draw marker in image."""
+ def draw(self, image: numpy.array, K, D, color: tuple = None, draw_axes: dict = None):
+ """Draw marker in image.
+
+ Parameters:
+ image: image where to draw
+ color: marker color (if None, no marker drawn)
+ draw_axes: enable marker axes drawing
+ """
+
+ # Draw marker if required
+ if color is not None:
- # Draw marker axis if pose has been estimated
- if self.translation.size == 3 and self.rotation.size == 9:
+ aruco.drawDetectedMarkers(image, [self.corners], numpy.array([self.identifier]), color)
- cv.drawFrameAxes(image, numpy.array(K), numpy.array(D), self.rotation, self.translation, self.size)
+ # Draw marker axes if pose has been estimated and if required
+ if self.translation.size == 3 and self.rotation.size == 9 and draw_axes is not None:
- aruco.drawDetectedMarkers(image, [self.corners], numpy.array([self.identifier]), self.color)
+ cv2.drawFrameAxes(image, numpy.array(K), numpy.array(D), self.rotation, self.translation, self.size, **draw_axes)
def save(self, destination_folder, dpi):
"""Save marker image as .png file into a destination folder."""
@@ -75,5 +81,5 @@ class ArUcoMarker():
filename = f'{self.dictionary.name}_{self.dictionary.format}_{self.identifier}.png'
filepath = f'{destination_folder}/{filename}'
- cv.imwrite(filepath, self.image(dpi))
+ cv2.imwrite(filepath, self.image(dpi))