-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecognizer.qml
46 lines (40 loc) · 1.27 KB
/
Recognizer.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import QtQuick 2.2
import "QClassifier.js" as QClassifier
Item {
id:recognizer
property var _points: new Array();
property var _strokeID: 0
property var _r: new QClassifier.QDollarRecognizer();
function addGesture(name){
_r.AddGesture(name,_points)
_strokeID = 0
}
function recognize(){
if (_points.length >= 5) {
var result = _r.Recognize(_points);
console.log("Result: " + result.Name + " (" + result.Score.toFixed(2) + ") in " + result.Time + " ms.");
figures.createFigure(result.Name, _points)
}
else {
console.log("Too little input made. Please try again.");
}
_strokeID = 0
}
function newStroke(x,y){
if (_strokeID == 0) { // starting a new gesture
_points.length = 0;
}
++_strokeID;
}
function addPoint(x,y){
_points[_points.length] = new QClassifier.Point(x, y, _strokeID); // append
}
Component.onCompleted: {
var data=fileio.read("/src/authoring-gui/res/gestures.json")
figures.types = _r.Init(data);
}
Component.onDestruction: {
var string = recognizer._r.GetUserGestures()
fileio.write("/src/authoring-gui/res/gestures2.json",string)
}
}