fffiloni commited on
Commit
2516acd
1 Parent(s): 9897471

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -39,10 +39,19 @@ def find_tip(points, convex_hull):
39
  return tuple(points[j])
40
 
41
  def find_tail(points, tip):
42
- # Find the farthest point from the tip
43
- farthest_point = max(points, key=lambda p: cv2.pointPolygonTest(np.array([tip], dtype=np.int32), tuple(p), True))
 
44
 
45
- return tuple(farthest_point)
 
 
 
 
 
 
 
 
46
 
47
  def infer(image_in):
48
  img = cv2.imread(image_in)
 
39
  return tuple(points[j])
40
 
41
  def find_tail(points, tip):
42
+ # Convert the tip and points to numpy arrays
43
+ tip = np.array([tip], dtype=np.float32)
44
+ points = np.array(points, dtype=np.int32)
45
 
46
+ # Find the index of the farthest point
47
+ distances = cv2.pointPolygonTest(points, tip, True)
48
+
49
+ if distances is not None:
50
+ farthest_index = np.argmax(distances)
51
+ farthest_point = tuple(points[farthest_index][0])
52
+ return farthest_point
53
+ else:
54
+ return None
55
 
56
  def infer(image_in):
57
  img = cv2.imread(image_in)