字符切分是实现机器识别验证码的一个必要步骤。
使用PIL读入图像,进行二值化处理(Binarize),然后利用sklearn.cluster中的kmeans进行字符切分,最后用matplotlib.pyplot输出结果。
参考:http://dsp.stackexchange.com/questions/23662/k-means-for-2d-point-clustering-in-python
Python代码:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from PIL import Image
##############################################################################
# Binarize image data
im = np.array(Image.open('zftb.gif'))
h, w = im.shape
X = [(h - x, y) for x ...