from paddleocr import PaddleOCR, draw_ocr
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
img_path = 'images/1.png'
ocr_result = ocr.ocr(img_path, cls=True)
for idx in range(len(ocr_result)):
res = ocr_result[idx]
my_chat_list = []
you_chat_list = []
other_chat_list = []
for index, line in enumerate(res):
print(line)
# 包含最左边的信息和引用信息
if 90 < line[0][0][0] and line[0][1][0] < 430:
you_chat_list.append(line[1][0])
elif 470 < line[0][0][0] and line[0][1][0] < 810:
my_chat_list.append(line[1][0])
print(f'对方昵称:{you_chat_list}')
print(f'DDR(直奔主题): {my_chat_list}')
# 显示结果
# from PIL import Image
# result = ocr_result[0]
# image = Image.open(img_path).convert('RGB')
# boxes = [line[0] for line in result]
# txts = [line[1][0] for line in result]
# scores = [line[1][1] for line in result]
# im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
# im_show = Image.fromarray(im_show)
# im_show.save('result.jpg')