From f7540c4574eb2ae3e4e4473e6afcdfe970fc5894 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Thu, 2 Jan 2025 13:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AE=A1=E7=AE=97=E8=AF=AF?= =?UTF-8?q?=E5=B7=AE=E5=AF=BC=E8=87=B4=E5=88=86=E5=89=B2=E4=BA=A7=E7=94=9F?= =?UTF-8?q?=E6=97=A0=E6=95=88=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- util/image_util.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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