百度paddleocr安裝使用
在之前的項目中使用的是百度在線版ocr,需要連接網(wǎng)絡(luò),有調(diào)用次數(shù)限制。
今年又有項目要用到ocr,在了解了下現(xiàn)在ocr情況之后開始了paddleocr的試用。
## 安裝:
安裝過程直接使用pip install paddleocr就可以了,后面就是看他安裝完,依賴有點多,要一點點來。
https://github.com/PaddlePaddle/PaddleOCR/releases
注:由于paddleocr整個包比較大,有上百兆,在使用pip安裝過程中需要耐心點。如果沒耐心可以直接下載github上的發(fā)布包進行安裝。
上面這個方法比較傳統(tǒng),要解決多個不同配置,可以使用官網(wǎng)上的配置一鍵安裝。
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/windows-pip.html
## 使用
```
from paddleocr import PaddleOCR, draw_ocr
# Paddleocr目前支持的多語言語種可以通過修改lang參數(shù)進行切換
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True,)? # need to run only once to download and load model into memory
img_path = './imgs/11.jpg'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
? ? res = result[idx]
? ? for line in res:
? ? ? ? print(line)
# 顯示結(jié)果
# 如果本地沒有simfang.ttf,可以在doc/fonts目錄下下載
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='doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
```
模型訓(xùn)練
如果有衍生需求還可以自己接著訓(xùn)練
報錯梳理
1、# ImportError: cannot import name 'inference' from 'paddle' (unknown location)
解決方式:
paddle版本問題,安裝一個穩(wěn)定版paddle即可
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/windows-pip.html
https://oomake.com/question/15635800