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.
Control Center gives you instant access to the things you do the most. You can use Control Center to quickly take a picture, turn on Wi-Fi, control your Apple TV, and more.
To lower the top half of the screen, do one the following: On an iPhone with Face ID: Swipe down on the bottom edge of the screen. On an iPhone with a Home button: Lightly double-tap the Home button.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With