Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -183,6 +183,7 @@ 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 |
p0, p1, p2, p3 = bound[0]
|
| 187 |
x = int(p0[0])
|
| 188 |
y = int(p0[1])
|
|
@@ -191,21 +192,21 @@ def blur_im(img,bounds,target_lang,trans_lang):
|
|
| 191 |
kernel = np.ones((3, 3), np.uint8)
|
| 192 |
im[y:y+h, x:x+w] = cv2.dilate(im[y:y+h, x:x+w], kernel, iterations=3)
|
| 193 |
im[y:y+h, x:x+w] = cv2.GaussianBlur(im[y:y+h, x:x+w],(51,51),0)
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
im = Image.fromarray(im)
|
| 198 |
for bound in bounds:
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
| 209 |
return im
|
| 210 |
|
| 211 |
def draw_boxes(image, bounds, color='blue', width=1):
|
|
|
|
| 183 |
im = cv2.imread(img)
|
| 184 |
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
|
| 185 |
for bound in bounds:
|
| 186 |
+
|
| 187 |
p0, p1, p2, p3 = bound[0]
|
| 188 |
x = int(p0[0])
|
| 189 |
y = int(p0[1])
|
|
|
|
| 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 |
im = Image.fromarray(im)
|
| 196 |
for bound in bounds:
|
| 197 |
+
if bound[2]>=0.3:
|
| 198 |
+
p0, p1, p2, p3 = bound[0]
|
| 199 |
+
x = int(p0[0])
|
| 200 |
+
y = int(p0[1])
|
| 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.15)
|
| 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))
|
| 208 |
+
else:
|
| 209 |
+
pass
|
| 210 |
return im
|
| 211 |
|
| 212 |
def draw_boxes(image, bounds, color='blue', width=1):
|