Python編程實(shí)現(xiàn)的圖片識別功能示例
本文實(shí)例講述了Python編程實(shí)現(xiàn)的圖片識別功能。分享給大家供大家參考,具體如下:
1. 安裝PIL,官方?jīng)]有WIN64位,Pillow替代
pip install Pillow-2.7.0-cp27-none-win_amd64.whl
2. 安裝Pytesser
下載pytesser_v0.0.1.zip,解壓后復(fù)制進(jìn)Python27\Lib\site-packges\pytesser路徑下,無pytesser則新建
在Python27\Lib\site-packges\pytesser中新建一pytesser.pth文件,內(nèi)容為pytesser
在pytesser內(nèi),修改三點(diǎn)
① pytesser.py修改成__init.py__
② 修改pytesser.py
import Image
改為
from PIL import Image
tesseract_exe_name = 'tesseract' 改為tesseract_exe_name = 'Python27\\Lib\\site-packges\\pytesser\\tesseract' 注意\轉(zhuǎn)義
③ 安裝Tesseract
下載Tesseract OCR engine:http://code.google.com/p/tesseract-ocr/ ,
下載后解壓,找到tessdata文件夾,用其替換掉pytesser解壓后的tessdata文件夾即可。
不過除了測試用驗(yàn)證碼之外,其余的系統(tǒng)驗(yàn)證碼的識別率很低。
附測試代碼
from pytesser import * from PIL import Image, ImageEnhance im = Image.open('D:\Python27\Lib\site-packages\pytesser\phototest.tif') im2 = Image.open(r'D:\Python27\Lib\site-packages\pytesser\fnord.tif','r') im3 = Image.open(r'F:\PROJECT\python\code\Study_1\src\20170424\cp.jpg','r') #文件讀寫模式以防報錯 #圖片處理1::黑白處理 enhancer = ImageEnhance.Contrast(im3) image2 = enhancer.enhance(5) image2.show() print image_to_string(image2) #圖片處理2: 降噪處理 imgry = im3.convert('L') #灰度處理 #灰度處理基礎(chǔ)上二值化處理 threshold = 140 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) out = imgry.point(table, '1') out.show() text = image_to_string(out) if text.isspace() : print "FAILE" else: print text #print text
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python操作MySQL數(shù)據(jù)庫的簡單步驟分享
這篇文章主要給大家介紹了關(guān)于Python操作MySQL數(shù)據(jù)庫的簡單步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04python中關(guān)于requests里的timeout()用法
這篇文章主要介紹了python中關(guān)于requests里的timeout()用法,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08python dict 字典 以及 賦值 引用的一些實(shí)例(詳解)
下面小編就為大家?guī)硪黄猵ython dict 字典 以及 賦值 引用的一些實(shí)例(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01PyCharm vs VSCode,作為python開發(fā)者,你更傾向哪種IDE呢?
這篇文章主要介紹了PyCharm和vscode作為python ide的優(yōu)劣,幫助你選擇適合自己的ide,感興趣的朋友可以了解下2020-08-08