aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoDetector.py64
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/detector.json40
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/detector_parameters.json (renamed from src/argaze.test/ArUcoMarkers/utils/tracker.json)0
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoDetector.py41
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoMarker.py2
5 files changed, 119 insertions, 28 deletions
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoDetector.py b/src/argaze.test/ArUcoMarkers/ArUcoDetector.py
index ab29024..3272f1c 100644
--- a/src/argaze.test/ArUcoMarkers/ArUcoDetector.py
+++ b/src/argaze.test/ArUcoMarkers/ArUcoDetector.py
@@ -9,28 +9,28 @@ from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoDetect
import cv2 as cv
import numpy
-class TestDetectionParametersClass(unittest.TestCase):
- """Test DetectionParameters class."""
+class TestDetectorParametersClass(unittest.TestCase):
+ """Test DetectorParameters class."""
def test_from_json(self):
- """Test DetectionParameters creation from json file."""
+ """Test DetectorParameters creation from json file."""
- # Edit traking data file path
+ # Edit file path
current_directory = os.path.dirname(os.path.abspath(__file__))
- json_filepath = os.path.join(current_directory, 'utils/detecter.json')
+ json_filepath = os.path.join(current_directory, 'utils/detector_parameters.json')
- # Load project
- detection_parameters = ArUcoDetector.DetectionParameters.from_json(json_filepath)
+ # Load file
+ detector_parameters = ArUcoDetector.DetectorParameters.from_json(json_filepath)
# Check data
- self.assertEqual(detection_parameters.cornerRefinementMethod, 3)
- self.assertEqual(detection_parameters.aprilTagQuadSigma, 2)
- self.assertEqual(detection_parameters.aprilTagDeglitch, 1)
+ self.assertEqual(detector_parameters.cornerRefinementMethod, 3)
+ self.assertEqual(detector_parameters.aprilTagQuadSigma, 2)
+ self.assertEqual(detector_parameters.aprilTagDeglitch, 1)
# Check bad data access fails
with self.assertRaises(AttributeError):
- detection_parameters.unknown_data = 1
+ detector_parameters.unknown_data = 1
class TestArUcoDetectorClass(unittest.TestCase):
"""Test ArUcoDetector class."""
@@ -38,31 +38,46 @@ class TestArUcoDetectorClass(unittest.TestCase):
def test_new(self):
"""Test ArUcoDetector creation."""
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+ aruco_detector = ArUcoDetector.ArUcoDetector(marker_size=3)
# Check ArUcoDetector creation
+ self.assertEqual(aruco_detector.dictionary.name, 'DICT_ARUCO_ORIGINAL')
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_detector.camera.dimensions, [0, 0]))
self.assertEqual(aruco_detector.detected_markers_number, 0)
self.assertEqual(aruco_detector.detected_markers, {})
+ def test_from_json(self):
+ """Test ArUcoDetector creation."""
+
+ # Edit file path
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ json_filepath = os.path.join(current_directory, 'utils/detector.json')
+
+ # Load file
+ aruco_detector = ArUcoDetector.ArUcoDetector.from_json(json_filepath)
+
+ # Check ArUcoDetector creation
+ self.assertEqual(aruco_detector.dictionary.name, 'DICT_ARUCO_ORIGINAL')
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_detector.camera.dimensions, [1920, 1080]))
+ self.assertEqual(aruco_detector.parameters.cornerRefinementMethod, 3)
+ self.assertEqual(aruco_detector.parameters.aprilTagQuadSigma, 2)
+ self.assertEqual(aruco_detector.parameters.aprilTagDeglitch, 1)
+
def test_detect(self):
"""Test detect method."""
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+ aruco_detector = ArUcoDetector.ArUcoDetector(marker_size=3)
# Load picture Full HD to test ArUcoMarker detection
current_directory = os.path.dirname(os.path.abspath(__file__))
frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_marker.png'))
# Check ArUcoMarker detection
- aruco_detector.detect(frame)
+ aruco_detector.detect_markers(frame)
self.assertEqual(aruco_detector.detected_markers_number, 1)
- self.assertEqual(aruco_detector.detected_markers[0].dictionary, aruco_dictionary)
+ self.assertEqual(aruco_detector.detected_markers[0].dictionary, aruco_detector.dictionary)
self.assertEqual(aruco_detector.detected_markers[0].identifier, 0)
self.assertEqual(aruco_detector.detected_markers[0].size, 3)
@@ -72,9 +87,12 @@ class TestArUcoDetectorClass(unittest.TestCase):
self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][2].astype(int), numpy.array([4177, 2427]), decimal=-1))
self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][3].astype(int), numpy.array([3823, 2427]), decimal=-1))
+ # Check marker pose estimation
+ aruco_detector.estimate_markers_pose([0])
+
# Check marker translation with -/+ 0.1 cm precision and rotation with -/+ 0.001 radian precision
self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].translation, numpy.array([33.87, 19.05, 0.]), decimal=1))
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].rotation, numpy.array([math.pi, 0., 0.]), decimal=3))
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].rotation, numpy.array([[1., 0., 0.], [0., -1., 0.], [0., 0., -1.]]), decimal=3))
# Check detect metrics
detect_count, markers_count = aruco_detector.detection_metrics
@@ -84,10 +102,8 @@ class TestArUcoDetectorClass(unittest.TestCase):
def test_detect_board(self):
"""Test detect board method."""
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_board = ArUcoBoard.ArUcoBoard(aruco_dictionary, 7, 5, 5, 3)
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+ aruco_board = ArUcoBoard.ArUcoBoard(7, 5, 5, 3)
+ aruco_detector = ArUcoDetector.ArUcoDetector(marker_size=3)
# Load picture Full HD to test ArUcoMarker board detection
current_directory = os.path.dirname(os.path.abspath(__file__))
diff --git a/src/argaze.test/ArUcoMarkers/utils/detector.json b/src/argaze.test/ArUcoMarkers/utils/detector.json
new file mode 100644
index 0000000..a8350f3
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/utils/detector.json
@@ -0,0 +1,40 @@
+{
+ "dictionary": "DICT_ARUCO_ORIGINAL",
+ "marker_size": 3.0,
+ "camera": {
+ "rms": 1.0,
+ "dimensions": [
+ 1920,
+ 1080
+ ],
+ "K": [
+ [
+ 1.0,
+ 0.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 1.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 0.0,
+ 1.0
+ ]
+ ],
+ "D": [
+ -1.0,
+ -0.5,
+ 0.0,
+ 0.5,
+ 1.0
+ ]
+ },
+ "parameters": {
+ "cornerRefinementMethod": 3,
+ "aprilTagQuadSigma": 2,
+ "aprilTagDeglitch": 1
+ }
+} \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/utils/tracker.json b/src/argaze.test/ArUcoMarkers/utils/detector_parameters.json
index d26a3fa..d26a3fa 100644
--- a/src/argaze.test/ArUcoMarkers/utils/tracker.json
+++ b/src/argaze.test/ArUcoMarkers/utils/detector_parameters.json
diff --git a/src/argaze/ArUcoMarkers/ArUcoDetector.py b/src/argaze/ArUcoMarkers/ArUcoDetector.py
index 0ce1753..3ebd442 100644
--- a/src/argaze/ArUcoMarkers/ArUcoDetector.py
+++ b/src/argaze/ArUcoMarkers/ArUcoDetector.py
@@ -124,12 +124,47 @@ class ArUcoDetector():
def __init__(self, **kwargs):
- self.dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(kwargs.pop('dictionary'))
+ # Handle dictionary str or instance
+ try:
+ dictionary_value = kwargs.pop('dictionary')
+
+ if type(dictionary_value) == str:
+ self.dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(dictionary_value)
+ elif isinstance(dictionary_value, ArUcoMarkersDictionary.ArUcoMarkersDictionary):
+ self.dictionary = dictionary_value
+ else:
+ raise ValueError(f'dictionary: {dictionary_value}')
+
+ except KeyError:
+
+ self.dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary()
+
+ # Handle camera dict or instance
+ try:
+ camera_value = kwargs.pop('camera')
+
+ if type(camera_value) == dict:
+ self.camera = ArUcoCamera.ArUcoCamera(**camera_value)
+ elif isinstance(camera_value, ArUcoCamera.ArUcoCamera):
+ self.camera = camera_value
+ else:
+ raise ValueError(f'camera: {camera_value}')
+
+ except KeyError:
+
+ self.camera = ArUcoCamera.ArUcoCamera()
+
+ # Init marker size
self.marker_size = kwargs.pop('marker_size')
- self.camera = ArUcoCamera.ArUcoCamera(**kwargs.pop('camera'))
# Init detector parameters
- self.__parameters = DetectorParameters(**kwargs.pop('parameters'))
+ try:
+
+ self.__parameters = DetectorParameters(**kwargs.pop('parameters'))
+
+ except KeyError:
+
+ self.__parameters = DetectorParameters()
# Init detected markers data
self.__detected_markers = {}
diff --git a/src/argaze/ArUcoMarkers/ArUcoMarker.py b/src/argaze/ArUcoMarkers/ArUcoMarker.py
index 8f7538d..f41810b 100644
--- a/src/argaze/ArUcoMarkers/ArUcoMarker.py
+++ b/src/argaze/ArUcoMarkers/ArUcoMarker.py
@@ -60,7 +60,7 @@ class ArUcoMarker():
aruco.drawDetectedMarkers(frame, [self.corners], numpy.array([self.identifier]))
def save(self, destination_folder, dpi):
- """Save marker image as .png file."""
+ """Save marker image as .png file into a destination folder."""
filename = f'{self.dictionary.name}_{self.dictionary.format}_{self.identifier}.png'
filepath = f'{destination_folder}/{filename}'