本项目用的是paddleOCR基于百度飞浆
blibli视频播放地址
b战地址 python三行代码 免费 高精度识别图片文字
项目github地址
https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.4/README_ch.md
1、先安装
https://visualstudio.microsoft.com/visual-cpp-build-tools/
2、命令行分别运行两行命令
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install "paddleocr>=2.0.1"
pip3 install -U https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-any.whl
代码部分
from paddleocr import PaddleOCR, draw_ocr
img_path = '4.jpg'
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
result = ocr.ocr(img_path, cls=True)
for line in result:
print(line)
from PIL import Image
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)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
|