feat: optimize padding and formula fallback

This commit is contained in:
liuyuanchuang
2026-03-10 09:54:54 +08:00
parent cff14904bf
commit f8173f7c0a
2 changed files with 13 additions and 4 deletions

View File

@@ -104,7 +104,8 @@ class ImageProcessor:
"""Add whitespace padding around the image.
Adds padding equal to padding_ratio * max(height, width) on each side.
This expands the image by approximately 30% total (15% on each side).
For small images (height < 80 or width < 500), uses reduced padding_ratio 0.2.
This expands the image by approximately 30% total (15% on each side) for normal images.
Args:
image: Input image as numpy array in BGR format.
@@ -113,7 +114,9 @@ class ImageProcessor:
Padded image as numpy array.
"""
height, width = image.shape[:2]
padding = int(max(height, width) * self.padding_ratio)
# Use smaller padding ratio for small images to preserve detail
padding_ratio = 0.2 if height < 80 or width < 500 else self.padding_ratio
padding = int(max(height, width) * padding_ratio)
# Add white padding on all sides
padded_image = cv2.copyMakeBorder(