python3.7 安裝PIL識別圖片中文字

前提:
本人開發環境是windows7 旗艦版 64位系統
python -V
Python 3.7.3
pip -V
pip 20.0.2 from d:\software\python\lib\site-packages\pip (python 3.7)

問題一:
python不是內部或外部命令的解決方法
https://jingyan.baidu.com/article/fc07f989a830d012ffe5191e.html(照葫蘆畫瓢時間到)
問題二(python3 pip升級命令):
基於python3開發用pip安裝插件時候要求pip 版本爲20.0.2(因人而異)
python -m pip install --upgrade pip
問題三:
卸載PIP的命令:python -m pip uninstall pip
重裝PIP的命令:easy_inatall pip
升級PIP的命令:python -m pip install --upgrade pip
卸載pip的命令行安裝的插件:pip uninstall 插件名在這裏插入圖片描述
查看所有安裝已安裝插件:pip list
在這裏插入圖片描述
問題四:
安裝python插件時候總是總是安裝不上,安裝不上的猜測原因一:你的網速不好 原因二:有可能跟安裝鏡像源有關(本人猜測)
解決辦法:
pip install 插件名 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
更多信息查看
總結:
python中每個版本對於插件的要求各不相同,對於初學者而言一開始裝插件時候經常裝不上都是正常的,報錯一連串,需要更細心、耐心一點查看報錯信息,在python中如果你想使用一個插件,不僅需要安裝插件還需要下載一些輔助的資源纔可以使用相應的插件,例如:PIL(Pillow)、pdfkit等插件是都需要下載相應的輔助資源

正題:
pillow是PIL的一個分支,雖是分支但是其與PIL同樣也具有很強的圖像處理庫。
第一步: 安裝Pillow、pytesseract插件

  1. pip install Pillow (pip install Pillow -i http://pypi.douban.com/simple --trusted-host pypi.douban.com)
  2. pip install pytesseract

第二步:安裝tesseract-ocr
1》
方法一:github地址: https://github.com/tesseract-ocr/tesseract
進去選擇wiki,在選擇對應的版本即可。安裝時默認只有一個eng的識別庫,可以勾選想要添加的庫,或者自己單獨下載後放到安裝文件夾tessdata下。我找了半天太。。。nan。。。le
https://tesseract-ocr.github.io/tessdoc/Home.html
在這裏插入圖片描述
方法二:在這裏選擇適合自己的版本
https://digi.bib.uni-mannheim.de/tesseract

2》傻瓜式安裝tesseract-ocr-xxx.exe
在這裏插入圖片描述
3》配置tesseract.exe到環境變量PATH中
驗證tesseract命令是否配置成功
tesseract -v在這裏插入圖片描述
4》修改python中的pytesseract.py文件
在這裏插入圖片描述
修改部分如下:
在這裏插入圖片描述

第三步:測試demo

import pytesseract
from PIL import Image

image = Image.open("../img/eng.png")
code = pytesseract.image_to_string(image,lang="eng")
print(code)

在這裏插入圖片描述
擴展:
當想識別圖片中中文時就會報錯,這時就需要引入新的語言庫,tesseract中只有二種語言包
在這裏插入圖片描述
在這裏插入圖片描述
語言庫下載地址:https://github.com/tesseract-ocr/tessdata
在這裏插入圖片描述
將下載下來的語言包放到改路徑下即可,放完之後可以輸入tesseract --list-langs驗證是否成功
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

import pytesseract
from PIL import Image

image = Image.open("../img/4.png")
code = pytesseract.image_to_string(image,lang="chi_sim")
print(code)

任何插件都有自身缺陷,所以。。。。
有什麼大家不理解,趕緊問我免得我老是忘記,好哈哈哈哈

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章