bachpc commited on
Commit
9e9067e
1 Parent(s): 9bdc8fc

Modify crop padding

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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 - 0.02) * width))
79
- y1 = max(0, int((min_y - h / 2 - 0.02) * height))
80
- x2 = min(width, int((min_x + w / 2 + 0.02) * width))
81
- y2 = min(height, int((min_y + h / 2 + 0.02) * height))
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))