Skip to content

Commit 4036a00

Browse files
committed
add named keypoints
1 parent 09626a1 commit 4036a00

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/Handpose/index.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class Handpose {
106106
image,
107107
this.runtimeConfig
108108
);
109-
//TODO: customize the output for easier use
110-
const result = predictions;
109+
let result = predictions;
110+
result = this.addKeypoints(result);
111111
if (typeof callback === "function") callback(result);
112112
return result;
113113
}
@@ -166,8 +166,8 @@ class Handpose {
166166
this.detectMedia,
167167
this.runtimeConfig
168168
);
169-
//TODO: customize the output for easier use
170-
const result = predictions;
169+
let result = predictions;
170+
result = this.addKeypoints(result);
171171
this.detectCallback(result);
172172
// wait for the frame to update
173173
await tf.nextFrame();
@@ -176,6 +176,32 @@ class Handpose {
176176
this.signalStop = false;
177177
}
178178

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+
179205
/**
180206
* Check if p5.js' preload() function is present
181207
* @returns {boolean} true if preload() exists

0 commit comments

Comments
 (0)