@@ -95,15 +95,15 @@ def oriented_bounding_box_numpy(points, tol=None):
9595 # also compute the axis aligned bounding box
9696 # and compare the areas of the two
9797
98- rect1 , area1 = minimum_area_rectangle_xy (points , return_size = True )
99-
10098 points = world_to_local_coordinates_numpy (frame , points )
99+ rect1 , area1 = minimum_area_rectangle_xy (points , return_size = True )
101100 rect2 = bounding_box (points )[:4 ]
102101 area2 = (rect2 [1 ][0 ] - rect2 [0 ][0 ]) * (rect2 [3 ][1 ] - rect2 [0 ][1 ])
103102
104103 if area1 < area2 :
105104 rect = [[pt [0 ], pt [1 ], 0.0 ] for pt in rect1 ]
106- bbox = rect + rect
105+ bbox = local_to_world_coordinates_numpy (frame , rect )
106+ bbox = vstack ((bbox , bbox )).tolist ()
107107 else :
108108 rect = [[pt [0 ], pt [1 ], 0.0 ] for pt in rect2 ]
109109 bbox = local_to_world_coordinates_numpy (frame , rect )
@@ -260,11 +260,12 @@ def minimum_area_rectangle_xy(points, return_size=False):
260260 p0 = points [simplex [0 ]]
261261 p1 = points [simplex [1 ]]
262262
263+ vn = xy - p0
264+
263265 # s direction
264266 s = p1 - p0
265267 sl = sum (s ** 2 ) ** 0.5
266268 su = s / sl
267- vn = xy - p0
268269 sc = (sum (vn * s , axis = 1 ) / sl ).reshape ((- 1 , 1 ))
269270 scmax = argmax (sc )
270271 scmin = argmin (sc )
@@ -277,7 +278,6 @@ def minimum_area_rectangle_xy(points, return_size=False):
277278 t = array ([- s [1 ], s [0 ]])
278279 tl = sum (t ** 2 ) ** 0.5
279280 tu = t / tl
280- vn = xy - p0
281281 tc = (sum (vn * t , axis = 1 ) / tl ).reshape ((- 1 , 1 ))
282282 tcmax = argmax (tc )
283283 tcmin = argmin (tc )
@@ -287,7 +287,7 @@ def minimum_area_rectangle_xy(points, return_size=False):
287287 h = tc [tcmax ] - tc [tcmin ]
288288 a = w * h
289289
290- # box corners
290+ # other box corners
291291 if dot (t , mean - p0 ) < 0 :
292292 b3 = b0 - h * tu
293293 b2 = b1 - h * tu
0 commit comments