【发布时间】:2016-03-11 01:11:30
【问题描述】:
我刚刚写了这个非常简单的手写数字识别。 Here is 8kb archive 使用以下代码 + 十个 .PNG 图像文件。它有效: 被公认为。
简而言之,数据库的每个数字(50x50 像素 = 250 个系数)汇总为 10 个系数向量(通过保留 10 个最大奇异值,请参阅 Low-rank approximation with SVD)。
然后对于要识别的数字,我们最小化与数据库中数字的距离。
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
digits = []
for i in range(11):
M = misc.imread(str(i) + '.png', flatten=True)
U, s, V = np.linalg.svd(M, full_matrices=False)
s[10:] = 0 # keep the 10 biggest singular values only, discard others
S = np.diag(s)
M_reduced = np.dot(U, np.dot(S, V)) # reconstitution of image with 10 biggest singular values
digits.append({'original': M, 'singular': s[:10], 'reduced': M_reduced})
# each 50x50 pixels digit is summarized into a vector of 10 coefficients : the 10 biggest singular values s[:10]
# 0.png to 9.png = all the digits (for machine training)
# 10.png = the digit to be recognized
toberecognizeddigit = digits[10]
digits = digits[:10]
# we find the nearest-neighbour by minimizing the distance between singular values of toberecoginzeddigit and all the digits in database
recognizeddigit = min(digits[:10], key=lambda d: sum((d['singular']-toberecognizeddigit['singular'])**2))
plt.imshow(toberecognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()
plt.imshow(recognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()
问题:
代码有效(您可以运行 ZIP 存档中的代码),但我们如何改进它以获得更好的结果?(我想象的主要是数学技术)。
例如在我的测试中,9 和 3 有时会相互混淆。
【问题讨论】:
-
我在使用这个OCR and character similarity 的失真和非常嘈杂的数字(非手绘)方面或多或少取得了成功,您可以尝试一下...您可以创建每个数字具有更多版本的参考字体轻松识别
标签: python math ocr data-analysis svd