Reputation: 873
I'm planning on letting a user draw the shape of a number (1 to 9) in the shape of a 7-segment display. What is the best way to detect what number was drawn?
I know how to do all the touch-tracking and UIGestureRecogniser stuff - I'm looking for a good logic of doing it.
So far, I've got: When a touch moves from 1 half of a segment to the other, highlight that seg. Once touches are finished, check what segs have been highlighted and decide what number drawn.
Ways I've thought of improving it: Draw a shape of the finger's path on screen. If the line intersects the middle of a seg, highlight that seg.
Anyone got any tips or better ways of doing this? I'm open to any suggestion - even if it means scrapping all my code and starting from scratch.
Upvotes: 8
Views: 2560
Reputation: 14893
If you're interested in detecting the numbers 1-9, check out BGNumericalGlyphRecognizer. I spent several months working with an $N-multistroke recognizer to create ScribbleMath (a math app that allows kids to draw their answers on the screen) and open-sourced the core logic. It turns out $N recognizers have a hard time differentiating 6 and 9, and are also bad at recognizing very simple letters like 1 and "-", and I created logic for handling those better. It's not perfect, but it'll get you farther than an $N recognizer out of the box. Enjoy!
Upvotes: 3
Reputation: 12081
I've used implementations of the $ stroke recognizers for drawn number recognition.
Both algorithms link to several Objective-C / iOS implementations.
The recognizers will compare input against predefined patterns based on different algorithms (detailed explanation available on the linked pages). For this to work you'll have to make your own number patterns (basically just draw something and let the recognizer convert this to a data structure you store for later use). Then on user input compare to the patterns you recorded earlier to find a match.
The $1 recognizer was sufficient for my application where I would let the user train first to practice drawing the numbers. The $N recognizer is able to distinguish between more complex stokes and might accept more complex drawn numbers. This is something you will have to experiment with.
Upvotes: 7