python Ocr识别

2022-03-23  本文已影响0人  别时茫茫

软件安装

识别的一般步骤

from PIL import Image
import pytesseract
import numpy as np
import sys

filename = sys.argv[1]
img1 = np.array(Image.open(filename))
text = pytesseract.image_to_string(img1)
print(text)

问题

汉字支持

img1 = np.array(Image.open(filename))
text = pytesseract.image_to_string(img1,lang = "chi_sim")
print(text)

paddle-ocr

安装

 ## https://pypi.org/project/paddleocr/
pip install "paddleocr>=2.0.1" # Recommend to use version 2.0.1+
## 同时需要安装paddle
pip install paddlepaddle

识别代码

from paddleocr import PaddleOCR
import sys
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang='ch') # need to run only once to download and load model into memory

img_path = sys.argv[1:]
result = ocr.ocr(img_path, cls=True)
for line in result:
    print(line)

参考

上一篇下一篇

猜你喜欢

热点阅读