python驗(yàn)證碼識別實(shí)例代碼
本文研究的主要是Python驗(yàn)證碼識別的相關(guān)代碼,具體如下。
Talk is cheap, show you the Code!
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from PIL import Image
#打開圖像
im=np.array(Image.open('yzm.png'))
#得到圖像3個維度
h,w,san=im.shape
X=[(h-x,y) for x in range(h) for y in range (w) if im[x][y][2]<200]
#將X轉(zhuǎn)換成numpy的array類型,方便后續(xù)運(yùn)算操作
X=np.array(X)
n_clusters=4
k_means=KMeans(init='k-means++',n_clusters=n_clusters)
k_means.fit(X)
k_means_labels=k_means.labels_
k_means_cluster_centers=k_means.cluster_centers_
k_means_labels_unique=np.unique(k_means_labels)
colors=['#4EACC5','#FF9C34','#4E9A06','#FF3300']
plt.figure()
plt.hold(True)
for k,col in zip(range(n_clusters),colors):
my_members=k_means_labels==k
cluster_center=k_means_cluster_centers[k]
plt.plot(X[my_members,1],X[my_members,0],'w',markerfacecolor=col,marker='.')
plt.plot(cluster_center[1],cluster_center[0],'o',markerfacecolor=col,markeredgecolor='k',markersize=6)
plt.title('KMeans')
plt.grid(True)
plt.show()
總結(jié)
以上就是本文關(guān)于python驗(yàn)證碼識別實(shí)例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
Python簡單調(diào)用MySQL存儲過程并獲得返回值的方法
這篇文章主要介紹了Python調(diào)用MySQL存儲過程并獲得返回值的方法,涉及Python操作MySQL存儲過程的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
在IPython中進(jìn)行Python程序執(zhí)行時間的測量方法
今天小編就為大家分享一篇在IPython中進(jìn)行Python程序執(zhí)行時間的測量方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11
pytorch實(shí)現(xiàn)線性回歸以及多元回歸
這篇文章主要為大家詳細(xì)介紹了pytorch實(shí)現(xiàn)線性回歸以及多元回歸,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-04-04
python實(shí)現(xiàn)12306登錄并保存cookie的方法示例
這篇文章主要介紹了 python實(shí)現(xiàn)12306登錄并保存cookie的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Python+selenium實(shí)現(xiàn)自動循環(huán)扔QQ郵箱漂流瓶
這篇文章主要為大家詳細(xì)介紹了Python+selenium實(shí)現(xiàn)自動循環(huán)扔QQ郵箱漂流瓶,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05

