修正计算误差导致分割产生无效图片
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -72,14 +72,18 @@ 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])
|
||||||
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: # 横向过长
|
elif wh_ratio > ratio: # 横向过长
|
||||||
new_img_width = height * ratio
|
new_img_width = height * ratio
|
||||||
step = height * (ratio - overlap * x_compensation) # 一般文字是横向的,所以横向截取时增大重叠部分
|
step = height * (ratio - overlap * x_compensation) # 一般文字是横向的,所以横向截取时增大重叠部分
|
||||||
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])
|
||||||
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:
|
else:
|
||||||
split_result.append({"img": image, "x_offset": 0, "y_offset": 0})
|
split_result.append({"img": image, "x_offset": 0, "y_offset": 0})
|
||||||
return split_result
|
return split_result
|
||||||
|
|||||||
Reference in New Issue
Block a user