diff options
Diffstat (limited to 'src/argaze/AreaOfInterest/AOI2DScene.py')
-rw-r--r-- | src/argaze/AreaOfInterest/AOI2DScene.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/argaze/AreaOfInterest/AOI2DScene.py b/src/argaze/AreaOfInterest/AOI2DScene.py index 8283e2e..2c8f003 100644 --- a/src/argaze/AreaOfInterest/AOI2DScene.py +++ b/src/argaze/AreaOfInterest/AOI2DScene.py @@ -25,6 +25,7 @@ import cv2 import numpy from xml.dom import minidom + class AOI2DScene(AOIFeatures.AOIScene): """Define AOI 2D scene.""" @@ -53,12 +54,11 @@ class AOI2DScene(AOIFeatures.AOIScene): # Load SVG path for path in description_file.getElementsByTagName('path'): - # Convert d-string into array d_string = path.getAttribute('d') - assert(d_string[0] == 'M') - assert(d_string[-1] == 'Z') + assert (d_string[0] == 'M') + assert (d_string[-1] == 'Z') points = [(float(x), float(y)) for x, y in [p.split(',') for p in d_string[1:-1].split('L')]] @@ -66,7 +66,6 @@ class AOI2DScene(AOIFeatures.AOIScene): # Load SVG rect for rect in description_file.getElementsByTagName('rect'): - # Convert rect element into dict rect_dict = { "Rectangle": { @@ -81,7 +80,6 @@ class AOI2DScene(AOIFeatures.AOIScene): # Load SVG circle for circle in description_file.getElementsByTagName('circle'): - # Convert circle element into dict circle_dict = { "Circle": { @@ -95,7 +93,6 @@ class AOI2DScene(AOIFeatures.AOIScene): # Load SVG ellipse for ellipse in description_file.getElementsByTagName('ellipse'): - # Convert ellipse element into dict ellipse_dict = { "Ellipse": { @@ -130,7 +127,7 @@ class AOI2DScene(AOIFeatures.AOIScene): if draw_aoi: aoi.draw(image, **draw_aoi) - def raycast(self, pointer:tuple) -> tuple[str, "AOIFeatures.AreaOfInterest", bool]: + def raycast(self, pointer: tuple) -> tuple[str, "AOIFeatures.AreaOfInterest", bool]: """Iterate over aoi to know which aoi is matching the given pointer position. Returns: aoi name @@ -139,30 +136,31 @@ class AOI2DScene(AOIFeatures.AOIScene): """ for name, aoi in self.items(): - matching = aoi.contains_point(pointer) yield name, aoi, matching - def draw_raycast(self, image: numpy.array, pointer:tuple, exclude=[], base_color=(0, 0, 255), matching_color=(0, 255, 0)): + def draw_raycast(self, image: numpy.array, pointer: tuple, exclude=[], base_color=(0, 0, 255), + matching_color=(0, 255, 0)): """Draw AOI with their matching status.""" for name, aoi, matching in self.raycast(pointer): if name in exclude: continue - + color = matching_color if matching else base_color if matching: - top_left_corner_pixel = numpy.rint(aoi.clockwise()[0]).astype(int) - cv2.putText(image, name, top_left_corner_pixel, cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) + cv2.putText(image, name, top_left_corner_pixel, cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, + cv2.LINE_AA) # Draw form aoi.draw(image, color) - def circlecast(self, center:tuple, radius:float) -> tuple[str, "AOIFeatures.AreaOfInterest", numpy.array, float, float]: + def circlecast(self, center: tuple, radius: float) -> tuple[ + str, "AOIFeatures.AreaOfInterest", numpy.array, float, float]: """Iterate over areas to know which aoi is matched circle. Returns: aoi name @@ -173,7 +171,6 @@ class AOI2DScene(AOIFeatures.AOIScene): """ for name, aoi in self.items(): - matched_region, aoi_ratio, circle_ratio = aoi.circle_intersection(center, radius) yield name, aoi, matched_region, aoi_ratio, circle_ratio @@ -211,6 +208,7 @@ class AOI2DScene(AOIFeatures.AOIScene): return aoi2D_scene ''' + def dimensionalize(self, rectangle_3d: AOIFeatures.AreaOfInterest, size: tuple) -> AOI3DScene.AOI3DScene: """ Convert to 3D scene considering it is inside of 3D rectangular frame. @@ -223,8 +221,8 @@ class AOI2DScene(AOIFeatures.AOIScene): AOI 3D scene """ - assert(rectangle_3d.dimension == 3) - assert(rectangle_3d.points_number == 4) + assert (rectangle_3d.dimension == 3) + assert (rectangle_3d.points_number == 4) # Vectorize outter_axis function vfunc = numpy.vectorize(rectangle_3d.outter_axis) @@ -233,7 +231,6 @@ class AOI2DScene(AOIFeatures.AOIScene): aoi3D_scene = AOI3DScene.AOI3DScene() for name, aoi2D in self.items(): - X, Y = (aoi2D / size).T aoi3D_scene[name] = numpy.array(vfunc(X, Y)).T.view(AOIFeatures.AreaOfInterest) |