最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python验证码识别实例代码
时间:2018-02-03 编辑:猪哥 来源:一聚教程网
本文研究的主要是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=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()
-
下一个: PHP实现正则表达式分组捕获操作示例
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27