OCR 03: PaddleOCR
Catalog
About
- Git repository https://github.com/PaddlePaddle/PaddleOCR
- Online demo https://www.paddlepaddle.org.cn/hub/scene/ocr
- Installation Docs https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/quickstart.md
Install
python -m pip install paddlepaddle==2.3.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install "paddleocr>=2.0.1"
If error ocurs during installation
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
Download buildTool Installer from https://visualstudio.microsoft.com/visual-cpp-build-tools/ and install the desktop c++ package, this will download several GiB files, taking a long time.
Usage
paddleocr --image_dir ./fp05b.jpg --use_angle_cls true --use_gpu false
If it is running for the first time, it will download the model files
Invoke in Python
from paddleocr import PaddleOCR, draw_ocr
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memory
img_path = './photos/fp04b.jpg'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
# 显示结果
from PIL import Image
result = 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='./msyh.ttc')
im_show = Image.fromarray(im_show)
im_show.save('fp04b_result.jpg')
Performance
- Run on CPU, it will take around 10 seconds to parsing a picture
- Correct rate is much better than Tesseract and EasyOCR, even when handling the cellphone photos.