test08.py 821 Bytes
from paddleocr import PaddleOCR, draw_ocr

# paddleocr目前支持中英文、英文、法语、德语、韩语、日语等80个语种,可以通过修改lang参数进行切换
ocr = PaddleOCR(
    use_angle_cls=False, lang="ch"
)  # need to run only once to download and load model into memory

img_path = "./ocr_invoice/ocr-vin-0007.jpg"
result = ocr.ocr(img_path, cls=False)
print("result===")
print(result)
# for line in result:
#     print(line)

# 可视化结果
from PIL import Image

image = Image.open(img_path).convert("RGB")
boxes = [line[0] for line in result[0]]
txts = [line[1][0] for line in result[0]]
scores = [line[1][1] for line in result[0]]
print("scores===")
print(scores)
im_show = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf")
im_show = Image.fromarray(im_show)
im_show.show()