fffiloni commited on
Commit
9897471
1 Parent(s): dc75d3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -38,12 +38,11 @@ def find_tip(points, convex_hull):
38
  if np.all(points[j] == points[indices[i - 1] - 2]):
39
  return tuple(points[j])
40
 
41
- def find_tail(points, convex_hull):
42
- # Implement the logic to find the tail point
43
- # You might need to adjust this based on the specific characteristics of your arrows
44
- # This is just a simple example, and you may need to fine-tune it based on your requirements
45
- tail_index = (convex_hull[0] + convex_hull[-1]) // 2
46
- return tuple(points[tail_index])
47
 
48
  def infer(image_in):
49
  img = cv2.imread(image_in)
@@ -58,7 +57,7 @@ def infer(image_in):
58
 
59
  if 6 > sides > 3 and sides + 2 == len(approx):
60
  arrow_tip = find_tip(approx[:,0,:], hull.squeeze())
61
- arrow_tail = find_tail(approx[:,0,:], hull.squeeze())
62
 
63
  if arrow_tip and arrow_tail:
64
  cv2.drawContours(img, [cnt], -1, (0, 255, 0), 3)
@@ -66,6 +65,7 @@ def infer(image_in):
66
  cv2.circle(img, arrow_tail, 3, (255, 0, 0), cv2.FILLED)
67
 
68
 
 
69
  cv2.imwrite("Image_result.png", img)
70
 
71
  return "Image_result.png", "1_gray.png", "2_blur.png", "3_canny.png", "4_dilate.png", "5_erode.png"
 
38
  if np.all(points[j] == points[indices[i - 1] - 2]):
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)
 
57
 
58
  if 6 > sides > 3 and sides + 2 == len(approx):
59
  arrow_tip = find_tip(approx[:,0,:], hull.squeeze())
60
+ arrow_tail = find_tail(approx[:,0,:], arrow_tip)
61
 
62
  if arrow_tip and arrow_tail:
63
  cv2.drawContours(img, [cnt], -1, (0, 255, 0), 3)
 
65
  cv2.circle(img, arrow_tail, 3, (255, 0, 0), cv2.FILLED)
66
 
67
 
68
+
69
  cv2.imwrite("Image_result.png", img)
70
 
71
  return "Image_result.png", "1_gray.png", "2_blur.png", "3_canny.png", "4_dilate.png", "5_erode.png"