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