A drawing recognizer, implementing the $P Point-Cloud Recognizer algorithm to classify drawn shapes by comparing them against a set of template gestures.
This is the successor to an earlier unistroke-only version I made; this one adds multistroke gesture support and resolves the direction and rotation sensitivity issues the previous version had.
Live demo: refineddev.github.io/stroke-recognizer
The $P algorithm treats a gesture as an unordered "point cloud" rather than an ordered sequence of points, which is what makes it robust to variations in stroke direction, order, and number of strokes. A circle drawn clockwise or anti-clockwise, or a multistroke shape drawn in a different stroke order, still matches the same template. This is a direct improvement over the earlier $1 (unistroke) version, where drawing the same shape in a different direction could register as an entirely different gesture.
Matching is done by finding the point-to-point pairing between the input gesture and each template (the Greedy-5 algorithm), which runs in roughly O(n^(2+ε)) time. Despite using half the points of the earlier unistroke version (32 vs 64), it runs in about the same time with noticeably better recognition accuracy.
- Draw — left mouse button or space bar; touch supported on touchscreens
- Recognize — right mouse button, or the button in the bottom-right of the screen
- The millisecond timing shown in the WASM build is inaccurate — likely related to
wasm32-unknown-unknownnot having full access to the standard library's timing facilities. The native build doesn't have this issue and is also faster. For the best experience, build and run locally rather than using the web demo.
