使用scikit-learn KMeans实现验证码的字符切分

字符切分是实现机器识别验证码的一个必要步骤。

验证码样本如下图所示:

验证码原始图

使用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 ...

继续阅读

[LeetCode]Additive Number

题目描述:

Additive number is a positive integer whose digits can form additive sequence.

A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of ...

继续阅读

年度归档