当前位置:   article > 正文

python使用paddleocr 识别图片上的文本_python识别图片中的指定文字paddleocr

python识别图片中的指定文字paddleocr
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')


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/678614
推荐阅读
相关标签
  

闽ICP备14008679号