dolla_one_recognizer_python
A Python 3 implementation of the $1 Unistroke Recognizer.
詳しい日本語の解説は README.ja.md にあります。
What is this
The $1 Unistroke Recognizer is a lightweight single-stroke gesture recognition algorithm by Wobbrock, Wilson, and Li (UIST '07). It needs no machine-learning training: register just one template per shape and it works. It resamples the input stroke to a fixed number of points, normalizes rotation, scale, and position, then picks the nearest registered template.
Input is a plain list of points [[x, y], ...], so the coordinates can come from a
mouse, touch input, or a tracker such as OpenCV optical flow / color / fingertip
tracking — just append each frame's (x, y) and pass the list in.
This repository contains the recognizer itself, packaged as dolla_one_recognizer_py/,
plus two small Tkinter demo apps: export_gesture_app.py (draw and save gesture
templates) and recognize_app.py (match a drawn stroke against saved templates).
Install
pip install dolla-one-recognizer-py
This installs the recognizer itself (dolla_one_recognizer_py), depending only on numpy.
To also try the GUI demo apps (export_gesture_app.py / recognize_app.py), clone the
repo instead, which additionally installs pillow for PNG I/O:
git clone https://github.com/yuzujelly2222/dolla_one_recognizer_python.git
cd dolla_one_recognizer_python
pip install -r requirements.txt
Usage
from dolla_one_recognizer_py import dolla_one_recognizer
# Register templates — one example stroke per shape is enough
line_template = [[x, x] for x in range(0, 101, 5)]
check_template = [[0, 30], [30, 0], [90, 60]]
recognizer = dolla_one_recognizer(
size=250,
templates=[line_template, check_template],
templates_name=["line", "checkmark"],
n=64,
)
# Raw points to recognize (e.g. collected from a mouse drag)
query = [[x, x * 0.9 + 2] for x in range(0, 101, 4)]
best_points, best_name, score = recognizer.recognize(query)
print(best_name, score) # -> line 0.96...
Try the GUI demos:
python export_gesture_app.py # draw and save to gestures/ as CSV + PNG
python recognize_app.py # auto-load gestures/ and test recognition
How it works
$1 applies four steps to the input points and returns the nearest template:
- Resample (
_resample) ton(default 64) evenly spaced points, absorbing differences in drawing speed. - Rotate (
_rotate_to_zero) so the angle from the centroid to the first point is zero. - Scale & translate (
_scale_to_square->_translate_to_origin) into asize x sizesquare (default 250) centered at the origin. - Match (
recognize) against each template, searching +/-45 degrees for the rotation that minimizes the average point-to-point distance (Golden Section Search), and return the closest. The distance is converted to a 0-1 score.
The Protractor enhancement (a closed-form optimal angle instead of the search) is not included in this implementation. See README.ja.md for a fuller walkthrough.
API
Only the members below are part of the public API; the geometry helpers are prefixed
with _ and are internal.
| Member | Description |
|---|---|
__init__(size, templates, templates_name, n) |
Initialize with a list of template strokes and their names |
add_template(points, name) |
Add one more template |
recognize(points) |
Normalize a raw stroke, match all templates, return (best_points, best_name, score) |
__init__ and add_template validate their input and raise ValueError when:
sizeis not > 0, ornis not > 1templatesandtemplates_namehave different lengths- a template has fewer than 2 points
- a template name is empty/whitespace-only, or already registered (names are trimmed)
Documentation & tests
A Sphinx-generated API reference lives in docs/ (source in docs_src/), published via
GitHub Pages. To rebuild it locally:
pip install sphinx sphinx-rtd-theme
sphinx-build -b html docs_src docs
A pytest suite covering the recognizer lives in tests/:
pip install pytest
pytest
License & citation
Distributed under the New BSD License — see LICENSE.
This is an independent implementation based on the pseudocode from the paper below. The original authors and copyright holders exist separately from this port.
Wobbrock, J.O., Wilson, A.D. and Li, Y. (2007). Gestures without libraries, toolkits or training: A $1 recognizer for user interface prototypes. Proceedings of the ACM Symposium on User Interface Software and Technology (UIST '07), pp. 159-168.
Official site (algorithm, pseudocode, reference implementation): https://depts.washington.edu/acelab/proj/dollar/index.html
Release files for dolla-one-recognizer-py 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dolla_one_recognizer_py-1.0.0.tar.gz | 14.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dolla_one_recognizer_py-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / dolla_one_recognizer_py-1.0.0.tar.gz
| Download URL | dolla_one_recognizer_py-1.0.0.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8def2179f4095a36fa813a67c20637f9e66563e6320cf086c7aa30eb04a90f6
|
|
BLAKE2b-256 checksum How to use checksums |
52cadfd5812874e9613cdb253218183687bd8fa562083f4986ed3a3ce72a2bac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / dolla_one_recognizer_py-1.0.0-py3-none-any.whl
| Download URL | dolla_one_recognizer_py-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3223febe96a324a036cf4f4cd287a1cce5c43766b498027db69495d966b193ce
|
|
BLAKE2b-256 checksum How to use checksums |
bb709eebaa24406f1a539537aa61525b06acbaef643a319a7e688143b710ca54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|