diff --git a/src/dopt_sensor_anomalies/detection.py b/src/dopt_sensor_anomalies/detection.py index 57fbcce..de9cf04 100644 --- a/src/dopt_sensor_anomalies/detection.py +++ b/src/dopt_sensor_anomalies/detection.py @@ -31,14 +31,17 @@ pixels_per_metric_Y: float = 0.251 # 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 Parameters ---------- - pt_A : npt.NDArray + pt_A : npt.NDArray[np.floating] tuple of coordinates x, y; shape (2, ) - pt_B : npt.NDArray + pt_B : npt.NDArray[np.floating] tuple of coordinates x, y; shape (2, ) Returns @@ -50,17 +53,17 @@ def midpoint(pt_A: npt.NDArray, pt_B: npt.NDArray) -> tuple[float, float]: def check_box_redundancy( - box1: t.Box, - box2: t.Box, + box_1: t.Box, + box_2: t.Box, tolerance: float = 5.0, ) -> bool: """to check if bounding box has already been identified and is just a redundant one Parameters ---------- - box1 : t.Box + box_1 : t.Box 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) tolerance : float, optional distance threshold for width and height, by default 5.0 @@ -71,8 +74,8 @@ def check_box_redundancy( redundancy evaluation """ # unpack the boxes - c1, s1, _ = box1 - c2, s2, _ = box2 + c1, s1, _ = box_1 + c2, s2, _ = box_2 # sort width and height such that (w, h) == (h, w) is treated the same # (might have been recognized in different orders) s1 = sorted(s1) @@ -81,7 +84,7 @@ def check_box_redundancy( 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))) - return center_dist < tolerance and size_diff < tolerance + return bool(center_dist < tolerance and size_diff < tolerance) # ** main function @@ -168,14 +171,14 @@ def measure_length( box = cv2.boxPoints(rbox) box = np.array(box, dtype=np.int32) # 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 (tl, tr, br, bl) = box # compute the midpoints between the top-left and top-right as well as bottom-left and bottom-right coordinates (tltrX, tltrY) = midpoint(tl, tr) (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) (trbrX, trbrY) = midpoint(tr, br)