-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.html
175 lines (130 loc) · 5 KB
/
database.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<html>
<head>
<script src="https://js.leapmotion.com/leap-0.6.4.js"></script>
<script src="./public/assets/js/savefile.js"></script>
</head>
<body>
<h1>Recording Data from the Phalanges</h1>
<div id="output"></div>
<script src="https://js.leapmotion.com/leap-0.6.4.js"></script>
<script type="text/javascript">
function stdDeviation()
{
var mean_val = mean(values);
var sum = 0;
var distance = 0;
for (var i = 0; i < values.length; i++){
distance = values - mean_val;
sum += distance * distance;
}
return Math.sqrt(sum/values.length);
}
function mean(hands)
{
var sum = 0;
for (i = 0; i < values.length; i++){
sum += values[i];
}
return (sum / values.length);
}
var hands = [];
// Leap.loop uses browser's requestAnimationFrame
var options = { enableGestures: true };
var count = 0;
Leap.loop(options, function(frame) {
if(typeof frame.hands != "undefined" && frame.hands.length == 1)
{
var curr_hand = frame.hands[0];
console.log(count, typeof curr_hand);
var handStatus = {
confidence: curr_hand.confidence,
direction: curr_hand.direction,
fingers: {
mcpPosition: curr_hand.fingers.mcpPosition, pipPosition: curr_hand.fingers.pipPosition, dipPosition: curr_hand.dipPosition
},
palmPosition: curr_hand.palmPosition,
palmNormal: curr_hand.palmNormal,
palmVelocity: curr_hand.palmVelocity
};
hands.push(handStatus);
if(count++ == 10)
{
var out = {};
for ( i = 0; i < hands.length; i++){
out.confidence.mean += hands[i].confidence;
}
out.confidence.mean /= hands.length;
for (i = 0; i < hands.length; i++){
out.confidence.sd += (out.confidence.mean - hands[i].confidence);
}
out.confidence.sd = Math.sqrt(out.confidence.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.direction.mean += hands[i].direction;
}
out.direction.mean /= direction.length;
for (i = 0; i < hands.length; i++){
out.direction.sd += (out.direction.mean - hands[i].direction);
}
out.direction.sd = Math.sqrt(out.direction.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.fingers.mcpPosition.mean += hands[i].fingers.mcpPosition;
}
out.fingers.mcpPosition.mean /= hands.length;
for (i = 0; i < hands.length; i++){
out.fingers.mcpPosition.sd += (out.fingers.mcpPosition.mean - hands[i].fingers.mcpPosition);
}
out.fingers.mcpPosition.sd = Math.sqrt(out.fingers.mcpPosition.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.fingers.pipPosition.mean += hands[i].fingers.pipPosition;
}
out.fingers.pipPosition.mean /= hands.length;
for (i = 0; i < hands.length; i++){
out.fingers.pipPosition.sd += (out.fingers.pipPosition.mean - hands[i].fingers.pipPosition);
}
out.fingers.pipPosition.sd = Math.sqrt(out.fingers.pipPosition.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.fingers.dipPosition.mean += hands[i].fingers.dipPosition;
}
out.fingers.dipPosition.mean /= hands.length;
for (i = 0; i < hands.length; i++){
out.fingers.dipPosition.sd += (out.fingers.dipPosition.mean - hands[i].fingers.dipPosition);
}
out.fingers.dipPosition.sd = Math.sqrt(out.fingers.dipPosition.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.palmPosition.mean += hands[i].palmPosition;
}
out.palmPosition.mean /= palmPosition.length;
for (i = 0; i < hands.length; i++){
out.palmPosition.sd += (out.palmPosition.mean - hands[i].palmPosition);
}
out.palmPosition.sd = Math.sqrt(out.palmPosition.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.palmVelocity.mean += hands[i].palmVelocity;
}
out.palmVelocity.mean /= palmVelocity.length;
for (i = 0; i < hands.length; i++){
out.palmVelocity.sd += (out.palmVelocity.mean - hands[i].palmVelocity);
}
out.palmVelocity.sd = Math.sqrt(out.palmVelocity.sd/hands.length);
for ( i = 0; i < hands.length; i++){
out.palmNormal.mean += hands[i].palmNormal;
}
out.palmNormal.mean /= direction.length;
for (i = 0; i < hands.length; i++){
out.palmNormal.sd += (out.palmNormal.mean - hands[i].palmNormal);
}
out.palmNormal.sd = Math.sqrt(out.palmNormal.sd/hands.length);
try {
console.log(JSON.stringify(hands));
} catch(err) {
console.log(err);
return;
}
startDownload(output, 'test.json');
return;
}
}
});
</script>
</body>
</html>