python验证码识别实例代码

yipeiwu_com6年前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=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验证码识别实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

Python使用matplotlib绘图无法显示中文问题的解决方法

Python使用matplotlib绘图无法显示中文问题的解决方法

本文实例讲述了Python使用matplotlib绘图无法显示中文问题的解决方法。分享给大家供大家参考,具体如下: 在python中,默认情况下是无法显示中文的,如下代码: impo...

python多线程编程中的join函数使用心得

python多线程编程中的join函数使用心得

今天去辛集买箱包,下午挺晚才回来,又是恶心又是头痛。恶心是因为早上吃坏东西+晕车+回来时看到车祸现场,头痛大概是烈日和空调混合刺激而成。没有时间没有精神没有力气学习了,这篇博客就说说py...

对Python 简单串口收发GUI界面的实例详解

忙活了三个多小时,连学带做,总算是搞出来了一个具有基本功能的串口通信PC机的GUI界面,Tkinter在python中确实很好用,而且代码量确实也很少,不足的是Tkinter不自带com...

python3.4 将16进制转成字符串的实例

将socket收到的16进制转成字符串 def hex_to_str(b): s = '' for i in b: s += '{0:0>2}'.format...

Python实现基于HTTP文件传输实例

本文实例讲述了Python实现基于HTTP文件传输的方法。分享给大家供大家参考。具体实现方法如下: 一、问题: 因为需要最近看了一下通过POST请求传输文件的内容 并且自己写了Serve...