优化图片分割和拓展方法,兼容横向过长的图片

This commit is contained in:
2024-08-08 14:15:51 +08:00
parent dd8dcc0d3c
commit d296fa4414
3 changed files with 50 additions and 43 deletions

View File

@@ -57,7 +57,7 @@ def find_boxes(content, layout, offset=0, length=None, improve=False, image_path
capture_box = util.zoom_rectangle(box, 0.2)
captured_image = image_util.capture(image, capture_box)
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
captured_image, offset_x, offset_y = image_util.expand_to_a4_size(captured_image, True)
captured_image, offset_x, offset_y = image_util.expand_to_a4_size(captured_image)
cv2.imwrite(temp_file.name, captured_image)
try:
layouts = util.get_ocr_layout(OCR, temp_file.name)
@@ -166,7 +166,7 @@ def get_mask_layout(image, name, id_card_num):
def handle_image_for_mask(split_result):
expand_img, offset_x, offset_y = image_util.expand_to_a4_size(split_result["img"], True)
expand_img, offset_x, offset_y = image_util.expand_to_a4_size(split_result["img"])
split_result["x_offset"] -= offset_x
split_result["y_offset"] -= offset_y
return expand_img, split_result["x_offset"], split_result["y_offset"]