Skip to content

Commit

Permalink
Merge branch 'mayaman-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyklee committed Mar 8, 2019
2 parents e4a3219 + 022415e commit 2f67861
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions src/PoseNet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ class PoseNet extends EventEmitter {
return posenet.getAdjacentKeyPoints(keypoints, confidence);
}

// eslint-disable-next-line class-methods-use-this
mapParts(pose) {
const newPose = JSON.parse(JSON.stringify(pose));
newPose.keypoints.forEach((keypoint) => {
newPose[keypoint.part] = {
x: keypoint.position.x,
y: keypoint.position.y,
confidence: keypoint.score,
};
});
return newPose;
}

/* eslint max-len: ["error", { "code": 180 }] */
async singlePose(inputOr, cb) {
let input;

if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
input = inputOr;
} else if (typeof inputOr === 'object' && (inputOr.elt instanceof HTMLImageElement || inputOr.elt instanceof HTMLVideoElement)) {
Expand All @@ -74,8 +86,8 @@ class PoseNet extends EventEmitter {
}

const pose = await this.net.estimateSinglePose(input, this.imageScaleFactor, this.flipHorizontal, this.outputStride);

const result = [{ pose, skeleton: this.skeleton(pose.keypoints) }];
const poseWithParts = this.mapParts(pose);
const result = [{ poseWithParts, skeleton: this.skeleton(pose.keypoints) }];
this.emit('pose', result);

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

const poses = await this.net.estimateMultiplePoses(input, this.imageScaleFactor, this.flipHorizontal, this.outputStride);
const result = poses.map(pose => ({ pose, skeleton: this.skeleton(pose.keypoints) }));
const posesWithParts = poses.map(pose => (this.mapParts(pose)));
const result = posesWithParts.map(pose => ({ pose, skeleton: this.skeleton(pose.keypoints) }));
this.emit('pose', result);
if (this.video) {
return tf.nextFrame().then(() => this.multiPose());
Expand Down

0 comments on commit 2f67861

Please sign in to comment.