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.


Chris Miles

November 15, 2012

More Decks by Chris Miles

Other Decks in Programming


  1. $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
  2. $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
  3. 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
  4. Step 3: Scale & Translate Scale to a reference square

    Translate the centroid to (0,0) Friday, 8 February 13
  5. 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
  6. 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
  7. 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
  8. 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
  9. @interface CMUnistrokeGestureRecognizer : UIGestureRecognizer @property (nonatomic, weak) id<CMUnistrokeGestureRecognizerDelegate> 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