-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordingHelpers.js
203 lines (168 loc) · 5.03 KB
/
recordingHelpers.js
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<html>
<head>
<script src="//js.leapmotion.com/leap-0.6.4.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(mean, values){
var sum = 0;
var distance = 0;
for (i = 0; i < values.length; i++){
distance = values - mean;
sum += distance * distance;
}
return sum/values.length;
}
function mean(values){
var sum = 0;
for (i = 0; i < value.length; i++){
sum += distance;
}
return sum;
}
function mean_multi(values)
{
}
function concatData(id, data) {
return id + ": " + data + "<br>";
}
function getFingerName(fingerType) {
switch(fingerType) {
case 0:
return 'Thumb';
break;
case 1:
return 'Index';
break;
case 2:
return 'Middle';
break;
case 3:
return 'Ring';
break;
case 4:
return 'Pinky';
break;
}
}
function concatJointPosition(id, position) {
return id + ": " + position[0] + ", " + position[1] + ", " + position[2] + "<br>";
}
var output = document.getElementById('output');
var frameString = "", handString = "", fingerString = "";
var hand, finger;
// Leap.loop uses browser's requestAnimationFrame
var options = { enableGestures: true };
var file = fopen("C:\\test.txt", 3);
if(fh!=-1)
{
var hand_confidence, hand_pinch_strength, hand_grab_strength=[];
var finger_dip = [];
var finger_pip = [];
var finger_mcp = [];
for(var i=0; i<5; i++)//creates joint functions on dip, pip, mcp for x,y,z axis
{
finger_dip[i]=[];
finger_pip[i]=[];
finger_mcp[i]=[];
}
// Main Leap Loop
Leap.loop(options, function(frame) {
//frameString = concatData("frame_id", frame.id);
//frameString += concatData("num_hands", frame.hands.length);
//frameString += concatData("num_fingers", frame.fingers.length);
//frameString += "<br>";
// Showcase some new V2 features
for (var i = 0, len = frame.hands.length; i < len; i++) {
hand = frame.hands[i];
hand_type=hand.type;
//write hand_type once
//handString += concatData("confidence", hand.confidence);
hand_confidence.push(hand.confidence);
//write hand_confidence after mean, stddev found
//handString += concatData("pinch_strength", hand.pinchStrength);
hand_pinch_strength.push(hand.pinchStrength);
//write hand_pinch_strength after mean, stddev found
//handString += concatData("grab_strength", hand.grabStrength);
hand_grab_strength.push(hand.grabStrength);
//handString += '<br>';
// Helpers for thumb, pinky, etc.
//fingerString = concatJointPosition("finger_thumb_dip", hand.thumb.dipPosition);
for (var j = 0, len2 = hand.fingers.length; j < len2; j++) {
finger = hand.fingers[j];
//fingerString += concatData("finger_type", finger.type) + " (" + getFingerName(finger.type) + ") <br>";
finger_dip[j][0].push(finger.dipPosition[0]);//x axis
finger_dip[j][1].push(finger.dipPosition[1]);//y axis
finger_dip[j][2].push(finger.dipPosition[2]);//z axis
finger_pip[j][0].push(finger.pipPosition[0]);//x axis
finger_pip[j][1].push(finger.pipPosition[1]);//y axis
finger_pip[j][2].push(finger.pipPosition[2]);//z axis
finger_mcp[j][0].push(finger.mcpPosition[0]);//x axis
finger_mcp[j][1].push(finger.mcpPosition[1]);//y axis
finger_mcp[j][2].push(finger.mcpPosition[2]);//z axis
//fingerString += concatJointPosition("finger_dip", finger.dipPosition);
//fingerString += concatJointPosition("finger_pip", finger.pipPosition);
//fingerString += concatJointPosition("finger_mcp", finger.mcpPosition);
//fingerString += "<br>";
}
frameString += handString;
frameString += fingerString;
}
fwrite(file, hand_type);
fwrite(file, mean(hand_confidence);
fwrite(file, stdDeviation(hand_confidence);
fwrite(file, mean(hand_pinch_strength);
fwrite(file, stdDeviation(hand_pinch_strength);
fwrite(file, mean(hand_grab_strength);
fwrite(file, stdDeviation(hand_grab_strength);
for(var i=0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, mean(finger_dip[i][j]));
}
}
for(var i = 0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, stdDeviation(finger_dip[i][j]));
}
}
for(var i = 0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, mean(finger_pip[i][j]));
}
}
for(var i = 0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, stdDeviation(finger_pip[i][j]));
}
}
for(var i = 0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, mean(finger_mcp[i][j]));
}
}
for(var i = 0; i<5; i++)
{
for(var j=0; j<3; j++)
{
fwrite(file, stdDeviation(finger_mcp[i][j]));
}
}
output.innerHTML = frameString;
}
});
</script>
</body>
</html>