①安裝PIL:pip install Pillow(之前的博客中有寫過)
②安裝pytesser3:pip install pytesser3
③安裝pytesseract:pip install pytesseract
④安裝autopy3:
先安裝wheel:pip install wheel
下載autopy3-0.51.1-cp36-cp36m-win_amd64.whl【點(diǎn)擊打開鏈接】
執(zhí)行命令:pip install E:/360安全瀏覽器下載/autopy3-0.51.1-cp36-cp36m-win_amd64.whl
##使用pip install autopy3時(shí)會報(bào)錯(cuò)如下:

④安裝Tesseract-OCR:百度直接搜索Tesseract-OCR下載即可
這里要說明的是安裝Tesseract-OCR后,其不會被默認(rèn)添加至環(huán)境變量path中,已導(dǎo)致如下報(bào)錯(cuò):

解決辦法有兩種:(先找到Tesseract-OCR安裝文件夾,再找到tesseract.exe文件)
我這里的絕對路徑是:D:/python/Tesseract-OCR/tesseract.exe
①將此路徑添加至環(huán)境變量path中(不過我是這么做的,但是PyCharm仍舊報(bào)錯(cuò))
②找到pytesseract.py文件
我這里是C:/Users/admin/AppData/Local/Programs/Python/Python36/Lib/site-packages/pytesseract/pytesseract.py
將文件中的tesseract_cmd修改為上方的絕對路徑

進(jìn)入正題,如何識別圖像中文字
上原圖:(這句是海上鋼琴師中的一句經(jīng)典臺詞)

接下來我們要通過python的pytesseract來識別圖片中的字符了
# _*_ coding:utf-8 _*_ import pytesseract from PIL import Image __author__ = 'admin' im = Image.open(r'C:/Users/admin/Desktop/example.png') print(pytesseract.image_to_string(im))
效果圖

以上這篇Python圖像處理之識別圖像中的文字(實(shí)例講解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長站。
新聞熱點(diǎn)
疑難解答
圖片精選