Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -183,15 +183,17 @@ def blur_im(img,bounds,target_lang,trans_lang):
|
|
183 |
im = cv2.imread(img)
|
184 |
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
|
185 |
for bound in bounds:
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
195 |
im = Image.fromarray(im)
|
196 |
for bound in bounds:
|
197 |
if bound[2]>=0.3:
|
@@ -201,7 +203,7 @@ def blur_im(img,bounds,target_lang,trans_lang):
|
|
201 |
w = int(p2[0]) - int(x)
|
202 |
h = int(p2[1]) - int(y)
|
203 |
draw = ImageDraw.Draw(im)
|
204 |
-
font_size=int(int(w)*0.
|
205 |
font = ImageFont.truetype("./fonts/unifont-15.0.01.ttf", int(font_size))
|
206 |
text = this(bound[1],target_lang,trans_lang)
|
207 |
draw.text((x, y),text, font = font, fill=(0,0,0))
|
@@ -209,9 +211,13 @@ def blur_im(img,bounds,target_lang,trans_lang):
|
|
209 |
pass
|
210 |
return im
|
211 |
|
212 |
-
def draw_boxes(image, bounds,
|
213 |
draw = ImageDraw.Draw(image)
|
214 |
for bound in bounds:
|
|
|
|
|
|
|
|
|
215 |
p0, p1, p2, p3 = bound[0]
|
216 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
217 |
return image
|
@@ -233,10 +239,6 @@ def detect(img, target_lang,trans_lang,target_lang2=None):
|
|
233 |
|
234 |
blr_out=blur_im(img,bounds,target_lang,trans_lang)
|
235 |
return im_out,blr_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
|
241 |
with gr.Blocks() as robot:
|
242 |
with gr.Row():
|
|
|
183 |
im = cv2.imread(img)
|
184 |
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
|
185 |
for bound in bounds:
|
186 |
+
if bound[2]>=0.3:
|
187 |
+
p0, p1, p2, p3 = bound[0]
|
188 |
+
x = int(p0[0])
|
189 |
+
y = int(p0[1])
|
190 |
+
w = int(p2[0]) - int(x)
|
191 |
+
h = int(p2[1]) - int(y)
|
192 |
+
kernel = np.ones((3, 3), np.uint8)
|
193 |
+
im[y:y+h, x:x+w] = cv2.dilate(im[y:y+h, x:x+w], kernel, iterations=3)
|
194 |
+
im[y:y+h, x:x+w] = cv2.GaussianBlur(im[y:y+h, x:x+w],(51,51),0)
|
195 |
+
else:
|
196 |
+
pass
|
197 |
im = Image.fromarray(im)
|
198 |
for bound in bounds:
|
199 |
if bound[2]>=0.3:
|
|
|
203 |
w = int(p2[0]) - int(x)
|
204 |
h = int(p2[1]) - int(y)
|
205 |
draw = ImageDraw.Draw(im)
|
206 |
+
font_size=int(int(w)*0.1)
|
207 |
font = ImageFont.truetype("./fonts/unifont-15.0.01.ttf", int(font_size))
|
208 |
text = this(bound[1],target_lang,trans_lang)
|
209 |
draw.text((x, y),text, font = font, fill=(0,0,0))
|
|
|
211 |
pass
|
212 |
return im
|
213 |
|
214 |
+
def draw_boxes(image, bounds, width=1):
|
215 |
draw = ImageDraw.Draw(image)
|
216 |
for bound in bounds:
|
217 |
+
if bound[2]>=0.3:
|
218 |
+
color = "green"
|
219 |
+
else:
|
220 |
+
color = "red"
|
221 |
p0, p1, p2, p3 = bound[0]
|
222 |
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
223 |
return image
|
|
|
239 |
|
240 |
blr_out=blur_im(img,bounds,target_lang,trans_lang)
|
241 |
return im_out,blr_out,pd.DataFrame(bounds),pd.DataFrame(bounds).iloc[:,1:]
|
|
|
|
|
|
|
|
|
242 |
|
243 |
with gr.Blocks() as robot:
|
244 |
with gr.Row():
|