generated from dopt-python/py311
small rework on type annotations
This commit is contained in:
parent
67e49a47d8
commit
85effb25b0
@ -31,14 +31,17 @@ pixels_per_metric_Y: float = 0.251
|
|||||||
|
|
||||||
|
|
||||||
# measuring
|
# measuring
|
||||||
def midpoint(pt_A: npt.NDArray, pt_B: npt.NDArray) -> tuple[float, float]:
|
def midpoint(
|
||||||
|
pt_A: npt.NDArray[np.floating],
|
||||||
|
pt_B: npt.NDArray[np.floating],
|
||||||
|
) -> tuple[float, float]:
|
||||||
"""to identify the midpoint of a 2D area
|
"""to identify the midpoint of a 2D area
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
pt_A : npt.NDArray
|
pt_A : npt.NDArray[np.floating]
|
||||||
tuple of coordinates x, y; shape (2, )
|
tuple of coordinates x, y; shape (2, )
|
||||||
pt_B : npt.NDArray
|
pt_B : npt.NDArray[np.floating]
|
||||||
tuple of coordinates x, y; shape (2, )
|
tuple of coordinates x, y; shape (2, )
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
@ -50,17 +53,17 @@ def midpoint(pt_A: npt.NDArray, pt_B: npt.NDArray) -> tuple[float, float]:
|
|||||||
|
|
||||||
|
|
||||||
def check_box_redundancy(
|
def check_box_redundancy(
|
||||||
box1: t.Box,
|
box_1: t.Box,
|
||||||
box2: t.Box,
|
box_2: t.Box,
|
||||||
tolerance: float = 5.0,
|
tolerance: float = 5.0,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""to check if bounding box has already been identified and is just a redundant one
|
"""to check if bounding box has already been identified and is just a redundant one
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
box1 : t.Box
|
box_1 : t.Box
|
||||||
tuple of box values: ((center_x, center_y), (width, height), angle)
|
tuple of box values: ((center_x, center_y), (width, height), angle)
|
||||||
box2 : t.Box
|
box_2 : t.Box
|
||||||
tuple of box values: ((center_x, center_y), (width, height), angle)
|
tuple of box values: ((center_x, center_y), (width, height), angle)
|
||||||
tolerance : float, optional
|
tolerance : float, optional
|
||||||
distance threshold for width and height, by default 5.0
|
distance threshold for width and height, by default 5.0
|
||||||
@ -71,8 +74,8 @@ def check_box_redundancy(
|
|||||||
redundancy evaluation
|
redundancy evaluation
|
||||||
"""
|
"""
|
||||||
# unpack the boxes
|
# unpack the boxes
|
||||||
c1, s1, _ = box1
|
c1, s1, _ = box_1
|
||||||
c2, s2, _ = box2
|
c2, s2, _ = box_2
|
||||||
# sort width and height such that (w, h) == (h, w) is treated the same
|
# sort width and height such that (w, h) == (h, w) is treated the same
|
||||||
# (might have been recognized in different orders)
|
# (might have been recognized in different orders)
|
||||||
s1 = sorted(s1)
|
s1 = sorted(s1)
|
||||||
@ -81,7 +84,7 @@ def check_box_redundancy(
|
|||||||
center_dist = cast(float, np.linalg.norm(np.array(c1) - np.array(c2)))
|
center_dist = cast(float, np.linalg.norm(np.array(c1) - np.array(c2)))
|
||||||
size_diff = cast(float, np.linalg.norm(np.array(s1) - np.array(s2)))
|
size_diff = cast(float, np.linalg.norm(np.array(s1) - np.array(s2)))
|
||||||
|
|
||||||
return center_dist < tolerance and size_diff < tolerance
|
return bool(center_dist < tolerance and size_diff < tolerance)
|
||||||
|
|
||||||
|
|
||||||
# ** main function
|
# ** main function
|
||||||
@ -168,14 +171,14 @@ def measure_length(
|
|||||||
box = cv2.boxPoints(rbox)
|
box = cv2.boxPoints(rbox)
|
||||||
box = np.array(box, dtype=np.int32)
|
box = np.array(box, dtype=np.int32)
|
||||||
# order the points in the contour in top-left, top-right, bottom-right, and bottom-left
|
# order the points in the contour in top-left, top-right, bottom-right, and bottom-left
|
||||||
box = perspective.order_points(box)
|
box = cast(npt.NDArray[np.float32], perspective.order_points(box))
|
||||||
|
|
||||||
# unpack the bounding box
|
# unpack the bounding box
|
||||||
(tl, tr, br, bl) = box
|
(tl, tr, br, bl) = box
|
||||||
# compute the midpoints between the top-left and top-right as well as bottom-left and bottom-right coordinates
|
# compute the midpoints between the top-left and top-right as well as bottom-left and bottom-right coordinates
|
||||||
(tltrX, tltrY) = midpoint(tl, tr)
|
(tltrX, tltrY) = midpoint(tl, tr)
|
||||||
(blbrX, blbrY) = midpoint(bl, br)
|
(blbrX, blbrY) = midpoint(bl, br)
|
||||||
# compute the midpoints between the top-left and top-right as well as the top-right and bottom-right coordinates
|
# compute the midpoints between the top-left and bottom-left as well as the top-right and bottom-right coordinates
|
||||||
(tlblX, tlblY) = midpoint(tl, bl)
|
(tlblX, tlblY) = midpoint(tl, bl)
|
||||||
(trbrX, trbrY) = midpoint(tr, br)
|
(trbrX, trbrY) = midpoint(tr, br)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user