/** * @license * Copyright 2021 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tensorflow/tfjs-core"),require("@tensorflow/tfjs-converter")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-core","@tensorflow/tfjs-converter"],e):e(t.posenet={},t.tf,t.tf)}(this,function(t,e,r){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function i(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return(o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r0&&i[i.length-1])&&(6===o[0]||2===o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0&&this.less(f(t),t);)this.exchange(t,f(t)),t=f(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(ee){l=!1;break}if(!l)break}return l}var h=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],d=h.length,m=h.reduce(function(t,e,r){return t[e]=r,t},{}),y=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]],v=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]});function g(t,e,r,n){return{y:n.get(t,e,r),x:n.get(t,e,r+d)}}function b(t,e,r){var n=g(t.heatmapY,t.heatmapX,t.id,r),i=n.y,o=n.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+i}}function w(t,e,r){return tr?r:t}function x(t,e){return{x:t.x+e.x,y:t.y+e.y}}var _=y.map(function(t){var e=t[0],r=t[1];return[m[e],m[r]]}),S=_.map(function(t){return t[1]}),E=_.map(function(t){return t[0]});function M(t,e,r,n){return{y:w(Math.round(t.y/e),0,r-1),x:w(Math.round(t.x/e),0,n-1)}}function k(t,e,r,n,i,o,u,s){void 0===s&&(s=2);for(var a=n.shape,l=a[0],f=a[1],c=function(t,e,r){var n=r.shape[2]/2;return{y:r.get(e.y,e.x,t),x:r.get(e.y,e.x,n+t)}}(t,M(e.position,o,l,f),u),p=x(e.position,c),d=0;d=0;--p){var d=S[p],m=E[p];a[d]&&!a[m]&&(a[m]=k(p,a[d],m,e,r,n,o))}for(p=0;p=0,function(){return"outputStride of "+n+" is invalid. It must be either 8, 16, or 32"}),function(t,r){e.util.assert("number"==typeof t[0]&&"number"==typeof t[1],function(){return"both resolution values must be a number but had values "+t}),e.util.assert(G(t[0],r),function(){return"height of "+t[0]+" is invalid for output stride "+r+"."}),e.util.assert(G(t[1],r),function(){return"width of "+t[1]+" is invalid for output stride "+r+"."})}(r,t.outputStride),this.baseModel=t,this.inputResolution=r}return t.prototype.estimateMultiplePoses=function(t,e){return void 0===e&&(e=it),u(this,void 0,void 0,function(){var r,n,i,a,l,f,c,p,h,d,m,y,v,g,b,w,x,_,S,E,M;return s(this,function(k){switch(k.label){case 0:return r=o({},it,e),function(t){var e=t.maxDetections,r=t.scoreThreshold,n=t.nmsRadius;if(e<=0)throw new Error("Invalid maxDetections "+e+". Should be > 0");if(r<0||r>1)throw new Error("Invalid scoreThreshold "+r+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid nmsRadius "+n+".")}(e),n=this.baseModel.outputStride,i=this.inputResolution,a=U(t),l=a[0],f=a[1],c=J(t,i),p=c.resized,h=c.padding,d=this.baseModel.predict(p),m=d.heatmapScores,y=d.offsets,v=d.displacementFwd,g=d.displacementBwd,[4,function(t){return u(this,void 0,void 0,function(){return s(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}([m,y,v,g])];case 1:return b=k.sent(),w=b[0],x=b[1],_=b[2],S=b[3],[4,N(w,x,_,S,n,r.maxDetections,r.scoreThreshold,r.nmsRadius)];case 2:return E=k.sent(),M=L(E,[l,f],i,h,r.flipHorizontal),m.dispose(),y.dispose(),v.dispose(),g.dispose(),p.dispose(),[2,M]}})})},t.prototype.estimateSinglePose=function(t,e){return void 0===e&&(e=nt),u(this,void 0,void 0,function(){var r,n,i,u,a,l,f,c,p,h,d,m,y,v,g,b;return s(this,function(s){switch(s.label){case 0:return r=o({},nt,e),n=this.baseModel.outputStride,i=this.inputResolution,u=U(t),a=u[0],l=u[1],f=J(t,i),c=f.resized,p=f.padding,h=this.baseModel.predict(c),d=h.heatmapScores,m=h.offsets,y=h.displacementFwd,v=h.displacementBwd,[4,A(d,m,n)];case 1:return g=s.sent(),b=L([g],[a,l],i,p,r.flipHorizontal),d.dispose(),m.dispose(),y.dispose(),v.dispose(),c.dispose(),[2,b[0]]}})})},t.prototype.estimatePoses=function(t,e){return u(this,void 0,void 0,function(){return s(this,function(r){switch(r.label){case 0:return"single-person"!==e.decodingMethod?[3,2]:[4,this.estimateSinglePose(t,e)];case 1:return[2,[r.sent()]];case 2:return[2,this.estimateMultiplePoses(t,e)]}})})},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function ut(t){return u(this,void 0,void 0,function(){var n,i,o,u,a,f,c;return s(this,function(s){switch(s.label){case 0:if(n=t.outputStride,i=t.quantBytes,o=t.multiplier,null==e)throw new Error("Cannot find TensorFlow.js. If you are using a