免費軟件不收費網(wǎng)站小說榜單首頁百度搜索風(fēng)云榜
Paddle OCR
PaddleOCR 基于深度學(xué)習(xí)技術(shù)實現(xiàn)的,使用十分簡單。
先看效果
可以看出來識別效果還是不錯的,里面的“濕”字識別成了繁體字。如果不是連體字,就不會出現(xiàn)這個問題。
1.測試環(huán)境
操作系統(tǒng):Win10
Python:3.10
2.安裝PaddlePaddle庫
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple(自行選擇鏡像源)
3.下載PaddleOCR庫
git clone https://github.com/PaddlePaddle/PaddleOCR
也可以選擇直接DownLoad下載文件解壓到本地
4.安裝依賴包
進入PaddleOCR文件夾下:
> cd PaddleOCR
安裝第三方依賴:
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
5.詳細代碼
from pprint import pprint
from paddleocr import PaddleOCR
import gradio as gr ocr = PaddleOCR(use_angle_cls=True, lang="ch") def process(image): result = ocr.ocr(image) # return resultoutput_text = "" # 初始化輸出文本變量for sublist in result:for line in sublist:text = line[1][0] # 提取文本output_text += text + "\n" # 將文本追加到輸出文本變量,并添加換行符pprint(output_text)return output_textiface = gr.Interface(fn=process, inputs="image", outputs="text",title="圖片OCR提取文字", iface.launch()
注意:這里result原先返回的還有坐標信息以及置信度,這里經(jīng)過處理只返回了識別后的文本信息。如果需要坐標信息,可以直接返回result。