Skip to content

Commit a5d597d

Browse files
committed
Merge branch 'mayaman-master'
2 parents 9e818a2 + 4359b98 commit a5d597d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PoseNet/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,22 @@ class PoseNet extends EventEmitter {
6161
return posenet.getAdjacentKeyPoints(keypoints, confidence);
6262
}
6363

64+
// eslint-disable-next-line class-methods-use-this
65+
mapParts(pose) {
66+
const newPose = JSON.parse(JSON.stringify(pose));
67+
newPose.keypoints.forEach((keypoint) => {
68+
newPose[keypoint.part] = {
69+
x: keypoint.position.x,
70+
y: keypoint.position.y,
71+
confidence: keypoint.score,
72+
};
73+
});
74+
return newPose;
75+
}
76+
6477
/* eslint max-len: ["error", { "code": 180 }] */
6578
async singlePose(inputOr, cb) {
6679
let input;
67-
6880
if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
6981
input = inputOr;
7082
} else if (typeof inputOr === 'object' && (inputOr.elt instanceof HTMLImageElement || inputOr.elt instanceof HTMLVideoElement)) {
@@ -74,8 +86,8 @@ class PoseNet extends EventEmitter {
7486
}
7587

7688
const pose = await this.net.estimateSinglePose(input, this.imageScaleFactor, this.flipHorizontal, this.outputStride);
77-
78-
const result = [{ pose, skeleton: this.skeleton(pose.keypoints) }];
89+
const poseWithParts = this.mapParts(pose);
90+
const result = [{ poseWithParts, skeleton: this.skeleton(pose.keypoints) }];
7991
this.emit('pose', result);
8092

8193
if (this.video) {
@@ -101,7 +113,8 @@ class PoseNet extends EventEmitter {
101113
}
102114

103115
const poses = await this.net.estimateMultiplePoses(input, this.imageScaleFactor, this.flipHorizontal, this.outputStride);
104-
const result = poses.map(pose => ({ pose, skeleton: this.skeleton(pose.keypoints) }));
116+
const posesWithParts = poses.map(pose => (this.mapParts(pose)));
117+
const result = posesWithParts.map(pose => ({ pose, skeleton: this.skeleton(pose.keypoints) }));
105118
this.emit('pose', result);
106119
if (this.video) {
107120
return tf.nextFrame().then(() => this.multiPose());

0 commit comments

Comments
 (0)