@@ -106,8 +106,8 @@ class Handpose {
106
106
image ,
107
107
this . runtimeConfig
108
108
) ;
109
- //TODO: customize the output for easier use
110
- const result = predictions ;
109
+ let result = predictions ;
110
+ result = this . addKeypoints ( result ) ;
111
111
if ( typeof callback === "function" ) callback ( result ) ;
112
112
return result ;
113
113
}
@@ -166,8 +166,8 @@ class Handpose {
166
166
this . detectMedia ,
167
167
this . runtimeConfig
168
168
) ;
169
- //TODO: customize the output for easier use
170
- const result = predictions ;
169
+ let result = predictions ;
170
+ result = this . addKeypoints ( result ) ;
171
171
this . detectCallback ( result ) ;
172
172
// wait for the frame to update
173
173
await tf . nextFrame ( ) ;
@@ -176,6 +176,32 @@ class Handpose {
176
176
this . signalStop = false ;
177
177
}
178
178
179
+ /**
180
+ * Return a new array of results with named keypoints added
181
+ * @param {Array } hands - the original detection results
182
+ * @return {Array } the detection results with named keypoints added
183
+ *
184
+ * @private
185
+ */
186
+ addKeypoints ( hands ) {
187
+ const result = hands . map ( ( hand ) => {
188
+ for ( let i = 0 ; i < hand . keypoints . length ; i ++ ) {
189
+ let keypoint = hand . keypoints [ i ] ;
190
+ let keypoint3D = hand . keypoints3D [ i ] ;
191
+ hand [ keypoint . name ] = {
192
+ x : keypoint . x ,
193
+ y : keypoint . y ,
194
+ x3D : keypoint3D . x ,
195
+ y3D : keypoint3D . y ,
196
+ z3D : keypoint3D . z ,
197
+ } ;
198
+ }
199
+ return hand ;
200
+ } ) ;
201
+ console . log ( result ) ;
202
+ return result ;
203
+ }
204
+
179
205
/**
180
206
* Check if p5.js' preload() function is present
181
207
* @returns {boolean } true if preload() exists
0 commit comments