Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
|
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,:],
|
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"
|