gestrec
A JavaScript implementation of the Protractor gesture recognizer.
This package provides a JavaScript version of Yang Li's Protractor gesture recognizer. The code is a close port of the Java version that ships as part of the Google Android distribution.
Usage
The gesture recognizer can be used both server-side and client-side. For use in node.js, simply npm install gestrec
or include gestrec as a dependency in your package.json file. For use on the client, simply import gestrec.min.js in the browser.
Example
var gestrec = ;var store = ; // a stroke is a collection of timestamped pointsvar stroke = // gestrec.Point( x, y, t) 2 5 1 2 9 2;// a gesture is a collection of one or more strokesvar gesture = stroke; // build a recognizer by providing gesture training examples// repeat to provide multiple examples for each named gesture classstore; // gestures can be read from JSON-style objectsvar down = gestrecGesture left = gestrecGesture; // recognize a matching (high-scoring) gesturevar prediction = store;console;// [{"name":"line_down","score":67108864}] // recognize a non-matching (low-scoring) gestureprediction = store;console;// [{"name":"line_down","score":0.6366197723675814}]
Gesture Training Application
A gesture training application is available online at http://uwdata.github.io/gestrec/.
The application is intended to work with both mouse and touch input. The code for the training application is included in this repository under the trainer
folder. Simply open the index.html
file in a browser to run locally.
Build Process
We use the gulp build system along with browserify to build gestrec.min.js.
- Install gulp, as needed. Follow step 1 on the Gulp Getting Started guide.
- Run
npm install
in the gestures folder to install dependencies. - Run
gulp
.