在 Python 中查找最相似的形状
我正在开发一个虚拟键盘,类似于 Swype(但对于它不支持的平台)。基本上,它的作用(对于那些不熟悉的人来说)是您在按键上移动手指,而无需为每个单词抬起手指。所以我需要做的是将绘制的形状与单词列表中每个单词的形状进行比较,并使用最相似的形状。我的问题是:如何找到最相似的形状?
编辑:我尝试了 $1 识别器的 Python 实现,但解析我的 32,000 个单词的单词列表需要近 7 分钟。有没有办法可以加快速度(或者至少预先计算)?这是我用来生成它的内容:
self.keylayout = ["qwertyuiop","asdfghjkl;","zxcvbnm,."]
for i in wl:
points = []
for j in i:
if j.lower() in self.keylayout[0]:
points.append((40, self.keylayout[0].index(j.lower())*48+24))
elif j.lower() in self.keylayout[1]:
points.append((120, self.keylayout[1].index(j.lower())*48+24))
elif j.lower() in self.kl[2]:
points.append((200, self.keylayout[2].index(j.lower())*48+24))
self.rec = Recognizer()
self.rec.addTemplate(i, points)
I am working on a virtual keyboard, similar to Swype (but for a platform it doesn't support). Basically, what it does (for those not familiar) is you move your finger over the keys without lifting it off for each word. So what I need to do is compare the shape drawn to the shape of each word in the wordlist, and use the most similar one. My problem is: How do I find the most similar shape?
Edit: I tried the Python implementation of the $1 recognizer, but it takes nearly 7 minutes to parse my 32,000 word wordlist. Is there a way I can speed this up (or at least precompute it)? Here is what I am using to generate it:
self.keylayout = ["qwertyuiop","asdfghjkl;","zxcvbnm,."]
for i in wl:
points = []
for j in i:
if j.lower() in self.keylayout[0]:
points.append((40, self.keylayout[0].index(j.lower())*48+24))
elif j.lower() in self.keylayout[1]:
points.append((120, self.keylayout[1].index(j.lower())*48+24))
elif j.lower() in self.kl[2]:
points.append((200, self.keylayout[2].index(j.lower())*48+24))
self.rec = Recognizer()
self.rec.addTemplate(i, points)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以前写过这个。稍微不同的方法,速度相当快。希望它有帮助..
http://krishnabharadwaj.info/how-swype-works/
Had written this sometime back. A slightly different approach, It is pretty fast. hope it helps..
http://krishnabharadwaj.info/how-swype-works/
查看 JavaScript 中的 1 美元单笔划识别器。真是太糟糕了。
Check out the $1 Unistroke Recognizer in JavaScript. It is badass.