python驗證碼識別實例代碼
更新時間:2018年02月03日 11:07:03 作者:linzch3
這篇文章主要介紹了python驗證碼識別實例代碼,分享了相關代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
本文研究的主要是Python驗證碼識別的相關代碼,具體如下。
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轉換成numpy的array類型,方便后續(xù)運算操作 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()
總結
以上就是本文關于python驗證碼識別實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關文章
如何使用django-treebeard實現樹類型存儲與編輯
這篇文章主要介紹了使用django-treebeard實現樹類型存儲與編輯的宣相關操作代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-08-08使用PyInstaller將python轉成可執(zhí)行文件exe筆記
這篇文章主要介紹了使用PyInstaller將python轉成可執(zhí)行文件exe筆記,需要的朋友可以參考下2018-05-05influx+grafana自定義python采集數據和一些坑的總結
一些數據的類型不正確會導致no datapoint的錯誤,真是令人抓狂,本文就是總結一下采集數據種的一些坑,希望大家可以從中獲益2018-09-09