-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordingHelpers.html~
88 lines (66 loc) · 1.75 KB
/
recordingHelpers.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
<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
};
the_hand.push(handStatus);
if(count++ == 10)
{
// console.log(mean(the_hand.confidence));
try {
console.log(JSON.stringify(the_hand));
} catch(err) {
console.log(err);
return;
}
startDownload(output, 'test.json');
return;
}
}
});
</script>
</body>
</html>