Skip to content

Commit b46627e

Browse files
authored
fix - adds callback support for single functions in posenet re: #244 (#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
1 parent 65a459d commit b46627e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/PoseNet/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PoseNet extends EventEmitter {
6262
}
6363

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

6868
if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
@@ -74,15 +74,22 @@ class PoseNet extends EventEmitter {
7474
}
7575

7676
const pose = await this.net.estimateSinglePose(input, this.imageScaleFactor, this.flipHorizontal, this.outputStride);
77+
7778
const result = [{ pose, skeleton: this.skeleton(pose.keypoints) }];
7879
this.emit('pose', result);
80+
7981
if (this.video) {
8082
return tf.nextFrame().then(() => this.singlePose());
8183
}
84+
85+
if (typeof cb === 'function') {
86+
cb(result);
87+
}
88+
8289
return result;
8390
}
8491

85-
async multiPose(inputOr) {
92+
async multiPose(inputOr, cb) {
8693
let input;
8794

8895
if (inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement) {
@@ -99,6 +106,11 @@ class PoseNet extends EventEmitter {
99106
if (this.video) {
100107
return tf.nextFrame().then(() => this.multiPose());
101108
}
109+
110+
if (typeof cb === 'function') {
111+
cb(result);
112+
}
113+
102114
return result;
103115
}
104116
}

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ module.exports = {
3232
...imageUtils,
3333
tf,
3434
};
35+

0 commit comments

Comments
 (0)