Python實現識別圖片內容的方法分析
本文實例講述了Python實現識別圖片內容的方法。分享給大家供大家參考,具體如下:
python識別圖片內容。
這里我的環(huán)境為windows64位,python2.7.14
需要用到PIL模塊和tesseract模塊。
首先需要安裝pip包管理,安裝方法可參考附錄windows下安裝python包管理器pip
安裝PIL模塊:
pip install Pillow
tesseract模塊安裝:
pip install pytesseract
安裝識別引擎和中文語言包,點擊此處本站下載。
下載完成解壓:
1.雙擊tesseract-ocr-setup-3.02.02.exe安裝,安裝完成后,需要指定tesseract模塊識別引擎的程序路徑,打開python安裝路徑的模塊路徑,我的路徑為:E:\wamp\python\Lib\site-packages\,進入pytesseract,編輯pytesseract.py文件,修改 tesseract_cmd = 'tesseract'
的內容:
# tesseract_cmd = 'tesseract' # 修改為安裝Tesseract-OCR的真實路徑
tesseract_cmd = 'E:/wamp/python modules/Tesseract-OCR/tesseract.exe'
2.進入解壓包中的中文語言包,復制chi_sim.traineddata到Tesseract-OCR安裝目錄下tessdata文件夾下,我的路徑:E:\wamp\python modules\Tesseract-OCR\tessdata\chi_sim.traineddata
環(huán)境配置完成。
python代碼:
# -*- coding: UTF-8 -*- from PIL import Image import pytesseract # 識別中文 text = pytesseract.image_to_string(Image.open('chinese.png'),lang='chi_sim') print text # 識別英文 text = pytesseract.image_to_string(Image.open('english.png')) print text
windows下安裝python包管理器pip。
pip下載地址:https://pypi.python.org/pypi/pip#downloads
選擇 pip-9.0.1.tar.gz (md5, pgp)
下載完成解壓,這里我解壓到D:\python\pip-9.0.1,命令行進入D:\python\pip-9.0.1
cd D:\python\pip-9.0.1
安裝pip
python setup.py install
安裝完成,輸入pip list
查看是否成功
pip list
顯示下面信息代表安裝成功:
pip (9.0.1)
setuptools (28.8.0)
pip安裝模塊命令:
pip install xxx
更多關于Python相關內容可查看本站專題:《Python數學運算技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
相關文章
python標準庫turtle海龜繪圖實現簡單奧運五環(huán)
這篇文章主要為大家介紹了python使用turtle實現最簡單簡單奧運五環(huán)繪圖,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05Python 解決空列表.append() 輸出為None的問題
在本篇文章里小編給大家整理了一篇關于Python 解決空列表.append() 輸出為None的問題的相關內容,有興趣的朋友們可以學習下。2021-05-05python數學建模之Numpy?應用介紹與Pandas學習
這篇文章主要介紹了python數學建模之Numpy?應用介紹與Pandas學習,NumPy?是一個運行速度非常快的數學庫,一個開源的的python科學計算庫,主要用于數組、矩陣計算2022-07-07