归档 2015年11月

[LeetCode]Minimum Depth of Binary Tree

题目描述:

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

题目大意:

给定一棵二叉树,计算其最小深度。

最小深度是指从根节点出发到达最近的叶子节点所需要经过的节点个数。

解题思路:

DFS或者BFS均可,详见代码。

Python代码(DFS ...

继续阅读

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

继续阅读

每日归档

上个月

下个月

归档