对 numpy 数组进行重新采样和标准化以进行手势识别
我将编写一个小应用程序来识别手势(现在使用鼠标)。
现在,将鼠标坐标记录在 Point 对象的 numpy 数组中(具有 x 和 y 属性的简单类)。 为了训练我的系统(基于 HMM),我需要(我认为......)一些在相同范围之间归一化的相同长度的样本。
举例来说,我需要一个 8 元素长度的数组来进行训练和分类器。 我刚刚记录了a1(5-len元素)和a2(9-len元素)。如何实现 len(a1)==len(a2)==8 ?
编辑:我找到了一个解释我的问题的网站: http://www.creativedistraction.com/演示/手势识别-kinect-with-hidden-markov-models-hmms/ 他使用 k-means 来减少 8 个簇中的元素。
解决方案:我有一些分散点(我不知道有多少),我想将其减少到 8 个有意义的点。我可以使用的技术之一是使用一些聚类算法对它们进行聚类。 KMeans 可能是一种可能性。在 scipy 中使用以下代码: from scipy.cluster.vq import kmeans2
def clusterize(numpy_array, n_cluster):
centroids, labels = kmeans2(numpy_array, n_cluster)
#print centroids, labels
return centroids
注意:如果 numpy_array 大小小于 n_cluster 我注意到解决方案不好,但在我的实际情况中,经过一些试验后我观察到我有超过 (numpy_array size>=60, n_cluster= 8).这是非常合乎逻辑的:k-means 不是一个确定性算法,而是一个涉及一些随机初始化的迭代过程,因为对于此类问题没有很好的分析解决方案(如果我理解得很好)。
当然,有一些我不想深入研究的数学见解。这样就可以完成工作了。
i'm going to write a little application to recognize gesture (for now with the mouse).
now, record the mouse coordinate in a numpy array of Point object (simple class with x and y attributes).
for training my system (based on HMM) i need (i think...) some sample of the same lenght normalized beetween the same range.
Say, for example, that i need an array of 8 element length for my training and for my classifier.
And i have just recordered a1( 5-len element ), and a2( 9-len element ). How to achive len(a1)==len(a2)==8 ?
EDIT: i found a website that explain my problem:
http://www.creativedistraction.com/demos/gesture-recognition-kinect-with-hidden-markov-models-hmms/
he uses k-means for reduce element in 8 cluster..
SOLUTION: i have some scattered points (i don't know how many) and i want to reduce it to a 8 meaning point. one of the technique i can use is to clusterize them with some cluster algorithms. KMeans could be one possibility. in scipy with this code:
from scipy.cluster.vq import kmeans2
def clusterize(numpy_array, n_cluster):
centroids, labels = kmeans2(numpy_array, n_cluster)
#print centroids, labels
return centroids
note: if numpy_array size is less then n_cluster i noticed that the solutions are not good, but in my real case after some trials i observed that i have more than (numpy_array size>=60, n_cluster=8). this is quite logical: k-means is not a deterministic alorightm but it is a iterative process that involved some random initialization, because there are no analitical good solution for this kind of problem (if i understood well).
for sure there are some mathematical insight that i don't want to delve into. this do the work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您所需要的,但这将从输入沿
n
均匀间隔的点进行线性插值。I'm not sure this is what you need, but this will linearly interpolate from the input along
n
evenly spaced points.