Implementation of the $N Multistroke Recognizer, in TypeScript/UMD package.
simply:
npm install ndollar-js
or for web browsers,
<script src="../dist/nDollar.js"></script>
var nDollar = require("ndollar-js");
var useBoundedRotationInvariance = true;
var recognizer = new nDollar.Recognizer( useBoundedRotationInvariance );
recognizer.LoadDefaultGestures( );
var triangle = [[new nDollar.Point(30, 7), new nDollar.Point(103, 7)],
[new nDollar.Point(103, 7), new nDollar.Point(66, 87)],
[new nDollar.Point(66, 87), new nDollar.Point(30, 7)]
];
recognizer.AddGesture( "triangle", triangle);
var myHandDrawingOfTriangle = [ [new nDollar.Point(20, 7), new nDollar.Point(54, 8), new nDollar.Point(100, 10)],
[new nDollar.Point(103, 7), new nDollar.Point(82, 47), new nDollar.Point(66, 87)],
[new nDollar.Point(66, 87), new nDollar.Point(45, 45), new nDollar.Point(30, 7)]
];
result = recognizer.recognize( myHandDrawingOfTriangle, requireSameNoOfStrokes, useProtractor);
/*
result = { Name: "triangle", Score: 8.076 }
*/
var useBoundedRotationInvariance = true;
var recognizer = new nDollar.Recognizer(useBoundedRotationInvariance);
var strokes = [];
var stroking = []
recognizer.LoadDefaultGestures( );
var triangle = [[new nDollar.Point(30, 7), new nDollar.Point(103, 7)],
[new nDollar.Point(103, 7), new nDollar.Point(66, 87)],
[new nDollar.Point(66, 87), new nDollar.Point(30, 7)]
];
recognizer.AddGesture( "triangle", triangle);
var myHandDrawingOfTriangle = [ [new nDollar.Point(20, 7), new nDollar.Point(54, 8), new nDollar.Point(100, 10)],
[new nDollar.Point(103, 7), new nDollar.Point(82, 47), new nDollar.Point(66, 87)],
[new nDollar.Point(66, 87), new nDollar.Point(45, 45), new nDollar.Point(30, 7)]
];
result = recognizer.recognize( myHandDrawingOfTriangle, requireSameNoOfStrokes, useProtractor);
/*
result = { Name: "triangle", Score: 8.076 }
*/
You can check [https://depts.washington.edu/aimgroup/proj/dollar/ndollar.html] to get the idea of what it's can do and parameters you can play with.
The Recognizer class is the main clas who do all the works. We can just create instance by
var recognizer = new nDollar.Recognizer( useBoundedRotationInvariance );
Then we need to add knowledge to it by either loading defaults or create your own gestures.
recognizer.LoadDefaultGestures( )
This load pre-built 16 shapes of gestures same as in the original.
Or you can create your own shapes
var triangle = [[new nDollar.Point(30, 7), new nDollar.Point(103, 7)],
[new nDollar.Point(103, 7), new nDollar.Point(66, 87)],
[new nDollar.Point(66, 87), new nDollar.Point(30, 7)]
];
recognizer.AddGesture( "triangle", triangle);
Then you can test your gesture to the recognizer.
result = recognizer.recognize( handDrawingOfTriangle, requireSameNoOfStrokes, useProtractor);
- useBoundedRotationInvariance : Strict the orientation of shape, If this is
true
, It's will not match the shape if it's too much different angle. - requireSameNoOfStrokes : Match the shape only when stroke count is equal.
- useProtractor : select alghorithm to compare shape, between original Golden Section Search and Protactor search.