pythonvectorcomparisonvirtual-keyboardn900

Find most similar shapes in Python


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)

Solution

  • Had written this sometime back. A slightly different approach, It is pretty fast. hope it helps..

    http://krishnabharadwaj.info/how-swype-works/