2021-02-21 Python Easyocr 图片文字识别
Python Easyocr 圖片文字識(shí)別
前段時(shí)間做了車牌識(shí)別相關(guān)的內(nèi)容分享,參看:
車牌識(shí)別(1)-車牌數(shù)據(jù)集生成
車牌識(shí)別(2)-搭建車牌識(shí)別模型
今天給大家分享一個(gè)簡(jiǎn)單的OCR文本識(shí)別工具:easyocr。這個(gè)模塊支持70多種語(yǔ)言的即用型OCR,包括中文,日文,韓文和泰文等。當(dāng)然這個(gè)模塊適當(dāng)改進(jìn)也可以用以車牌識(shí)別
?
1.安裝
pip install easyocr -i https://pypi.tuna.tsinghua.edu.cn/simple它會(huì)安裝除了模型文件之外的所有依賴,模型文件則會(huì)在運(yùn)行代碼的時(shí)候下載。
在pytorch網(wǎng)站上,請(qǐng)確保選擇正確的CUDA版本。如果僅打算在CPU模式下運(yùn)行,請(qǐng)選擇CUDA = None。
我的電腦沒安裝gpu版本的pytorch,所以運(yùn)行比較慢。
2.使用教程
?
import easyocrreader = easyocr.Reader(['ch_sim']) # ch_sim是Chinese simplified簡(jiǎn)寫result = reader.readtext('1.jpg')print(result)運(yùn)行的過程中會(huì)安裝所需要的模型文件,像下面這樣:
?
由于它的下載速度非常慢,而且經(jīng)常會(huì)失敗,因此建議先下載好模型文件,再將其放置到所需要的位置:
?
文字檢測(cè)模型(CRAFT)(必須)https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/craft_mlt_25k.zip 中文(簡(jiǎn)體)模型(識(shí)別中文必須)https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese_sim.zip 中國(guó)(傳統(tǒng))模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/chinese.zip 拉丁模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/latin.zip 日本模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/japanese.zip 韓文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/korean.zip 泰文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/thai.zip 阿拉伯文模型https://pythondict.com/go/?url=https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/arabic.zip如果下載速度太慢,請(qǐng)?jiān)诠娞?hào)后臺(tái)回復(fù):easyocr(明天再試下載,今晚還沒傳輸?shù)骄W(wǎng)盤),下載文字檢測(cè)模型(CRAFT)和中文簡(jiǎn)體模型文件包。
?
下載完模型后,將文件放到下面這個(gè)位置。
???????
Windows:C:\Users\用戶名\.EasyOCR\modelLinux:~/ .EasyOCR / model?
如下圖所示:
重新執(zhí)行腳本不會(huì)再提醒下載模型了,隨便找的一個(gè)圖片如下:
識(shí)別結(jié)果如下:
- ?
輸出采用列表格式,每個(gè)list分別表示對(duì)應(yīng)文字的邊界框、識(shí)別文本結(jié)果和置信度。
對(duì)于多語(yǔ)種的情況:
- ?
- ?
?
效果如下:
總體效果還算不錯(cuò),感興趣的朋友可以試下車牌識(shí)別的效果,以及思考下如何改進(jìn)車牌識(shí)別效果
?
總結(jié)
以上是生活随笔為你收集整理的2021-02-21 Python Easyocr 图片文字识别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021-02-21 代码不规范,运维两
- 下一篇: 2021-02-23 Matlab数据导