aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoScene.py49
1 files changed, 44 insertions, 5 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoScene.py b/src/argaze/ArUcoMarkers/ArUcoScene.py
index 85c3fbf..3783660 100644
--- a/src/argaze/ArUcoMarkers/ArUcoScene.py
+++ b/src/argaze/ArUcoMarkers/ArUcoScene.py
@@ -113,7 +113,7 @@ class ArUcoScene():
# Normalize places data
new_places = {}
- for identifier, place in self.places.items():
+ for identifier, data in self.places.items():
# Convert string identifier to int value
if type(identifier) == str:
@@ -121,10 +121,10 @@ class ArUcoScene():
identifier = int(identifier)
# Get translation vector
- tvec = numpy.array(place.pop('translation')).astype(numpy.float32)
+ tvec = numpy.array(data.pop('translation')).astype(numpy.float32)
# Check rotation value shape
- rvalue = numpy.array(place.pop('rotation')).astype(numpy.float32)
+ rvalue = numpy.array(data.pop('rotation')).astype(numpy.float32)
# Rotation matrix
if rvalue.shape == (3, 3):
@@ -146,10 +146,15 @@ class ArUcoScene():
new_places[identifier] = Place(tvec, rmat, new_marker)
+ # else places are configured using detected markers
+ elif isinstance(data, ArUcoMarker.ArUcoMarker):
+
+ new_places[identifier] = Place(data.translation, data.rotation, data)
+
# else places are already at expected format
- elif (type(identifier) == int) and isinstance(place, Place):
+ elif (type(identifier) == int) and isinstance(data, Place):
- new_places[identifier] = place
+ new_places[identifier] = data
self.places = new_places
@@ -676,3 +681,37 @@ class ArUcoScene():
# Ignore errors due to out of field places: their coordinate are larger than int32 limitations.
except cv.error:
pass
+
+ def to_obj(self, obj_filepath):
+ """Save ArUco scene to .obj file."""
+
+ with open(obj_filepath, 'w', encoding='utf-8') as file:
+
+ file.write('# ArGaze OBJ File\n')
+ file.write('# http://achil.recherche.enac.fr/features/eye/argaze/\n')
+
+ v_count = 0
+
+ for identifier, place in self.places.items():
+
+ file.write(f'o {self.dictionary.name}#{identifier}_Marker\n')
+
+ vertices = ''
+
+ T = place.translation
+ R = place.rotation
+
+ points = (T + numpy.float32([R.dot(place.marker.points[0]), R.dot(place.marker.points[1]), R.dot(place.marker.points[2]), R.dot(place.marker.points[3])])).reshape(-1, 3)
+
+ print(points)
+
+ # Write vertices in reverse order
+ for i in [3, 2, 1, 0]:
+
+ file.write(f'v {" ".join(map(str, points[i]))}\n')
+ v_count += 1
+
+ vertices += f' {v_count}'
+
+ file.write('s off\n')
+ file.write(f'f{vertices}\n')