fffiloni commited on
Commit
e7a8bfc
·
verified ·
1 Parent(s): 54b68aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -68,11 +68,18 @@ def find_tail(points, tip):
68
 
69
  return None
70
 
 
 
 
 
71
  def infer(image_in):
72
  img = cv2.imread(image_in)
73
 
74
  contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
75
 
 
 
 
76
  for cnt in contours:
77
  peri = cv2.arcLength(cnt, True)
78
  approx = cv2.approxPolyDP(cnt, 0.025 * peri, True)
@@ -89,12 +96,16 @@ def infer(image_in):
89
  arrow_tail = find_tail(approx[:,0,:], arrow_tip)
90
  if arrow_tail :
91
  cv2.circle(img, arrow_tail, 3, (255, 0, 0), cv2.FILLED)
 
 
 
92
 
93
 
94
 
95
  cv2.imwrite("Image_result.png", img)
 
96
 
97
- return "Image_result.png", "1_gray.png", "2_blur.png", "3_canny.png", "4_dilate.png", "5_erode.png"
98
 
99
  gr.Interface(
100
  fn=infer,
@@ -105,9 +116,6 @@ gr.Interface(
105
  outputs=[
106
  gr.Image(),
107
  gr.Image(),
108
- gr.Image(),
109
- gr.Image(),
110
- gr.Image(),
111
- gr.Image(),
112
  ]
113
  ).launch()
 
68
 
69
  return None
70
 
71
+ def draw_arrow(img_result, tip, tail):
72
+ # Draw arrow on the blank image
73
+ cv2.arrowedLine(img_result, tuple(tip), tuple(tail), (0, 255, 0), 3)
74
+
75
  def infer(image_in):
76
  img = cv2.imread(image_in)
77
 
78
  contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
79
 
80
+ # Create a blank image to accumulate arrows
81
+ img_result = np.zeros_like(img)
82
+
83
  for cnt in contours:
84
  peri = cv2.arcLength(cnt, True)
85
  approx = cv2.approxPolyDP(cnt, 0.025 * peri, True)
 
96
  arrow_tail = find_tail(approx[:,0,:], arrow_tip)
97
  if arrow_tail :
98
  cv2.circle(img, arrow_tail, 3, (255, 0, 0), cv2.FILLED)
99
+
100
+ # Draw arrow on the same blank image
101
+ draw_arrow(img_result, arrow_tip, arrow_tail)
102
 
103
 
104
 
105
  cv2.imwrite("Image_result.png", img)
106
+ cv2.imwrite("Arrows_on_same_blank.png", img_result)
107
 
108
+ return "Image_result.png", "Arrows_on_same_blank.png"
109
 
110
  gr.Interface(
111
  fn=infer,
 
116
  outputs=[
117
  gr.Image(),
118
  gr.Image(),
119
+
 
 
 
120
  ]
121
  ).launch()