赞
踩
(1)代码:
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
def my_ocr(img_path):
# need to run only once to download and load model into memory
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
result = ocr.ocr(img_path, cls=True)
for line in result:
print(line)
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')
if __name__ == '__main__':
my_ocr('test.jpg')
pass
(2)效果:
(1)代码:
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
def my_ocr(img_path):
# need to run only once to download and load model into memory
ocr = PaddleOCR()
result = ocr.ocr(img_path, rec=False)
for line in result:
print(line)
image = Image.open(img_path).convert('RGB')
im_show = draw_ocr(image, result, txts=None, scores=None, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
pass
if __name__ == '__main__':
my_ocr('test.jpg')
pass
(2)效果:
(1)代码:
from paddleocr import PaddleOCR
def my_ocr(img_path):
ocr = PaddleOCR() # need to run only once to download and load model into memory
result = ocr.ocr(img_path, det=False)
for line in result:
print(line)
pass
if __name__ == '__main__':
my_ocr('word_1.jpg')
pass
(2)效果:
ModuleNotFoundError: No module named 'layoutparser'
解决方法:
pip install layoutparser
或者
pip --default-timeout=100 install layoutparser -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。