Skip to content

Commit

Permalink
fix - adds callback support for single functions in posenet re: #244 (#…
Browse files Browse the repository at this point in the history
…254)

* fix(adds callback support for single functions in posenet https://github.com/ml5js/ml5-library/issue

adds callback support for single functions in posenet
#244

#244

* rm package-lock.json

* fix(PoseNet/index.js): Add support for PoseNet `.singlePose()` & `.multiPose()` callback #244

Add support for PoseNet `.singlePose()` & `.multiPose()` callback #244 & updated callback error
handling

#244

* rm error check when returning callback in posenet singlePose & multiPose

* fixed indentation

* temp rm cb function

* added cb function back in

* added yarn and package lock

* added lock files from ml5 master
  • Loading branch information
joeyklee authored Jan 24, 2019
1 parent 65a459d commit b46627e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/PoseNet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PoseNet extends EventEmitter {
}

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

if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
Expand All @@ -74,15 +74,22 @@ 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) }];
this.emit('pose', result);

if (this.video) {
return tf.nextFrame().then(() => this.singlePose());
}

if (typeof cb === 'function') {
cb(result);
}

return result;
}

async multiPose(inputOr) {
async multiPose(inputOr, cb) {
let input;

if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
Expand All @@ -99,6 +106,11 @@ class PoseNet extends EventEmitter {
if (this.video) {
return tf.nextFrame().then(() => this.multiPose());
}

if (typeof cb === 'function') {
cb(result);
}

return result;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ module.exports = {
...imageUtils,
tf,
};

0 comments on commit b46627e

Please sign in to comment.