修正计算误差导致分割产生无效图片

This commit is contained in:
2025-01-02 13:05:10 +08:00
parent 5e6a471954
commit f7540c4574
2 changed files with 7 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
x-env: x-env:
&template &template
image: fcb_photo_review:1.14.11 image: fcb_photo_review:1.14.12
restart: always restart: always
x-review: x-review:

View File

@@ -72,6 +72,8 @@ def split(image, ratio=1.414, overlap=0.05, x_compensation=3):
for i in range(math.ceil(height / step)): for i in range(math.ceil(height / step)):
offset = round(step * i) offset = round(step * i)
cropped_img = capture(image, [0, offset, width, offset + new_img_height]) cropped_img = capture(image, [0, offset, width, offset + new_img_height])
if cropped_img.shape[0] > 0:
# 计算误差可能导致图片高度为0此时不添加
split_result.append({"img": cropped_img, "x_offset": 0, "y_offset": offset}) split_result.append({"img": cropped_img, "x_offset": 0, "y_offset": offset})
elif wh_ratio > ratio: # 横向过长 elif wh_ratio > ratio: # 横向过长
new_img_width = height * ratio new_img_width = height * ratio
@@ -79,6 +81,8 @@ def split(image, ratio=1.414, overlap=0.05, x_compensation=3):
for i in range(math.ceil(width / step)): for i in range(math.ceil(width / step)):
offset = round(step * i) offset = round(step * i)
cropped_img = capture(image, [offset, 0, offset + new_img_width, width]) cropped_img = capture(image, [offset, 0, offset + new_img_width, width])
if cropped_img.shape[1] > 0:
# 计算误差可能导致图片宽度为0此时不添加
split_result.append({"img": cropped_img, "x_offset": offset, "y_offset": 0}) split_result.append({"img": cropped_img, "x_offset": offset, "y_offset": 0})
else: else:
split_result.append({"img": image, "x_offset": 0, "y_offset": 0}) split_result.append({"img": image, "x_offset": 0, "y_offset": 0})