Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,29 +38,33 @@ def find_tip(points, convex_hull):
|
|
38 |
if np.all(points[j] == points[indices[i - 1] - 2]):
|
39 |
return tuple(points[j])
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
|
46 |
def infer(image_in):
|
47 |
img = cv2.imread(image_in)
|
48 |
|
49 |
contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
50 |
-
|
51 |
for cnt in contours:
|
52 |
peri = cv2.arcLength(cnt, True)
|
53 |
approx = cv2.approxPolyDP(cnt, 0.025 * peri, True)
|
54 |
hull = cv2.convexHull(approx, returnPoints=False)
|
55 |
sides = len(hull)
|
56 |
|
57 |
-
|
58 |
-
|
59 |
if 6 > sides > 3 and sides + 2 == len(approx):
|
60 |
arrow_tip = find_tip(approx[:,0,:], hull.squeeze())
|
61 |
-
|
|
|
|
|
62 |
cv2.drawContours(img, [cnt], -1, (0, 255, 0), 3)
|
63 |
cv2.circle(img, arrow_tip, 3, (0, 0, 255), cv2.FILLED)
|
|
|
|
|
64 |
|
65 |
cv2.imwrite("Image_result.png", img)
|
66 |
|
|
|
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)
|
50 |
|
51 |
contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
52 |
+
|
53 |
for cnt in contours:
|
54 |
peri = cv2.arcLength(cnt, True)
|
55 |
approx = cv2.approxPolyDP(cnt, 0.025 * peri, True)
|
56 |
hull = cv2.convexHull(approx, returnPoints=False)
|
57 |
sides = len(hull)
|
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)
|
65 |
cv2.circle(img, arrow_tip, 3, (0, 0, 255), cv2.FILLED)
|
66 |
+
cv2.circle(img, arrow_tail, 3, (255, 0, 0), cv2.FILLED)
|
67 |
+
|
68 |
|
69 |
cv2.imwrite("Image_result.png", img)
|
70 |
|