From 21df8738182135ad549d5d40d806fbfe0a0a052b Mon Sep 17 00:00:00 2001 From: shunsuke-iwashita <129936839+shunsuke-iwashita@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:16:29 +0900 Subject: [PATCH] fix calibration_model/fld.py (#132) * fix calibration_model/fld.py * Update fld.py * Update fld.py --- sportslabkit/calibration_model/fld.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sportslabkit/calibration_model/fld.py b/sportslabkit/calibration_model/fld.py index 5abe684..b953db5 100644 --- a/sportslabkit/calibration_model/fld.py +++ b/sportslabkit/calibration_model/fld.py @@ -52,6 +52,11 @@ def _get_largest_contour(self, image): def _approximate_hull(self, contour): hull = cv2.convexHull(contour) return hull + + def _get_upper_left_courner(self, hull): + """Find the nearest point from the upper left corner.""" + sorted_hull = sorted(hull, key=lambda x:x[0][0]*x[0][0] + x[0][1]*x[0][1]) + return sorted_hull[0][0] def _farthest_point_from(self, reference_point, point_list): """Find the point in 'point_list' that is farthest from 'reference_point'.""" @@ -66,7 +71,7 @@ def _farthest_point_from(self, reference_point, point_list): def _approximate_quad(self, hull): """Approximate a convex hull to a quadrilateral by considering most distant points.""" - first_point = hull[0][0] + first_point = self._get_upper_left_corner(hull) second_point = self._farthest_point_from(first_point, hull) max_distance = 0