ocr_cut_image.py 666 Bytes
Newer Older
赵小蒙's avatar
赵小蒙 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from magic_pdf.libs.commons import join_path
from magic_pdf.libs.pdf_image_tools import cut_image


def cut_image_and_table(spans, page, page_id, book_name, save_path):
    def s3_return_path(type):
        return join_path(book_name, type)

    def img_save_path(type):
        return join_path(save_path, s3_return_path(type))

    for span in spans:
        span_type = span['type']
        if span_type == 'image':
15
            span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('images'))
赵小蒙's avatar
赵小蒙 committed
16
        elif span_type == 'table':
17
            span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('tables'))
赵小蒙's avatar
赵小蒙 committed
18
19

    return spans