Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -189,34 +189,31 @@ class Model:
|
|
189 |
if detail:
|
190 |
print(msg + "ratio out of limit")
|
191 |
continue
|
192 |
-
# 扩展边界
|
193 |
expand_pixel = (bounds[3] - bounds[1]) // 20
|
194 |
-
bounds =
|
195 |
max(bounds[1] - expand_pixel, 0),
|
196 |
min(bounds[2] + expand_pixel // 2, im0.shape[1]),
|
197 |
min(bounds[3] + expand_pixel, im0.shape[0]),
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
temp_bound = (0, h2 - (cy - tp1), w, h2 + (b1 - cy))
|
217 |
temp_img = np.full((h, w, 3), 255, dtype=np.uint8)
|
218 |
-
temp_img[
|
219 |
-
bounds[0]:bounds[2]]
|
220 |
temp_img = transform.resize(temp_img, (1024, 512), preserve_range=True).astype(np.uint8)
|
221 |
imgs.append(temp_img)
|
222 |
return imgs
|
|
|
189 |
if detail:
|
190 |
print(msg + "ratio out of limit")
|
191 |
continue
|
|
|
192 |
expand_pixel = (bounds[3] - bounds[1]) // 20
|
193 |
+
bounds = [max(bounds[0] - expand_pixel // 2, 0),
|
194 |
max(bounds[1] - expand_pixel, 0),
|
195 |
min(bounds[2] + expand_pixel // 2, im0.shape[1]),
|
196 |
min(bounds[3] + expand_pixel, im0.shape[0]),
|
197 |
+
]
|
198 |
+
# corp and resize
|
199 |
+
w = bounds[2] - bounds[0]
|
200 |
+
h = bounds[3] - bounds[1]
|
201 |
+
bounds[3] += h % 2
|
202 |
+
h += h % 2
|
203 |
+
r = min(512 / w, 1024 / h)
|
204 |
+
pw, ph = int(512 / r - w), int(1024 / r - h)
|
205 |
+
bounds_tmp = (bounds[0] - pw // 2, bounds[1] - ph // 2,
|
206 |
+
bounds[2] + pw // 2 + pw % 2, bounds[3] + ph // 2 + ph % 2)
|
207 |
+
bounds = (max(0, bounds_tmp[0]), max(0, bounds_tmp[1]),
|
208 |
+
min(im0.shape[1], bounds_tmp[2]), min(im0.shape[0], bounds_tmp[3]))
|
209 |
+
dl = bounds[0] - bounds_tmp[0]
|
210 |
+
dr = bounds[2] - bounds_tmp[2]
|
211 |
+
dt = bounds[1] - bounds_tmp[1]
|
212 |
+
db = bounds[3] - bounds_tmp[3]
|
213 |
+
w = bounds_tmp[2] - bounds_tmp[0]
|
214 |
+
h = bounds_tmp[3] - bounds_tmp[1]
|
|
|
215 |
temp_img = np.full((h, w, 3), 255, dtype=np.uint8)
|
216 |
+
temp_img[dt:h + db, dl:w + dr] = im0[bounds[1]:bounds[3], bounds[0]:bounds[2]]
|
|
|
217 |
temp_img = transform.resize(temp_img, (1024, 512), preserve_range=True).astype(np.uint8)
|
218 |
imgs.append(temp_img)
|
219 |
return imgs
|