Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CMUnistrokeGestureRecognizer - iOS port of $1 Unistroke Recognizer

Chris Miles
November 15, 2012

CMUnistrokeGestureRecognizer - iOS port of $1 Unistroke Recognizer

Introducing CMUnistrokeGestureRecognizer, my open source implementation of the $1 Unistroke Recognizer for iOS. Presented at Melbourne Cocoaheads Nov 2012.

http://blog.chrismiles.info/2012/12/introducing-cmunistrokegesturerecognizer.html
https://github.com/chrismiles/CMUnistrokeGestureRecognizer

Chris Miles

November 15, 2012
Tweet

More Decks by Chris Miles

Other Decks in Programming

Transcript

  1. CMUnistrokeGestureRecognizer
    Chris Miles
    Freelance Software Engineer iOS Specialist
    @chrismiles
    http:/
    /chrismiles.info/
    Friday, 8 February 13

    View full-size slide

  2. Infinity Blade
    Friday, 8 February 13

    View full-size slide

  3. Palm OS Graffiti
    Friday, 8 February 13

    View full-size slide

  4. Unistroke Gesture
    Friday, 8 February 13

    View full-size slide

  5. $1 Unistroke Recognizer
    http:/
    /depts.washington.edu/aimgroup/proj/dollar/
    Friday, 8 February 13

    View full-size slide

  6. $1 Goals
    Resilient to movement & sampling
    speed
    Rotation, scale, position invariance
    No advanced maths (e.g., matrix
    inversions, derivatives, integrals)
    Easily written with few lines of code
    Friday, 8 February 13

    View full-size slide

  7. $1 Goals
    Fast enough for interactive use
    Define gestures with minimum of only
    one example
    Return top results ordered by score [0-1]
    Provide recognition rates that are
    competitive with more complex
    algorithms
    Friday, 8 February 13

    View full-size slide

  8. Friday, 8 February 13

    View full-size slide

  9. Friday, 8 February 13

    View full-size slide

  10. Friday, 8 February 13

    View full-size slide

  11. Step 1: Resample
    Resample to N equidistantly spaced
    points
    32 ≤ N ≤ 256
    Friday, 8 February 13

    View full-size slide

  12. Step 2: Rotate
    Rotate to "Indicative Angle"
    Indicative Angle is the angle required
    to rotate the gesture’s first point to 0°
    about the centroid of the gesture
    Friday, 8 February 13

    View full-size slide

  13. Step 3: Scale & Translate
    Scale to a reference square
    Translate the centroid to (0,0)
    Friday, 8 February 13

    View full-size slide

  14. Step 4: Recognise
    Calculate the average distance di
    between corresponding points of
    candidate C and each template Ti
    This is the "Path-Distance"
    Friday, 8 February 13

    View full-size slide

  15. Step 4: Recognise
    The template Ti with the least path-
    distance to C is the winner
    Calculate a [0-1] score with:
    Friday, 8 February 13

    View full-size slide

  16. Step 4: Recognise
    Optional: Rotation Invariance
    Attempt to align two gestures C and
    Ti more optimally
    A strategy called Golden Section
    Search is used to scan best fit
    between ±45° from indicative angle
    with threshold 2°
    Friday, 8 February 13

    View full-size slide

  17. Step 4: Recognise
    Alternatively: Protractor method
    Similar steps 1-3: Resample, rotate,
    scale & translate
    Step 4 compares a vector
    representation of the gesture against
    templates using Optimal-Cosine-
    Distance
    Friday, 8 February 13

    View full-size slide

  18. CMUnistrokeGestureRecognizer
    UIGestureRecognizer
    Core algorithm implemented in C
    GLKMath for optimal vector math
    Friday, 8 February 13

    View full-size slide

  19. @interface CMUnistrokeGestureRecognizer : UIGestureRecognizer
    @property (nonatomic, weak) id
    unistrokeDelegate;
    @property (nonatomic, assign) float minimumScoreThreshold;
    @property (nonatomic, assign) BOOL protactorMethodEnabled;
    @property (nonatomic, assign) BOOL rotationInvarianceEnabled;
    @property (nonatomic, strong, readonly) CMUnistrokeGestureResult *result;
    @property (nonatomic, strong, readonly) UIBezierPath *strokePath;
    - (void)registerUnistrokeWithName:(NSString *)name bezierPath:
    (UIBezierPath *)path;
    - (void)clearAllUnistrokes;
    @end
    Friday, 8 February 13

    View full-size slide

  20. @protocol CMUnistrokeGestureRecognizerDelegate
    @optional
    - (void)unistrokeGestureRecognizer:(CMUnistrokeGestureRecognizer
    *)unistrokeGestureRecognizer isEvaluatingStrokePath:(UIBezierPath
    *)strokePath;
    - (void)unistrokeGestureRecognizerDidFailToRecognize:
    (CMUnistrokeGestureRecognizer *)unistrokeGestureRecognizer;
    @end
    Friday, 8 February 13

    View full-size slide

  21. $N Multistroke Recognizer
    Friday, 8 February 13

    View full-size slide

  22. $P Point-Cloud Recognizer
    Friday, 8 February 13

    View full-size slide

  23. Friday, 8 February 13

    View full-size slide

  24. https:/
    /github.com/chrismiles/CMUnistrokeGestureRecognizer
    Chris Miles
    @chrismiles
    http:/
    /chrismiles.info/
    Friday, 8 February 13

    View full-size slide