diff --git a/docker-compose.yml b/docker-compose.yml index b199d85..80d6892 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ x-env: &template - image: fcb_photo_review:1.14.11 + image: fcb_photo_review:1.14.12 restart: always x-review: diff --git a/util/image_util.py b/util/image_util.py index 0b30cc0..3a0082b 100644 --- a/util/image_util.py +++ b/util/image_util.py @@ -72,14 +72,18 @@ def split(image, ratio=1.414, overlap=0.05, x_compensation=3): for i in range(math.ceil(height / step)): offset = round(step * i) cropped_img = capture(image, [0, offset, width, offset + new_img_height]) - split_result.append({"img": cropped_img, "x_offset": 0, "y_offset": offset}) + if cropped_img.shape[0] > 0: + # 计算误差可能导致图片高度为0,此时不添加 + split_result.append({"img": cropped_img, "x_offset": 0, "y_offset": offset}) elif wh_ratio > ratio: # 横向过长 new_img_width = height * ratio step = height * (ratio - overlap * x_compensation) # 一般文字是横向的,所以横向截取时增大重叠部分 for i in range(math.ceil(width / step)): offset = round(step * i) cropped_img = capture(image, [offset, 0, offset + new_img_width, width]) - split_result.append({"img": cropped_img, "x_offset": offset, "y_offset": 0}) + if cropped_img.shape[1] > 0: + # 计算误差可能导致图片宽度为0,此时不添加 + split_result.append({"img": cropped_img, "x_offset": offset, "y_offset": 0}) else: split_result.append({"img": image, "x_offset": 0, "y_offset": 0}) return split_result