diff options
Diffstat (limited to 'src/argaze/RegionOfInterest/ROI3DScene.py')
-rw-r--r-- | src/argaze/RegionOfInterest/ROI3DScene.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/argaze/RegionOfInterest/ROI3DScene.py b/src/argaze/RegionOfInterest/ROI3DScene.py index cf55e63..683110c 100644 --- a/src/argaze/RegionOfInterest/ROI3DScene.py +++ b/src/argaze/RegionOfInterest/ROI3DScene.py @@ -3,11 +3,25 @@ import math import re +from argaze import DataStructures from argaze.RegionOfInterest import ROI2DScene import numpy import cv2 as cv -import matplotlib.path as mpath + +class ROI3D(DataStructures.DictObject): + """Define Region Of Interest 3D + ``` + { + 'name': str, + 'vertices': array of (x, y, z) tuples + } + ``` + """ + + def __init__(self, name, vertices): + + super().__init__(type(self).__name__, **{'name': name, 'vertices': vertices}) class ROI3DScene(list): """List of ROI3D dictionary. @@ -56,6 +70,7 @@ class ROI3DScene(list): # start parsing try: + roi3D_list = [] roi3D = {} vertices = [] faces = [] @@ -77,7 +92,7 @@ class ROI3DScene(list): # extract roi3D name elif key == 'name': - roi3D['NAME'] = str(match.group(1)) + roi3D['name'] = str(match.group(1)) # fill vertices array elif key == 'vertice': @@ -87,10 +102,10 @@ class ROI3DScene(list): # extract roi3D vertice id elif key == 'face': - roi3D['FACE'] = [int(i) for i in match.group(1).split()] + roi3D['face'] = [int(i) for i in match.group(1).split()] # store roi3D dict into scene array - self.append(roi3D) + roi3D_list.append(roi3D) # clear roi3D dict roi3D = {} @@ -101,9 +116,10 @@ class ROI3DScene(list): file.close() # retreive all roi3D vertices - for roi3D in self: - roi3D['VERTICES'] = [ vertices[i-1] for i in roi3D['FACE'] ] - roi3D.pop('FACE', None) + for roi3D in roi3D_list: + roi3D['vertices'] = [ vertices[i-1] for i in roi3D['face'] ] + roi3D.pop('face', None) + self.append(ROI3D(**roi3D)) except IOError: raise IOError(f'File not found: {obj_filepath}') @@ -124,17 +140,17 @@ class ROI3DScene(list): for roi3D in self: - vertices_3D = numpy.array(roi3D['VERTICES']).astype('float32') + vertices_3D = numpy.array(roi3D.vertices).astype('float32') vertices_2D, J = cv.projectPoints(vertices_3D, self.__rotation, self.__translation, K, D) vertices_2D = vertices_2D.astype('int').reshape((len(vertices_2D), 2)) roi2D = { - 'NAME': roi3D['NAME'], - 'VERTICES': vertices_2D, - 'POINTER_INSIDE': False + 'name': roi3D.name, + 'vertices': vertices_2D, + 'pointer': None } - roi2D_scene.append(roi2D) + roi2D_scene.append(ROI2DScene.ROI2D(**roi2D)) return roi2D_scene |