本文介紹了python使用tensorflow深度學(xué)習(xí)識(shí)別驗(yàn)證碼 ,分享給大家,具體如下:
除了傳統(tǒng)的PIL包處理圖片,然后用pytessert+OCR識(shí)別意外,還可以使用tessorflow訓(xùn)練來識(shí)別驗(yàn)證碼。
此篇代碼大部分是轉(zhuǎn)載的,只改了很少地方。
代碼是運(yùn)行在linux環(huán)境,tessorflow沒有支持windows的python 2.7。
gen_captcha.py代碼。
#coding=utf-8 from captcha.image import ImageCaptcha # pip install captcha import numpy as np import matplotlib.pyplot as plt from PIL import Image import random # 驗(yàn)證碼中的字符, 就不用漢字了 number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] ''' number=['0','1','2','3','4','5','6','7','8','9'] alphabet =[] ALPHABET =[] ''' # 驗(yàn)證碼一般都無視大小寫;驗(yàn)證碼長度4個(gè)字符 def random_captcha_text(char_set=number + alphabet + ALPHABET, captcha_size=4): captcha_text = [] for i in range(captcha_size): c = random.choice(char_set) captcha_text.append(c) return captcha_text # 生成字符對(duì)應(yīng)的驗(yàn)證碼 def gen_captcha_text_and_image(): while(1): image = ImageCaptcha() captcha_text = random_captcha_text() captcha_text = ''.join(captcha_text) captcha = image.generate(captcha_text) #image.write(captcha_text, captcha_text + '.jpg') # 寫到文件 captcha_image = Image.open(captcha) #captcha_image.show() captcha_image = np.array(captcha_image) if captcha_image.shape==(60,160,3): break return captcha_text, captcha_image if __name__ == '__main__': # 測(cè)試 text, image = gen_captcha_text_and_image() print image gray = np.mean(image, -1) print gray print image.shape print gray.shape f = plt.figure() ax = f.add_subplot(111) ax.text(0.1, 0.9, text, ha='center', va='center', transform=ax.transAxes) plt.imshow(image) plt.show()
網(wǎng)頁題目:python使用tensorflow深度學(xué)習(xí)識(shí)別驗(yàn)證碼-創(chuàng)新互聯(lián)
文章路徑:http://chinadenli.net/article12/djjjgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、搜索引擎優(yōu)化、域名注冊(cè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站制作、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容