From 823eb0ba13b22e2dde0c2a436c25d4a30c3437f4 Mon Sep 17 00:00:00 2001 From: Pavel Lutskov Date: Sat, 23 Jun 2018 22:02:39 +0200 Subject: [PATCH] Made goal recognition NumPy 1.6.0 compatible --- pykick/finders.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pykick/finders.py b/pykick/finders.py index e10d8df..7eaf33e 100644 --- a/pykick/finders.py +++ b/pykick/finders.py @@ -61,14 +61,15 @@ class GoalFinder(object): return thr def goal_similarity(self, contour): - contour = contour.squeeze(axis=1) - hull = cv2.convexHull(contour).squeeze(axis=1) + hull = cv2.convexHull(contour).squeeze() len_h = cv2.arcLength(hull, True) - # Wild assumption that the goal should lie close to its + # Supporting points of goal contour should lie close to its # enclosing convex hull - shape_sim = np.linalg.norm(contour[:,None] - hull, - axis=2).min(axis=1).sum() / len_h + distances = np.array([[np.sqrt(np.sum(point**2)) for point in node] + for node in contour - hull]) + min_dist = np.array([d.min() for d in distances]) + shape_sim = min_dist.sum() / len_h # Wild assumption that the area of the goal is rather small # compared to its enclosing convex hull