国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python編程實現的圖片識別功能示例

2020-02-16 02:00:31
字體:
來源:轉載
供稿:網友

本文實例講述了Python編程實現的圖片識別功能。分享給大家供大家參考,具體如下:

1. 安裝PIL,官方沒有WIN64位,Pillow替代

pip install Pillow-2.7.0-cp27-none-win_amd64.whl

2. 安裝Pytesser

下載pytesser_v0.0.1.zip,解壓后復制進Python27/Lib/site-packges/pytesser路徑下,無pytesser則新建

在Python27/Lib/site-packges/pytesser中新建一pytesser.pth文件,內容為pytesser

在pytesser內,修改三點

① 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' 注意/轉義

③ 安裝Tesseract

下載Tesseract OCR engine:http://code.google.com/p/tesseract-ocr/ ,

下載后解壓,找到tessdata文件夾,用其替換掉pytesser解壓后的tessdata文件夾即可。

不過除了測試用驗證碼之外,其余的系統驗證碼的識別率很低。

附測試代碼

from pytesser import *from PIL import Image, ImageEnhanceim = 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')  #灰度處理#灰度處理基礎上二值化處理threshold = 140table = []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

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭阳县| 庆元县| 龙岩市| 阿鲁科尔沁旗| 阿拉善左旗| 松滋市| 汶上县| 蕲春县| 孟津县| 盐津县| 孟村| 察雅县| 栾川县| 尉犁县| 辽宁省| 通道| 肥东县| 北宁市| 柳江县| 康乐县| 贡觉县| 高要市| 诸城市| 陵川县| 曲周县| 开原市| 吉隆县| 五莲县| 惠安县| 石狮市| 昭觉县| 阿巴嘎旗| 平昌县| 深州市| 龙川县| 高台县| 疏附县| 钟山县| 芮城县| 五原县| 天峻县|