Spaces:
Build error
Build error
Modify crop padding
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ def table_structure(pil_img):
|
|
61 |
return result
|
62 |
|
63 |
|
64 |
-
def crop_image(pil_img, detection_result):
|
65 |
crop_images = []
|
66 |
image = PIL_to_cv(pil_img)
|
67 |
width = image.shape[1]
|
@@ -75,10 +75,10 @@ def crop_image(pil_img, detection_result):
|
|
75 |
w = result[2]
|
76 |
h = result[3]
|
77 |
|
78 |
-
x1 = max(0, int((min_x - w / 2
|
79 |
-
y1 = max(0, int((min_y - h / 2
|
80 |
-
x2 = min(width, int((min_x + w / 2
|
81 |
-
y2 = min(height, int((min_y + h / 2
|
82 |
# print(x1, y1, x2, y2)
|
83 |
crop_image = image[y1:y2, x1:x2, :]
|
84 |
crop_images.append(cv_to_PIL(crop_image))
|
|
|
61 |
return result
|
62 |
|
63 |
|
64 |
+
def crop_image(pil_img, detection_result, padding=30):
|
65 |
crop_images = []
|
66 |
image = PIL_to_cv(pil_img)
|
67 |
width = image.shape[1]
|
|
|
75 |
w = result[2]
|
76 |
h = result[3]
|
77 |
|
78 |
+
x1 = max(0, int((min_x - w / 2) * width) - padding)
|
79 |
+
y1 = max(0, int((min_y - h / 2) * height) - padding)
|
80 |
+
x2 = min(width, int((min_x + w / 2) * width) + padding)
|
81 |
+
y2 = min(height, int((min_y + h / 2) * height) + padding)
|
82 |
# print(x1, y1, x2, y2)
|
83 |
crop_image = image[y1:y2, x1:x2, :]
|
84 |
crop_images.append(cv_to_PIL(crop_image))
|