@@ -61,10 +61,22 @@ class PoseNet extends EventEmitter {
61
61
return posenet . getAdjacentKeyPoints ( keypoints , confidence ) ;
62
62
}
63
63
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
+
64
77
/* eslint max-len: ["error", { "code": 180 }] */
65
78
async singlePose ( inputOr ) {
66
79
let input ;
67
-
68
80
if ( inputOr instanceof HTMLImageElement || inputOr instanceof HTMLVideoElement ) {
69
81
input = inputOr ;
70
82
} else if ( typeof inputOr === 'object' && ( inputOr . elt instanceof HTMLImageElement || inputOr . elt instanceof HTMLVideoElement ) ) {
@@ -74,7 +86,8 @@ class PoseNet extends EventEmitter {
74
86
}
75
87
76
88
const pose = await this . net . estimateSinglePose ( input , this . imageScaleFactor , this . flipHorizontal , this . outputStride ) ;
77
- const result = [ { pose, skeleton : this . skeleton ( pose . keypoints ) } ] ;
89
+ const poseWithParts = this . mapParts ( pose ) ;
90
+ const result = [ { poseWithParts, skeleton : this . skeleton ( pose . keypoints ) } ] ;
78
91
this . emit ( 'pose' , result ) ;
79
92
if ( this . video ) {
80
93
return tf . nextFrame ( ) . then ( ( ) => this . singlePose ( ) ) ;
@@ -94,7 +107,8 @@ class PoseNet extends EventEmitter {
94
107
}
95
108
96
109
const poses = await this . net . estimateMultiplePoses ( input , this . imageScaleFactor , this . flipHorizontal , this . outputStride ) ;
97
- const result = poses . map ( pose => ( { pose, skeleton : this . skeleton ( pose . keypoints ) } ) ) ;
110
+ const posesWithParts = poses . map ( pose => ( this . mapParts ( pose ) ) ) ;
111
+ const result = posesWithParts . map ( pose => ( { pose, skeleton : this . skeleton ( pose . keypoints ) } ) ) ;
98
112
this . emit ( 'pose' , result ) ;
99
113
if ( this . video ) {
100
114
return tf . nextFrame ( ) . then ( ( ) => this . multiPose ( ) ) ;
@@ -129,5 +143,4 @@ const poseNet = (videoOrOptionsOrCallback, optionsOrCallback, cb) => {
129
143
130
144
return new PoseNet ( video , options , detectionType , callback ) ;
131
145
} ;
132
-
133
- export default poseNet ;
146
+ export default poseNet ;
0 commit comments