赞
踩
from paddleocr import PaddleOCR, draw_ocr # ocr = PaddleOCR(lang="ch", use_gpu="False") , lang="ch" # ocr = PaddleOCR(use_angle_cls=True) # 初始化 OCR ocr = PaddleOCR() # 初始化 OCR image_path = 'F:\学习\测试用图\英文测试.png' # 图片路径 # result = ocr.ocr(image_path, cls=True) # 进行文字识别 result = ocr.ocr(image_path) # 进行文字识别 print(result) with open('wenzi.txt', 'a', encoding='utf-8') as file: # 遍历出文字识别的结果 for line in result: for word in line: print(word) # 提取出识别数据中的文字元组 text_line = word[-1] # 从文字元组中提取文字内容 text = text_line[0] print('test:', text) file.write(text + '\n') print("识别结果已保存到txt文件中") from PIL import Image image = Image.open(image_path).convert('RGB') boxes = [detection[0] for line in result for detection in line] # Nested loop added txts = [detection[1][0] for line in result for detection in line] # Nested loop added scores = [detection[1][1] for line in result for detection in line] # Nested loop added im_show = draw_ocr(image, boxes, txts, scores) im_show = Image.fromarray(im_show) im_show.save('test_ocr.jpg')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。