@swan-admin/swan-web-component 1.0.122 → 1.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BodyScan-CCRXkFFL.mjs +3 -0
- package/dist/BodyScan-CCRXkFFL.mjs.map +1 -0
- package/dist/BodyScan-RBxSYdGc.js +3 -0
- package/dist/BodyScan-RBxSYdGc.js.map +1 -0
- package/dist/{FaceScan-BdcqQIJ5.mjs → FaceScan-DQvhrp3K.mjs} +2 -2
- package/dist/{FaceScan-BdcqQIJ5.mjs.map → FaceScan-DQvhrp3K.mjs.map} +1 -1
- package/dist/{FaceScan-lUHosRqk.js → FaceScan-Dva9De8x.js} +2 -2
- package/dist/{FaceScan-lUHosRqk.js.map → FaceScan-Dva9De8x.js.map} +1 -1
- package/dist/{Modal-TzaSySDr.mjs → Modal-CZgyeNwW.mjs} +1 -1
- package/dist/{Modal-TzaSySDr.mjs.map → Modal-CZgyeNwW.mjs.map} +1 -1
- package/dist/{Modal-DxgejzjH.js → Modal-CmbYIXgn.js} +1 -1
- package/dist/{Modal-DxgejzjH.js.map → Modal-CmbYIXgn.js.map} +1 -1
- package/dist/bodyScan.js +1 -1
- package/dist/bodyScan.mjs +1 -1
- package/dist/faceScan.js +1 -1
- package/dist/faceScan.mjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{pose-detection.esm-BV7VgekA.js → pose-detection.esm-DFB9u8DH.js} +1 -1
- package/dist/{pose-detection.esm-BV7VgekA.js.map → pose-detection.esm-DFB9u8DH.js.map} +1 -1
- package/dist/{pose-detection.esm-D8r1CbkV.mjs → pose-detection.esm-EvS-BndH.mjs} +1 -1
- package/dist/{pose-detection.esm-D8r1CbkV.mjs.map → pose-detection.esm-EvS-BndH.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/BodyScan-B5BvnBHj.js +0 -3
- package/dist/BodyScan-B5BvnBHj.js.map +0 -1
- package/dist/BodyScan-CL9reolN.mjs +0 -3
- package/dist/BodyScan-CL9reolN.mjs.map +0 -1
|
@@ -16,4 +16,4 @@ import{getBackend as t,env as e,expandDims as n,Tensor as r,tidy as i,tensor2d a
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
* =============================================================================
|
|
18
18
|
*/function U(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}D(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var H=function(){return(H=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function V(t,e,n,r){return new(n||(n=Promise))(function(e,i){function o(t){try{s(r.next(t))}catch(t){i(t)}}function a(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var r;t.done?e(t.value):(r=t.value,r instanceof n?r:new n(function(t){t(r)})).then(o,a)}s((r=r.apply(t,[])).next())})}function G(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function K(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}var Y=["nose","left_eye","right_eye","left_ear","right_ear","left_shoulder","right_shoulder","left_elbow","right_elbow","left_wrist","right_wrist","left_hip","right_hip","left_knee","right_knee","left_ankle","right_ankle"],X=["nose","left_eye_inner","left_eye","left_eye_outer","right_eye_inner","right_eye","right_eye_outer","left_ear","right_ear","mouth_left","mouth_right","left_shoulder","right_shoulder","left_elbow","right_elbow","left_wrist","right_wrist","left_pinky","right_pinky","left_index","right_index","left_thumb","right_thumb","left_hip","right_hip","left_knee","right_knee","left_ankle","right_ankle","left_heel","right_heel","left_foot_index","right_foot_index"],W={left:[1,2,3,7,9,11,13,15,17,19,21,23,25,27,29,31],right:[4,5,6,8,10,12,14,16,18,20,22,24,26,28,30,32],middle:[0]},q={left:[1,3,5,7,9,11,13,15],right:[2,4,6,8,10,12,14,16],middle:[0]},Q=[[0,1],[0,2],[1,3],[2,4],[5,6],[5,7],[5,11],[6,8],[6,12],[7,9],[8,10],[11,12],[11,13],[12,14],[13,15],[14,16]],J=[[0,1],[0,4],[1,2],[2,3],[3,7],[4,5],[5,6],[6,8],[9,10],[11,12],[11,13],[11,23],[12,14],[14,16],[12,24],[13,15],[15,17],[16,18],[16,20],[15,17],[15,19],[15,21],[16,22],[17,19],[18,20],[23,25],[23,24],[24,26],[25,27],[26,28],[27,29],[28,30],[27,31],[28,32],[29,31],[30,32]];function Z(t){return t instanceof SVGAnimatedLength?t.baseVal.value:t}function $(t){return V(this,0,void 0,function(){var e,n;return G(this,function(i){switch(i.label){case 0:return e=document.createElement("canvas"),t instanceof r?[4,m.toPixels(t,e)]:[3,2];case 1:return i.sent(),[3,3];case 2:e.width=Z(t.width),e.height=Z(t.height),n=e.getContext("2d"),t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0),i.label=3;case 3:return[2,e]}})})}function tt(t){return V(this,0,void 0,function(){var e,n,i,o,a,s;return G(this,function(u){switch(u.label){case 0:return t instanceof r?(e=t.shape.slice(0,2),n=e[0],i=e[1],o=ImageData.bind,[4,m.toPixels(t)]):[3,2];case 1:return[2,new(o.apply(ImageData,[void 0,u.sent(),i,n]))];case 2:return a=document.createElement("canvas"),s=a.getContext("2d"),a.width=Z(t.width),a.height=Z(t.height),s.drawImage(t,0,0),[2,s.getImageData(0,0,a.width,a.height)]}})})}function et(t){return V(this,0,void 0,function(){var e,n;return G(this,function(r){switch(r.label){case 0:return t instanceof SVGImageElement||t instanceof OffscreenCanvas?[4,$(t)]:[3,2];case 1:return n=r.sent(),[3,3];case 2:n=t,r.label=3;case 3:return e=n,[2,m.fromPixels(e,4)]}})})}function nt(t){if(t<0||t>=256)throw new Error("Mask value must be in range [0, 255] but got ".concat(t));if(!Number.isInteger(t))throw new Error("Mask value must be an integer but got ".concat(t))}var rt={runtime:"mediapipe",enableSmoothing:!0,enableSegmentation:!1,smoothSegmentation:!0,modelType:"full"},it=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,this.mask]})})},t.prototype.toImageData=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,tt(this.mask)]})})},t.prototype.toTensor=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,et(this.mask)]})})},t.prototype.getUnderlyingType=function(){return"canvasimagesource"},t}();function ot(t){return nt(t),"person"}var at=function(){function t(t){var e,n=this;switch(this.width=0,this.height=0,this.selfieMode=!1,this.poseSolution=new z.Pose({locateFile:function(e,n){if(t.solutionPath){var r=t.solutionPath.replace(/\/+$/,"");return"".concat(r,"/").concat(e)}return"".concat(n,"/").concat(e)}}),t.modelType){case"lite":e=0;break;case"heavy":e=2;break;default:e=1}this.poseSolution.setOptions({modelComplexity:e,smoothLandmarks:t.enableSmoothing,enableSegmentation:t.enableSegmentation,smoothSegmentation:t.smoothSegmentation,selfieMode:this.selfieMode}),this.poseSolution.onResults(function(t){if(n.height=t.image.height,n.width=t.image.width,null==t.poseLandmarks)n.poses=[];else{var e=n.translateOutput(t.poseLandmarks,t.poseWorldLandmarks);t.segmentationMask&&(e.segmentation={maskValueToLabel:ot,mask:new it(t.segmentationMask)}),n.poses=[e]}})}return t.prototype.translateOutput=function(t,e){var n=this,r={keypoints:t.map(function(t,e){return{x:t.x*n.width,y:t.y*n.height,z:t.z,score:t.visibility,name:X[e]}})};return null!=e&&(r.keypoints3D=e.map(function(t,e){return{x:t.x,y:t.y,z:t.z,score:t.visibility,name:X[e]}})),r},t.prototype.estimatePoses=function(t,e,n){return V(this,0,void 0,function(){var i,o;return G(this,function(a){switch(a.label){case 0:return e&&e.flipHorizontal&&e.flipHorizontal!==this.selfieMode&&(this.selfieMode=e.flipHorizontal,this.poseSolution.setOptions({selfieMode:this.selfieMode})),t instanceof r?(o=ImageData.bind,[4,m.toPixels(t)]):[3,2];case 1:return i=new(o.apply(ImageData,[void 0,a.sent(),t.shape[1],t.shape[0]])),[3,3];case 2:i=t,a.label=3;case 3:return t=i,[4,this.poseSolution.send({image:t},n)];case 4:return a.sent(),[2,this.poses]}})})},t.prototype.dispose=function(){this.poseSolution.close()},t.prototype.reset=function(){this.poseSolution.reset()},t.prototype.initialize=function(){return this.poseSolution.initialize()},t}();function st(t){return V(this,0,void 0,function(){var e,n;return G(this,function(r){switch(r.label){case 0:return e=function(t){if(null==t)return H({},rt);var e=H({},t);return e.runtime="mediapipe",null==e.enableSegmentation&&(e.enableSegmentation=rt.enableSegmentation),null==e.enableSmoothing&&(e.enableSmoothing=rt.enableSmoothing),null==e.smoothSegmentation&&(e.smoothSegmentation=rt.smoothSegmentation),null==e.modelType&&(e.modelType=rt.modelType),e}(t),[4,(n=new at(e)).initialize()];case 1:return r.sent(),[2,n]}})})}function ut(t){return t instanceof r?{height:t.shape[0],width:t.shape[1]}:{height:t.height,width:t.width}}function lt(t){return t-2*Math.PI*Math.floor((t+Math.PI)/(2*Math.PI))}function ht(t){return t instanceof r?t:m.fromPixels(t)}function ct(t,e,n){return ft(n,"inputResolution"),[1/n.width*t[0][0]*e.width,1/n.height*t[0][1]*e.width,t[0][3]*e.width,1/n.width*t[1][0]*e.height,1/n.height*t[1][1]*e.height,t[1][3]*e.height,0,0]}function ft(t,e){F.assert(0!==t.width,function(){return"".concat(e," width cannot be 0.")}),F.assert(0!==t.height,function(){return"".concat(e," height cannot be 0.")})}function pt(t,e,n){var r=n.rotationVectorStartKeypointIndex,i=n.rotationVectorEndKeypointIndex,o=t.locationData,a=o.relativeKeypoints[r].x*e.width,s=o.relativeKeypoints[r].y*e.height,u=o.relativeKeypoints[i].x*e.width,l=o.relativeKeypoints[i].y*e.height,h=2*Math.sqrt((u-a)*(u-a)+(l-s)*(l-s)),c=function(t,e,n){var r,i=t.locationData,o=n.rotationVectorStartKeypointIndex,a=n.rotationVectorEndKeypointIndex;r=n.rotationVectorTargetAngle?n.rotationVectorTargetAngle:Math.PI*n.rotationVectorTargetAngleDegree/180;var s=i.relativeKeypoints[o].x*e.width,u=i.relativeKeypoints[o].y*e.height,l=i.relativeKeypoints[a].x*e.width,h=i.relativeKeypoints[a].y*e.height;return lt(r-Math.atan2(-(h-u),l-s))}(t,e,n);return{xCenter:a/e.width,yCenter:s/e.height,width:h/e.width,height:h/e.height,rotation:c}}function dt(t){if(16!==t.length)throw new Error("Array length must be 16 but got ".concat(t.length));return[[t[0],t[1],t[2],t[3]],[t[4],t[5],t[6],t[7]],[t[8],t[9],t[10],t[11]],[t[12],t[13],t[14],t[15]]]}function mt(t,e,n,r,i,o,a){return t[e][i]*(t[n][o]*t[r][a]-t[n][a]*t[r][o])}function yt(t,e,n){var r=(e+1)%4,i=(e+2)%4,o=(e+3)%4,a=(n+1)%4,s=(n+2)%4,u=(n+3)%4;return mt(t,r,i,o,a,s,u)+mt(t,i,o,r,a,s,u)+mt(t,o,r,i,a,s,u)}function gt(t,e,n){void 0===n&&(n={ignoreRotation:!1});for(var r=[],i=0,o=t;i<o.length;i++){var a=o[i],s=a.x-.5,u=a.y-.5,l=n.ignoreRotation?0:e.rotation,h=Math.cos(l)*s-Math.sin(l)*u,c=Math.sin(l)*s+Math.cos(l)*u;h=h*e.width+e.xCenter,c=c*e.height+e.yCenter;var f=a.z*e.width,p=H({},a);p.x=h,p.y=c,p.z=f,r.push(p)}return r}function vt(t,e){var n=function(t,e,n,r){var i=(r-n)/255;return{scale:i,offset:n-0*i}}(0,0,e[0],e[1]);return i(function(){return y(S(t,n.scale),n.offset)})}function bt(t,e,r){var a,l,h,c,f,p,d,m,y,g,v,b,w=e.outputTensorSize,x=e.keepAspectRatio,k=e.borderMode,S=e.outputTensorFloatRange,T=ut(t),M=function(t,e){return e?{xCenter:e.xCenter*t.width,yCenter:e.yCenter*t.height,width:e.width*t.width,height:e.height*t.height,rotation:e.rotation}:{xCenter:.5*t.width,yCenter:.5*t.height,width:t.width,height:t.height,rotation:0}}(T,r),_=function(t,e,n){if(void 0===n&&(n=!1),!n)return{top:0,left:0,right:0,bottom:0};var r=e.height,i=e.width;ft(e,"targetSize"),ft(t,"roi");var o,a,s=r/i,u=t.height/t.width,l=0,h=0;return s>u?(o=t.width,a=t.width*s,h=(1-u/s)/2):(o=t.height/s,a=t.height,l=(1-s/u)/2),t.width=o,t.height=a,{top:h,left:l,right:l,bottom:h}}(M,w,x),E=(a=M,l=T.width,h=T.height,c=a.width,f=a.height,p=Math.cos(a.rotation),d=Math.sin(a.rotation),m=a.xCenter,y=a.yCenter,g=1/l,v=1/h,(b=new Array(16))[0]=c*p*1*g,b[1]=-f*d*g,b[2]=0,b[3]=(-.5*c*p*1+.5*f*d+m)*g,b[4]=c*d*1*v,b[5]=f*p*v,b[6]=0,b[7]=(-.5*f*p-.5*c*d*1+y)*v,b[8]=0,b[9]=0,b[10]=c*g,b[11]=0,b[12]=0,b[13]=0,b[14]=0,b[15]=1,dt(b));return{imageTensor:i(function(){var e=ht(t),r=o(ct(E,T,w),[1,8]),i="zero"===k?"constant":"nearest",a=u.transform(n(s(e,"float32")),r,"bilinear",i,0,[w.height,w.width]);return null!=S?vt(a,S):a}),padding:_,transformationMatrix:E}}function wt(t,e,n,r){return 1===r?.5*(t+e):t+(e-t)*n/(r-1)}function xt(t){return null!=t&&null!=t.currentTime}function kt(t){for(var e={locationData:{relativeKeypoints:[]}},n=Number.MAX_SAFE_INTEGER,r=Number.MIN_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER,a=0;a<t.length;++a){var s=t[a];n=Math.min(n,s.x),r=Math.max(r,s.x),i=Math.min(i,s.y),o=Math.max(o,s.y),e.locationData.relativeKeypoints.push({x:s.x,y:s.y})}return e.locationData.relativeBoundingBox={xMin:n,yMin:i,xMax:r,yMax:o,width:r-n,height:o-i},e}function St(t,e,n,r){return V(this,0,void 0,function(){var r,i,a,s,l;return G(this,function(h){switch(h.label){case 0:return t.sort(function(t,e){return Math.max.apply(Math,e.score)-Math.max.apply(Math,t.score)}),r=o(t.map(function(t){return[t.locationData.relativeBoundingBox.yMin,t.locationData.relativeBoundingBox.xMin,t.locationData.relativeBoundingBox.yMax,t.locationData.relativeBoundingBox.xMax]})),i=g(t.map(function(t){return t.score[0]})),[4,u.nonMaxSuppressionAsync(r,i,e,n)];case 1:return[4,(a=h.sent()).array()];case 2:return s=h.sent(),l=t.filter(function(t,e){return s.indexOf(e)>-1}),c([r,i,a]),[2,l]}})})}function Tt(t,e){return t.map(function(t){var n=H(H({},t),{x:t.x*e.width,y:t.y*e.height});return null!=t.z&&(n.z=t.z*e.width),n})}function Mt(t,e,n){return V(this,0,void 0,function(){var r,i,o,a,s,u,l,h,c,p,d,m,y,g,v,b,w,x,k,S,T,M,_,E;return G(this,function(A){switch(A.label){case 0:if(r=f(e,[0]),i=r.shape,o=i[0],a=i[1],s=i[2],t.length!==s)throw new Error("Expected heatmap to have same number of channels as the number of landmarks. But got landmarks length: "+"".concat(t.length,", heatmap length: ").concat(s));return u=[],[4,r.buffer()];case 1:for(l=A.sent(),h=0;h<t.length;h++)if(c=t[h],p=H({},c),u.push(p),d=Math.trunc(p.x*a),m=Math.trunc(p.y*o),!(d<0||d>=a||m<0||d>=o)){for(y=Math.trunc((n.kernelSize-1)/2),g=Math.max(0,d-y),v=Math.min(a,d+y+1),b=Math.max(0,m-y),w=Math.min(o,m+y+1),x=0,k=0,S=0,T=0,M=b;M<w;++M)for(_=g;_<v;++_)E=l.get(M,_,h),x+=E,T=Math.max(T,E),k+=_*E,S+=M*E;T>=n.minConfidenceToRefine&&x>0&&(p.x=k/a/x,p.y=S/o/x)}return r.dispose(),[2,u]}})})}function _t(t,e){var n=e.left,r=e.top,i=e.left+e.right,o=e.top+e.bottom;return t.map(function(t){return H(H({},t),{x:(t.x-n)/(1-i),y:(t.y-r)/(1-o),z:t.z/(1-i)})})}function Et(t,e,n){return V(this,0,void 0,function(){var r,o,a,s,u;return G(this,function(l){switch(l.label){case 0:return r=t[0],o=t[1],a=function(t,e,n){return i(function(){var r,i,o,a;n.reverseOutputOrder?(i=f(T(t,[0,n.boxCoordOffset+0],[-1,1])),r=f(T(t,[0,n.boxCoordOffset+1],[-1,1])),a=f(T(t,[0,n.boxCoordOffset+2],[-1,1])),o=f(T(t,[0,n.boxCoordOffset+3],[-1,1]))):(r=f(T(t,[0,n.boxCoordOffset+0],[-1,1])),i=f(T(t,[0,n.boxCoordOffset+1],[-1,1])),o=f(T(t,[0,n.boxCoordOffset+2],[-1,1])),a=f(T(t,[0,n.boxCoordOffset+3],[-1,1]))),i=y(S(M(i,n.xScale),e.w),e.x),r=y(S(M(r,n.yScale),e.h),e.y),n.applyExponentialOnBoxSize?(o=S(A(M(o,n.hScale)),e.h),a=S(A(M(a,n.wScale)),e.w)):(o=S(M(o,n.hScale),e.h),a=S(M(a,n.wScale),e.h));var s=w(r,M(o,2)),u=w(i,M(a,2)),l=y(r,M(o,2)),h=y(i,M(a,2)),c=_([p(s,[n.numBoxes,1]),p(u,[n.numBoxes,1]),p(l,[n.numBoxes,1]),p(h,[n.numBoxes,1])],1);if(n.numKeypoints)for(var d=0;d<n.numKeypoints;++d){var m=n.keypointCoordOffset+d*n.numValuesPerKeypoint,g=void 0,v=void 0;n.reverseOutputOrder?(g=f(T(t,[0,m],[-1,1])),v=f(T(t,[0,m+1],[-1,1]))):(v=f(T(t,[0,m],[-1,1])),g=f(T(t,[0,m+1],[-1,1])));var b=y(S(M(g,n.xScale),e.w),e.x),x=y(S(M(v,n.yScale),e.h),e.y);c=_([c,p(b,[n.numBoxes,1]),p(x,[n.numBoxes,1])],1)}return c})}(o,e,n),s=i(function(){var t=r;return n.sigmoidScore?(null!=n.scoreClippingThresh&&(t=E(r,-n.scoreClippingThresh,n.scoreClippingThresh)),t=d(t)):t}),[4,At(a,s,n)];case 1:return u=l.sent(),c([a,s]),[2,u]}})})}function At(t,e,n){return V(this,0,void 0,function(){var r,i,o,a,s,u,l,h,c,f,p,d;return G(this,function(m){switch(m.label){case 0:return r=[],[4,t.data()];case 1:return i=m.sent(),[4,e.data()];case 2:for(o=m.sent(),a=0;a<n.numBoxes;++a)if(!(null!=n.minScoreThresh&&o[a]<n.minScoreThresh||(s=a*n.numCoords,u=Ft(i[s+0],i[s+1],i[s+2],i[s+3],o[a],n.flipVertically,a),(l=u.locationData.relativeBoundingBox).width<0||l.height<0))){if(n.numKeypoints>0)for((h=u.locationData).relativeKeypoints=[],c=n.numKeypoints*n.numValuesPerKeypoint,f=0;f<c;f+=n.numValuesPerKeypoint)p=s+n.keypointCoordOffset+f,d={x:i[p+0],y:n.flipVertically?1-i[p+1]:i[p+1]},h.relativeKeypoints.push(d);r.push(u)}return[2,r]}})})}function Ft(t,e,n,r,i,o,a){return{score:[i],ind:a,locationData:{relativeBoundingBox:{xMin:e,yMin:o?1-n:t,xMax:r,yMax:o?1-t:n,width:r-e,height:n-t}}}}function Pt(t,e){return"none"===t?e:function(t){return 1/(1+Math.exp(-t))}(e)}function Ot(t,e,n,r){return V(this,0,void 0,function(){var i,o,a,s,u,l,h,c;return G(this,function(f){switch(f.label){case 0:return n=n||e.flipHorizontally||!1,r=r||e.flipVertically||!1,i=t.size,o=i/e.numLandmarks,[4,t.data()];case 1:for(a=f.sent(),s=[],u=0;u<e.numLandmarks;++u)l=u*o,(c={x:0,y:0}).x=n?e.inputImageWidth-a[l]:a[l],o>1&&(c.y=r?e.inputImageHeight-a[l+1]:a[l+1]),o>2&&(c.z=a[l+2]),o>3&&(c.score=Pt(e.visibilityActivation,a[l+3])),s.push(c);for(h=0;h<s.length;++h)(c=s[h]).x=c.x/e.inputImageWidth,c.y=c.y/e.inputImageHeight,c.z=c.z/e.inputImageWidth/(e.normalizeZ||1);return[2,s]}})})}function Rt(t,e,n){var r=t.width,i=t.height,o=t.rotation;if(null==n.rotation&&null==n.rotationDegree||(o=function(t,e){return null!=e.rotation?t+=e.rotation:null!=e.rotationDegree&&(t+=Math.PI*e.rotationDegree/180),lt(t)}(o,n)),0===o)t.xCenter=t.xCenter+r*n.shiftX,t.yCenter=t.yCenter+i*n.shiftY;else{var a=(e.width*r*n.shiftX*Math.cos(o)-e.height*i*n.shiftY*Math.sin(o))/e.width,s=(e.width*r*n.shiftX*Math.sin(o)+e.height*i*n.shiftY*Math.cos(o))/e.height;t.xCenter=t.xCenter+a,t.yCenter=t.yCenter+s}var u=Math.max(r*e.width,i*e.height);return r=u/e.width,i=u/e.height,t.width=r*n.scaleX,t.height=i*n.scaleY,t}function It(t,e){return t.map(function(t){var n=H(H({},t),{x:t.x/e.width,y:t.y/e.height});return null!=t.z&&(t.z=t.z/e.width),n})}var Ct=function(){function t(t){this.alpha=t,this.initialized=!1}return t.prototype.apply=function(t,e){var n;return this.initialized?n=null==e?this.storedValue+this.alpha*(t-this.storedValue):this.storedValue+this.alpha*e*Math.asinh((t-this.storedValue)/e):(n=t,this.initialized=!0),this.rawValue=t,this.storedValue=n,n},t.prototype.applyWithAlpha=function(t,e,n){return this.alpha=e,this.apply(t,n)},t.prototype.hasLastRawValue=function(){return this.initialized},t.prototype.lastRawValue=function(){return this.rawValue},t.prototype.reset=function(){this.initialized=!1},t}(),Lt=function(){function t(t){this.frequency=t.frequency,this.minCutOff=t.minCutOff,this.beta=t.beta,this.thresholdCutOff=t.thresholdCutOff,this.thresholdBeta=t.thresholdBeta,this.derivateCutOff=t.derivateCutOff,this.x=new Ct(this.getAlpha(this.minCutOff)),this.dx=new Ct(this.getAlpha(this.derivateCutOff)),this.lastTimestamp=0}return t.prototype.apply=function(t,e,n){if(null==t)return t;var r=Math.trunc(e);if(this.lastTimestamp>=r)return t;0!==this.lastTimestamp&&0!==r&&(this.frequency=1/(1e-6*(r-this.lastTimestamp))),this.lastTimestamp=r;var i=this.x.hasLastRawValue()?(t-this.x.lastRawValue())*n*this.frequency:0,o=this.dx.applyWithAlpha(i,this.getAlpha(this.derivateCutOff)),a=this.minCutOff+this.beta*Math.abs(o),s=null!=this.thresholdCutOff?this.thresholdCutOff+this.thresholdBeta*Math.abs(o):null;return this.x.applyWithAlpha(t,this.getAlpha(a),s)},t.prototype.getAlpha=function(t){return 1/(1+this.frequency/(2*Math.PI*t))},t}(),jt=function(){function t(t){this.config=t}return t.prototype.apply=function(t,e,n){var r=this;if(null==t)return this.reset(),null;this.initializeFiltersIfEmpty(t);var i=1;if(!this.config.disableValueScaling){if(n<this.config.minAllowedObjectScale)return K([],t,!0);i=1/n}return t.map(function(t,n){var o=H(H({},t),{x:r.xFilters[n].apply(t.x,e,i),y:r.yFilters[n].apply(t.y,e,i)});return null!=t.z&&(o.z=r.zFilters[n].apply(t.z,e,i)),o})},t.prototype.reset=function(){this.xFilters=null,this.yFilters=null,this.zFilters=null},t.prototype.initializeFiltersIfEmpty=function(t){var e=this;null!=this.xFilters&&this.xFilters.length===t.length||(this.xFilters=t.map(function(t){return new Lt(e.config)}),this.yFilters=t.map(function(t){return new Lt(e.config)}),this.zFilters=t.map(function(t){return new Lt(e.config)}))},t}(),Nt=function(){function t(t){this.config=t,this.window=[],this.lowPassFilter=new Ct(1),this.lastValue=0,this.lastValueScale=1,this.lastTimestamp=-1}return t.prototype.apply=function(t,e,n){if(null==t)return t;var r,i=Math.trunc(e);if(this.lastTimestamp>=i)return t;if(-1===this.lastTimestamp)r=1;else{for(var o=t*n-this.lastValue*this.lastValueScale,a=i-this.lastTimestamp,s=o,u=a,l=(1+this.window.length)*(1e6/30),h=0,c=this.window;h<c.length;h++){var f=c[h];if(u+f.duration>l)break;s+=f.distance,u+=f.duration}var p=s/(1e-6*u);r=1-1/(1+this.config.velocityScale*Math.abs(p)),this.window.unshift({distance:o,duration:a}),this.window.length>this.config.windowSize&&this.window.pop()}return this.lastValue=t,this.lastValueScale=n,this.lastTimestamp=i,this.lowPassFilter.applyWithAlpha(t,r)},t}(),Bt=function(){function t(t){this.config=t}return t.prototype.apply=function(t,e,n){var r=this;if(null==t)return this.reset(),null;var i=1;if(!this.config.disableValueScaling){if(n<this.config.minAllowedObjectScale)return K([],t,!0);i=1/n}return this.initializeFiltersIfEmpty(t),t.map(function(t,n){var o=H(H({},t),{x:r.xFilters[n].apply(t.x,e,i),y:r.yFilters[n].apply(t.y,e,i)});return null!=t.z&&(o.z=r.zFilters[n].apply(t.z,e,i)),o})},t.prototype.reset=function(){this.xFilters=null,this.yFilters=null,this.zFilters=null},t.prototype.initializeFiltersIfEmpty=function(t){var e=this;null!=this.xFilters&&this.xFilters.length===t.length||(this.xFilters=t.map(function(t){return new Nt(e.config)}),this.yFilters=t.map(function(t){return new Nt(e.config)}),this.zFilters=t.map(function(t){return new Nt(e.config)}))},t}(),zt=function(){function t(t){if(null!=t.velocityFilter)this.keypointsFilter=new Bt(t.velocityFilter);else{if(null==t.oneEuroFilter)throw new Error("Either configure velocityFilter or oneEuroFilter, but got "+"".concat(t,"."));this.keypointsFilter=new jt(t.oneEuroFilter)}}return t.prototype.apply=function(t,e,n,r,i){if(void 0===r&&(r=!1),null==t)return this.keypointsFilter.reset(),null;var o=null!=i?function(t,e){return(t.width*e.width+t.height*e.height)/2}(i,n):1,a=r?Tt(t,n):t,s=this.keypointsFilter.apply(a,e,o);return r?It(s,n):s},t}(),Dt=function(){function t(t){this.alpha=t.alpha}return t.prototype.apply=function(t){var e=this;if(null==t)return this.visibilityFilters=null,null;null!=this.visibilityFilters&&this.visibilityFilters.length===t.length||(this.visibilityFilters=t.map(function(t){return new Ct(e.alpha)}));for(var n=[],r=0;r<t.length;++r){var i=t[r],o=H({},i);o.score=this.visibilityFilters[r].apply(i.score),n.push(o)}return n},t}(),Ut={interpolatedScaleAspectRatio:1,featureMapHeight:[],featureMapWidth:[],numLayers:5,minScale:.1484375,maxScale:.75,inputSizeHeight:224,inputSizeWidth:224,anchorOffsetX:.5,anchorOffsetY:.5,strides:[8,16,32,32,32],aspectRatios:[1],fixedAnchorSize:!0},Ht={runtime:"tfjs",modelType:"full",enableSmoothing:!0,enableSegmentation:!1,smoothSegmentation:!0,detectorModelUrl:"https://tfhub.dev/mediapipe/tfjs-model/blazepose_3d/detector/1",landmarkModelUrl:"https://tfhub.dev/mediapipe/tfjs-model/blazepose_3d/landmark/full/2"},Vt={maxPoses:1,flipHorizontal:!1},Gt={applyExponentialOnBoxSize:!1,flipVertically:!1,numBoxes:2254,numCoords:12,boxCoordOffset:0,keypointCoordOffset:4,numKeypoints:4,numValuesPerKeypoint:2,sigmoidScore:!0,scoreClippingThresh:100,reverseOutputOrder:!0,xScale:224,yScale:224,hScale:224,wScale:224,minScoreThresh:.5},Kt={shiftX:0,shiftY:0,scaleX:1.25,scaleY:1.25},Yt={outputTensorSize:{width:224,height:224},keepAspectRatio:!0,outputTensorFloatRange:[-1,1],borderMode:"zero"},Xt={outputTensorSize:{width:256,height:256},keepAspectRatio:!0,outputTensorFloatRange:[0,1],borderMode:"zero"},Wt={numLandmarks:39,inputImageWidth:256,inputImageHeight:256,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},qt={numLandmarks:39,inputImageWidth:1,inputImageHeight:1,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},Qt={kernelSize:7,minConfidenceToRefine:.5},Jt={alpha:.1},Zt={oneEuroFilter:{frequency:30,minCutOff:.05,beta:80,derivateCutOff:1,minAllowedObjectScale:1e-6}},$t={oneEuroFilter:{frequency:30,minCutOff:.01,beta:10,derivateCutOff:1,minAllowedObjectScale:1e-6}},te={oneEuroFilter:{frequency:30,minCutOff:.1,beta:40,derivateCutOff:1,minAllowedObjectScale:1e-6,disableValueScaling:!0}},ee={activation:"none"},ne={combineWithPreviousRatio:.7},re=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,$(this.mask)]})})},t.prototype.toImageData=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,tt(this.mask)]})})},t.prototype.toTensor=function(){return V(this,0,void 0,function(){return G(this,function(t){return[2,this.mask]})})},t.prototype.getUnderlyingType=function(){return"tensor"},t}();function ie(t){return nt(t),"person"}var oe=function(){function e(t,e,n,r,i,a){this.detectorModel=t,this.landmarkModel=e,this.enableSmoothing=n,this.enableSegmentation=r,this.smoothSegmentation=i,this.modelType=a,this.regionOfInterest=null,this.prevFilteredSegmentationMask=null,this.anchors=function(t){null==t.reduceBoxesInLowestLayer&&(t.reduceBoxesInLowestLayer=!1),null==t.interpolatedScaleAspectRatio&&(t.interpolatedScaleAspectRatio=1),null==t.fixedAnchorSize&&(t.fixedAnchorSize=!1);for(var e=[],n=0;n<t.numLayers;){for(var r=[],i=[],o=[],a=[],s=n;s<t.strides.length&&t.strides[s]===t.strides[n];){var u=wt(t.minScale,t.maxScale,s,t.strides.length);if(0===s&&t.reduceBoxesInLowestLayer)o.push(1),o.push(2),o.push(.5),a.push(.1),a.push(u),a.push(u);else{for(var l=0;l<t.aspectRatios.length;++l)o.push(t.aspectRatios[l]),a.push(u);if(t.interpolatedScaleAspectRatio>0){var h=s===t.strides.length-1?1:wt(t.minScale,t.maxScale,s+1,t.strides.length);a.push(Math.sqrt(u*h)),o.push(t.interpolatedScaleAspectRatio)}}s++}for(var c=0;c<o.length;++c){var f=Math.sqrt(o[c]);r.push(a[c]/f),i.push(a[c]*f)}var p=0,d=0;if(t.featureMapHeight.length>0)p=t.featureMapHeight[n],d=t.featureMapWidth[n];else{var m=t.strides[n];p=Math.ceil(t.inputSizeHeight/m),d=Math.ceil(t.inputSizeWidth/m)}for(var y=0;y<p;++y)for(var g=0;g<d;++g)for(var v=0;v<r.length;++v){var b={xCenter:(g+t.anchorOffsetX)/d,yCenter:(y+t.anchorOffsetY)/p,width:0,height:0};t.fixedAnchorSize?(b.width=1,b.height=1):(b.width=i[v],b.height=r[v]),e.push(b)}n=s}return e}(Ut);var s=g(this.anchors.map(function(t){return t.width})),u=g(this.anchors.map(function(t){return t.height})),l=g(this.anchors.map(function(t){return t.xCenter})),h=g(this.anchors.map(function(t){return t.yCenter}));this.anchorTensor={x:l,y:h,w:s,h:u},this.prevFilteredSegmentationMask=this.enableSegmentation?o([],[0,0]):null}return e.prototype.estimatePoses=function(t,e,r){return V(this,0,void 0,function(){var o,a,u,f,p,d,m,y,g,v,b,w,x,k,S,T,M,_,E,A,F,P,O;return G(this,function(R){switch(R.label){case 0:return o=function(t){var e;if(null==(e=null==t?Vt:H({},t)).maxPoses&&(e.maxPoses=1),e.maxPoses<=0)throw new Error("Invalid maxPoses ".concat(e.maxPoses,". Should be > 0."));if(e.maxPoses>1)throw new Error("Multi-pose detection is not implemented yet. Please set maxPoses to 1.");return e}(e),null==t?(this.reset(),[2,[]]):(this.maxPoses=o.maxPoses,this.timestamp=null!=r?1e3*r:xt(t)?1e6*t.currentTime:null,a=ut(t),u=i(function(){return s(ht(t),"float32")}),null!=(f=this.regionOfInterest)?[3,2]:[4,this.detectPose(u)]);case 1:if(0===(p=R.sent()).length)return this.reset(),u.dispose(),[2,[]];d=p[0],f=this.poseDetectionToRoi(d,a),R.label=2;case 2:return[4,this.poseLandmarksByRoi(f,u)];case 3:return m=R.sent(),u.dispose(),null==m?(this.reset(),[2,[]]):(y=m.landmarks,g=m.auxiliaryLandmarks,v=m.poseScore,b=m.worldLandmarks,w=m.segmentationMask,x=this.poseLandmarkFiltering(y,g,b,a),k=x.actualLandmarksFiltered,S=x.auxiliaryLandmarksFiltered,T=x.actualWorldLandmarksFiltered,M=this.poseLandmarksToRoi(S,a),this.regionOfInterest=M,_=this.smoothSegmentation&&null!=w?this.poseSegmentationFiltering(w):w,null!=(E=null!=k?Tt(k,a):null)&&E.forEach(function(t,e){t.name=X[e]}),null!=(A=T)&&A.forEach(function(t,e){t.name=X[e]}),F={score:v,keypoints:E,keypoints3D:A},null!==_&&(P=i(function(){var t=n(_,2),e=l(t,[[0,0],[0,0],[0,1]]);return h(e,[[0,0],[0,0],[0,2]],"symmetric")}),this.smoothSegmentation||c(_),O={maskValueToLabel:ie,mask:new re(P)},F.segmentation=O),[2,[F]])}})})},e.prototype.poseSegmentationFiltering=function(e){var n=this.prevFilteredSegmentationMask;return 0===n.size?this.prevFilteredSegmentationMask=e:(this.prevFilteredSegmentationMask=function(e,n,r){return"webgl"===t()?function(t,e,n){var r=n.combineWithPreviousRatio.toFixed(2),o={variableNames:["prevMask","newMask"],outputShape:t.shape,userCode:"\n void main() {\n ivec2 coords = getOutputCoords();\n int height = coords[0];\n int width = coords[1];\n\n float prevMaskValue = getPrevMask(height, width);\n float newMaskValue = getNewMask(height, width);\n\n /*\n * Assume p := newMaskValue\n * H(p) := 1 + (p * log(p) + (1-p) * log(1-p)) / log(2)\n * uncertainty alpha(p) =\n * Clamp(1 - (1 - H(p)) * (1 - H(p)), 0, 1) [squaring the\n * uncertainty]\n *\n * The following polynomial approximates uncertainty alpha as a\n * function of (p + 0.5):\n */\n const float c1 = 5.68842;\n const float c2 = -0.748699;\n const float c3 = -57.8051;\n const float c4 = 291.309;\n const float c5 = -624.717;\n float t = newMaskValue - 0.5;\n float x = t * t;\n\n float uncertainty =\n 1.0 - min(1.0, x * (c1 + x * (c2 + x * (c3 + x * (c4 + x * c5)))));\n\n float outputValue = newMaskValue + (prevMaskValue - newMaskValue) *\n (uncertainty * ".concat(r,");\n\n setOutput(outputValue);\n }\n")},a=v();return i(function(){var n=a.compileAndRun(o,[t,e]);return b().makeTensorFromDataId(n.dataId,n.shape,n.dtype)})}(e,n,r):i(function(){var t=w(n,.5),i=x(t),o=w(1,k(1,S(i,y(5.68842,S(i,y(-.748699,S(i,y(-57.8051,S(i,y(291.309,S(i,-624.717)))))))))));return y(n,S(w(e,n),S(o,r.combineWithPreviousRatio)))})}(n,e,ne),c(e)),c(n),this.prevFilteredSegmentationMask},e.prototype.dispose=function(){this.detectorModel.dispose(),this.landmarkModel.dispose(),c([this.anchorTensor.x,this.anchorTensor.y,this.anchorTensor.w,this.anchorTensor.h,this.prevFilteredSegmentationMask])},e.prototype.reset=function(){this.regionOfInterest=null,this.enableSegmentation&&(c(this.prevFilteredSegmentationMask),this.prevFilteredSegmentationMask=o([],[0,0])),this.visibilitySmoothingFilterActual=null,this.visibilitySmoothingFilterAuxiliary=null,this.landmarksSmoothingFilterActual=null,this.landmarksSmoothingFilterAuxiliary=null},e.prototype.detectPose=function(t){return V(this,0,void 0,function(){var e,n,r,o,a,s,u,l,h,p;return G(this,function(d){switch(d.label){case 0:return e=bt(t,Yt),n=e.imageTensor,r=e.padding,o=this.detectorModel.predict(n),a=function(t){return i(function(){var e=function(t){return i(function(){return[T(t,[0,0,0],[1,-1,1]),T(t,[0,0,1],[1,-1,-1])]})}(t),n=e[0],r=e[1];return{boxes:f(r),logits:f(n)}})}(o),s=a.boxes,[4,Et([u=a.logits,s],this.anchorTensor,Gt)];case 1:return 0===(l=d.sent()).length?(c([n,o,u,s]),[2,l]):[4,St(l,this.maxPoses,.3)];case 2:return h=d.sent(),p=function(t,e){void 0===t&&(t=[]);for(var n=e.left,r=e.top,i=e.left+e.right,o=e.top+e.bottom,a=0;a<t.length;a++){var s=t[a],u=s.locationData.relativeBoundingBox,l=(u.xMin-n)/(1-i),h=(u.yMin-r)/(1-o),c=u.width/(1-i),f=u.height/(1-o);u.xMin=l,u.yMin=h,u.width=c,u.height=f,u.xMax=l+c,u.yMax=h+f;var p=s.locationData.relativeKeypoints;p&&p.forEach(function(t){var e=(t.x-n)/(1-i),a=(t.y-r)/(1-o);t.x=e,t.y=a})}return t}(h,r),c([n,o,u,s]),[2,p]}})})},e.prototype.poseDetectionToRoi=function(t,e){return Rt(pt(t,e,{rotationVectorEndKeypointIndex:1,rotationVectorStartKeypointIndex:0,rotationVectorTargetAngleDegree:90}),e,Kt)},e.prototype.poseLandmarksByRoi=function(t,e){return V(this,0,void 0,function(){var n,r,i,o,a,s,u,l,h,f,p,d,m,y;return G(this,function(g){switch(g.label){case 0:if(n=ut(e),r=bt(e,Xt,t),i=r.imageTensor,o=r.padding,a=r.transformationMatrix,"lite"!==this.modelType&&"full"!==this.modelType&&"heavy"!==this.modelType)throw new Error("Model type must be one of lite, full or heavy,"+"but got ".concat(this.modelType));return s=["ld_3d","output_poseflag","activation_heatmap","world_3d"],this.enableSegmentation&&s.push("activation_segmentation"),u=this.landmarkModel.execute(i,s),[4,this.tensorsToPoseLandmarksAndSegmentation(u)];case 1:return null==(l=g.sent())?(c(u),c(i),[2,null]):(h=l.landmarks,f=l.auxiliaryLandmarks,p=l.poseScore,d=l.worldLandmarks,m=l.segmentationMask,[4,this.poseLandmarksAndSegmentationInverseProjection(n,t,o,a,h,f,d,m)]);case 2:return y=g.sent(),c(u),c(i),[2,H({poseScore:p},y)]}})})},e.prototype.poseLandmarksAndSegmentationInverseProjection=function(t,e,n,r,a,s,l,h){return V(this,0,void 0,function(){var d,m,y,g,v,b;return G(this,function(w){return d=_t(a,n),m=_t(s,n),y=gt(d,e),g=gt(m,e),v=function(t,e){for(var n=[],r=0,i=t;r<i.length;r++){var o=i[r],a=o.x,s=o.y,u=e.rotation,l=Math.cos(u)*a-Math.sin(u)*s,h=Math.sin(u)*a+Math.cos(u)*s,c=H({},o);c.x=l,c.y=h,n.push(c)}return n}(l,e),b=null,this.enableSegmentation&&(b=i(function(){var e=h.shape,n=e[0],i=e[1],a=function(t){var e=dt(new Array(16).fill(0));e[0][0]=yt(t,0,0),e[1][0]=-yt(t,0,1),e[2][0]=yt(t,0,2),e[3][0]=-yt(t,0,3),e[0][2]=yt(t,2,0),e[1][2]=-yt(t,2,1),e[2][2]=yt(t,2,2),e[3][2]=-yt(t,2,3),e[0][1]=-yt(t,1,0),e[1][1]=yt(t,1,1),e[2][1]=-yt(t,1,2),e[3][1]=yt(t,1,3),e[0][3]=-yt(t,3,0),e[1][3]=yt(t,3,1),e[2][3]=-yt(t,3,2),e[3][3]=yt(t,3,3);for(var n=t[0][0]*e[0][0]+t[1][0]*e[0][1]+t[2][0]*e[0][2]+t[3][0]*e[0][3],r=0;r<e.length;r++)for(var i=0;i<e.length;i++)e[r][i]/=n;return e}(r),s=o(ct(a,{width:i,height:n},t),[1,8]),l=[1,n,i,1];return f(u.transform(p(h,l),s,"bilinear","constant",0,[t.height,t.width]),[0,3])}),c(h)),[2,{landmarks:y,auxiliaryLandmarks:g,worldLandmarks:v,segmentationMask:b}]})})},e.prototype.tensorsToPoseLandmarksAndSegmentation=function(t){return V(this,0,void 0,function(){var e,n,r,o,a,s,u,l,h,c,p,m,y;return G(this,function(g){switch(g.label){case 0:return e=t[0],n=t[1],r=t[2],o=t[3],a=this.enableSegmentation?t[4]:null,[4,n.data()];case 1:return(s=g.sent()[0])<.5?[2,null]:[4,Ot(e,Wt)];case 2:return[4,Mt(g.sent(),r,Qt)];case 3:return u=g.sent(),l=u.slice(0,33),h=u.slice(33,35),[4,Ot(o,qt)];case 4:return c=g.sent(),p=c.slice(0,33),m=function(t,e){for(var n=[],r=0;r<t.length;r++){var i=H({},e[r]);i.score=t[r].score,n.push(i)}return n}(l,p),y=this.enableSegmentation?function(t,e){return i(function(){var n=f(t,[0]),r=n.shape[2];if(1===r){var i=n;switch(e.activation){case"none":break;case"sigmoid":i=d(i);break;case"softmax":throw new Error("Softmax activation requires two channels.");default:throw new Error("Activation not supported (".concat(e.activation,")"))}return f(i,[2])}throw new Error("Unsupported number of tensor channels ".concat(r))})}(a,ee):null,[2,{landmarks:l,auxiliaryLandmarks:h,poseScore:s,worldLandmarks:m,segmentationMask:y}]}})})},e.prototype.poseLandmarksToRoi=function(t,e){return Rt(pt(kt(t),e,{rotationVectorStartKeypointIndex:0,rotationVectorEndKeypointIndex:1,rotationVectorTargetAngleDegree:90}),e,Kt)},e.prototype.poseLandmarkFiltering=function(t,e,n,r){var i,o,a;if(null!=this.timestamp&&this.enableSmoothing){var s=pt(kt(e),r,{rotationVectorEndKeypointIndex:0,rotationVectorStartKeypointIndex:1,rotationVectorTargetAngleDegree:90});null==this.visibilitySmoothingFilterActual&&(this.visibilitySmoothingFilterActual=new Dt(Jt)),i=this.visibilitySmoothingFilterActual.apply(t),null==this.visibilitySmoothingFilterAuxiliary&&(this.visibilitySmoothingFilterAuxiliary=new Dt(Jt)),o=this.visibilitySmoothingFilterAuxiliary.apply(e),a=this.visibilitySmoothingFilterActual.apply(n),null==this.landmarksSmoothingFilterActual&&(this.landmarksSmoothingFilterActual=new zt(Zt)),i=this.landmarksSmoothingFilterActual.apply(i,this.timestamp,r,!0,s),null==this.landmarksSmoothingFilterAuxiliary&&(this.landmarksSmoothingFilterAuxiliary=new zt($t)),o=this.landmarksSmoothingFilterAuxiliary.apply(o,this.timestamp,r,!0,s),null==this.worldLandmarksSmoothingFilterActual&&(this.worldLandmarksSmoothingFilterActual=new zt(te)),a=this.worldLandmarksSmoothingFilterActual.apply(n,this.timestamp)}else i=t,o=e,a=n;return{actualLandmarksFiltered:i,auxiliaryLandmarksFiltered:o,actualWorldLandmarksFiltered:a}},e}();function ae(t){return V(this,0,void 0,function(){var e,n,r,i,o,a;return G(this,function(s){switch(s.label){case 0:return e=function(t){var e=H({},null==t?Ht:t);if(null==e.enableSmoothing&&(e.enableSmoothing=Ht.enableSmoothing),null==e.enableSegmentation&&(e.enableSegmentation=Ht.enableSegmentation),null==e.smoothSegmentation&&(e.smoothSegmentation=Ht.smoothSegmentation),null==e.modelType&&(e.modelType=Ht.modelType),null==e.detectorModelUrl&&(e.detectorModelUrl=Ht.detectorModelUrl),null==e.landmarkModelUrl)switch(e.modelType){case"lite":e.landmarkModelUrl="https://tfhub.dev/mediapipe/tfjs-model/blazepose_3d/landmark/lite/2";break;case"heavy":e.landmarkModelUrl="https://tfhub.dev/mediapipe/tfjs-model/blazepose_3d/landmark/heavy/2";break;default:e.landmarkModelUrl="https://tfhub.dev/mediapipe/tfjs-model/blazepose_3d/landmark/full/2"}return e}(t),n="string"==typeof e.detectorModelUrl&&e.detectorModelUrl.indexOf("https://tfhub.dev")>-1,r="string"==typeof e.landmarkModelUrl&&e.landmarkModelUrl.indexOf("https://tfhub.dev")>-1,[4,Promise.all([R(e.detectorModelUrl,{fromTFHub:n}),R(e.landmarkModelUrl,{fromTFHub:r})])];case 1:return i=s.sent(),o=i[0],a=i[1],[2,new oe(o,a,e.enableSmoothing,e.enableSegmentation,e.smoothSegmentation,e.modelType)]}})})}var se,ue,le,he=function(){function t(t){!function(t){if(t.maxTracks<1)throw new Error("Must specify 'maxTracks' to be at least 1, but "+"encountered ".concat(t.maxTracks));if(t.maxAge<=0)throw new Error("Must specify 'maxAge' to be positive, but "+"encountered ".concat(t.maxAge));if(void 0!==t.keypointTrackerParams){if(t.keypointTrackerParams.keypointConfidenceThreshold<0||t.keypointTrackerParams.keypointConfidenceThreshold>1)throw new Error("Must specify 'keypointConfidenceThreshold' to be in the range [0, 1], but encountered "+"".concat(t.keypointTrackerParams.keypointConfidenceThreshold));if(t.keypointTrackerParams.minNumberOfKeypoints<1)throw new Error("Must specify 'minNumberOfKeypoints' to be at least 1, but "+"encountered ".concat(t.keypointTrackerParams.minNumberOfKeypoints));for(var e=0,n=t.keypointTrackerParams.keypointFalloff;e<n.length;e++){var r=n[e];if(r<=0)throw new Error("Must specify each keypoint falloff parameterto be positive "+"but encountered ".concat(r))}}}(t),this.tracks=[],this.maxTracks=t.maxTracks,this.maxAge=1e3*t.maxAge,this.minSimilarity=t.minSimilarity,this.nextID=1}return t.prototype.apply=function(t,e){this.filterOldTracks(e);var n=this.computeSimilarity(t);return this.assignTracks(t,n,e),this.updateTracks(e),t},t.prototype.getTracks=function(){return this.tracks.slice()},t.prototype.getTrackIDs=function(){return new Set(this.tracks.map(function(t){return t.id}))},t.prototype.filterOldTracks=function(t){var e=this;this.tracks=this.tracks.filter(function(n){return t-n.lastTimestamp<=e.maxAge})},t.prototype.assignTracks=function(t,e,n){for(var r=Array.from(Array(e[0].length).keys()),i=[],o=0,a=Array.from(Array(t.length).keys());o<a.length;o++){var s=a[o];if(0!==r.length){for(var u=-1,l=-1,h=0,c=r;h<c.length;h++){var f=c[h],p=e[s][f];p>=this.minSimilarity&&p>l&&(u=f,l=p)}if(u>=0){var d=this.tracks[u];d=Object.assign(d,this.createTrack(t[s],n,d.id)),t[s].id=d.id;var m=r.indexOf(u);r.splice(m,1)}else i.push(s)}else i.push(s)}for(var y=0,g=i;y<g.length;y++){s=g[y];var v=this.createTrack(t[s],n);this.tracks.push(v),t[s].id=v.id}},t.prototype.updateTracks=function(t){this.tracks.sort(function(t,e){return e.lastTimestamp-t.lastTimestamp}),this.tracks=this.tracks.slice(0,this.maxTracks)},t.prototype.createTrack=function(t,e,n){var r={id:n||this.nextTrackID(),lastTimestamp:e,keypoints:K([],t.keypoints,!0).map(function(t){return H({},t)})};return void 0!==t.box&&(r.box=H({},t.box)),r},t.prototype.nextTrackID=function(){var t=this.nextID;return this.nextID+=1,t},t.prototype.remove=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.tracks=this.tracks.filter(function(e){return!t.includes(e.id)})},t.prototype.reset=function(){this.tracks=[]},t}(),ce=function(t){function e(e){return t.call(this,e)||this}return U(e,t),e.prototype.computeSimilarity=function(t){var e=this;return 0===t.length||0===this.tracks.length?[[]]:t.map(function(t){return e.tracks.map(function(n){return e.iou(t,n)})})},e.prototype.iou=function(t,e){var n=Math.max(t.box.xMin,e.box.xMin),r=Math.max(t.box.yMin,e.box.yMin),i=Math.min(t.box.xMax,e.box.xMax),o=Math.min(t.box.yMax,e.box.yMax);if(n>=i||r>=o)return 0;var a=(i-n)*(o-r);return a/(t.box.width*t.box.height+e.box.width*e.box.height-a)},e}(he),fe=function(t){function e(e){var n=t.call(this,e)||this;return n.keypointThreshold=e.keypointTrackerParams.keypointConfidenceThreshold,n.keypointFalloff=e.keypointTrackerParams.keypointFalloff,n.minNumKeyoints=e.keypointTrackerParams.minNumberOfKeypoints,n}return U(e,t),e.prototype.computeSimilarity=function(t){if(0===t.length||0===this.tracks.length)return[[]];for(var e=[],n=0,r=t;n<r.length;n++){for(var i=r[n],o=[],a=0,s=this.tracks;a<s.length;a++){var u=s[a];o.push(this.oks(i,u))}e.push(o)}return e},e.prototype.oks=function(t,e){for(var n=this.area(e.keypoints)+1e-6,r=0,i=0,o=0;o<t.keypoints.length;++o){var a=t.keypoints[o],s=e.keypoints[o];if(!(a.score<this.keypointThreshold||s.score<this.keypointThreshold)){i+=1;var u=Math.pow(a.x-s.x,2)+Math.pow(a.y-s.y,2),l=2*this.keypointFalloff[o];r+=Math.exp(-1*u/(2*n*Math.pow(l,2)))}}return i<this.minNumKeyoints?0:r/i},e.prototype.area=function(t){var e=this,n=t.filter(function(t){return t.score>e.keypointThreshold}),r=Math.min.apply(Math,K([1],n.map(function(t){return t.x}),!1)),i=Math.max.apply(Math,K([0],n.map(function(t){return t.x}),!1)),o=Math.min.apply(Math,K([1],n.map(function(t){return t.y}),!1));return(i-r)*(Math.max.apply(Math,K([0],n.map(function(t){return t.y}),!1))-o)},e}(he);function pe(t){switch(t){case ue.BlazePose:return X.reduce(function(t,e,n){return t[e]=n,t},{});case ue.PoseNet:case ue.MoveNet:return Y.reduce(function(t,e,n){return t[e]=n,t},{});default:throw new Error("Model ".concat(t," is not supported."))}}(le=se||(se={})).Keypoint="keypoint",le.BoundingBox="boundingBox",function(t){t.MoveNet="MoveNet",t.BlazePose="BlazePose",t.PoseNet="PoseNet"}(ue||(ue={}));var de=Object.freeze({__proto__:null,getKeypointIndexBySide:function(t){switch(t){case ue.BlazePose:return W;case ue.PoseNet:case ue.MoveNet:return q;default:throw new Error("Model ".concat(t," is not supported."))}},getAdjacentPairs:function(t){switch(t){case ue.BlazePose:return J;case ue.PoseNet:case ue.MoveNet:return Q;default:throw new Error("Model ".concat(t," is not supported."))}},getKeypointIndexByName:pe}),me=["SinglePose.Lightning","SinglePose.Thunder","MultiPose.Lightning"],ye={modelType:"SinglePose.Lightning",enableSmoothing:!0},ge={},ve={frequency:30,minCutOff:2.5,beta:300,derivateCutOff:2.5,thresholdCutOff:.5,thresholdBeta:5,disableValueScaling:!0},be={maxTracks:18,maxAge:1e3,minSimilarity:.2,keypointTrackerParams:{keypointConfidenceThreshold:.3,keypointFalloff:[.026,.025,.025,.035,.035,.079,.079,.072,.072,.062,.062,.107,.107,.087,.087,.089,.089],minNumberOfKeypoints:4}},we={maxTracks:18,maxAge:1e3,minSimilarity:.15,trackerParams:{}};function xe(t,e){var n,r,i,o;return t?e.width>e.height?(n=1,r=e.height/e.width,i=0,o=(e.width/2-e.height/2)/e.width):(n=e.width/e.height,r=1,i=(e.height/2-e.width/2)/e.height,o=0):e.width>e.height?(n=e.width/e.height,r=1,i=(e.height/2-e.width/2)/e.height,o=0):(n=1,r=e.height/e.width,i=0,o=(e.width/2-e.height/2)/e.width),{yMin:i,xMin:o,yMax:i+n,xMax:o+r,height:n,width:r}}function ke(t,e){var n={maxTracks:t.maxTracks,maxAge:t.maxAge,minSimilarity:t.minSimilarity};return null!=e.maxTracks&&(n.maxTracks=e.maxTracks),null!=e.maxAge&&(n.maxAge=e.maxAge),null!=e.minSimilarity&&(n.minSimilarity=e.minSimilarity),n}var Se=function(){function e(t,e){this.moveNetModel=t,this.modelInputResolution={height:0,width:0},this.keypointIndexByName=pe(ue.MoveNet),"SinglePose.Lightning"===e.modelType?(this.modelInputResolution.width=192,this.modelInputResolution.height=192):"SinglePose.Thunder"===e.modelType&&(this.modelInputResolution.width=256,this.modelInputResolution.height=256),this.multiPoseModel="MultiPose.Lightning"===e.modelType,this.multiPoseModel||(this.keypointFilter=new jt(ve),this.cropRegionFilterYMin=new Ct(.9),this.cropRegionFilterXMin=new Ct(.9),this.cropRegionFilterYMax=new Ct(.9),this.cropRegionFilterXMax=new Ct(.9)),this.enableSmoothing=e.enableSmoothing,e.minPoseScore?this.minPoseScore=e.minPoseScore:this.minPoseScore=.25,e.multiPoseMaxDimension?this.multiPoseMaxDimension=e.multiPoseMaxDimension:this.multiPoseMaxDimension=256,this.enableTracking=e.enableTracking,this.multiPoseModel&&this.enableTracking&&(e.trackerType===se.Keypoint?this.tracker=new fe(e.trackerConfig):e.trackerType===se.BoundingBox&&(this.tracker=new ce(e.trackerConfig)),this.enableSmoothing&&(this.keypointFilterMap=new Map))}return e.prototype.runSinglePersonPoseModel=function(e){return V(this,0,void 0,function(){var n,r,i,o,a;return G(this,function(s){switch(s.label){case 0:if(4!==(n=this.moveNetModel.execute(e)).shape.length||1!==n.shape[0]||1!==n.shape[1]||17!==n.shape[2]||3!==n.shape[3])throw n.dispose(),new Error("Unexpected output shape from model: [".concat(n.shape,"]"));return"webgpu"===t()?[3,1]:(r=n.dataSync(),[3,3]);case 1:return[4,n.data()];case 2:r=s.sent(),s.label=3;case 3:for(n.dispose(),i={keypoints:[],score:0},o=0,a=0;a<17;++a)i.keypoints[a]={y:r[3*a],x:r[3*a+1],score:r[3*a+2]},i.keypoints[a].score>.2&&(++o,i.score+=i.keypoints[a].score);return o>0&&(i.score/=o),[2,i]}})})},e.prototype.runMultiPersonPoseModel=function(e){return V(this,0,void 0,function(){var n,r,i,o,a,s,u,l;return G(this,function(h){switch(h.label){case 0:if(3!==(n=this.moveNetModel.execute(e)).shape.length||1!==n.shape[0]||56!==n.shape[2])throw n.dispose(),new Error("Unexpected output shape from model: [".concat(n.shape,"]"));return"webgpu"===t()?[3,1]:(r=n.dataSync(),[3,3]);case 1:return[4,n.data()];case 2:r=h.sent(),h.label=3;case 3:for(n.dispose(),i=[],o=r.length/56,a=0;a<o;++a)for(i[a]={keypoints:[]},s=56*a+51,i[a].box={yMin:r[s],xMin:r[s+1],yMax:r[s+2],xMax:r[s+3],width:r[s+3]-r[s+1],height:r[s+2]-r[s]},u=56*a+55,i[a].score=r[u],i[a].keypoints=[],l=0;l<17;++l)i[a].keypoints[l]={y:r[56*a+3*l],x:r[56*a+3*l+1],score:r[56*a+3*l+2]};return[2,i]}})})},e.prototype.estimatePoses=function(t,e,i){return void 0===e&&(e=ge),V(this,0,void 0,function(){var o,a,s,u,l,h;return G(this,function(c){switch(c.label){case 0:return e=function(t){return null==t?ge:H({},t)}(e),null==t?(this.reset(),[2,[]]):(null==i?xt(t)&&(i=1e6*t.currentTime):i*=1e3,o=ht(t),a=ut(o),s=n(o,0),t instanceof r||o.dispose(),u=[],this.multiPoseModel?[3,2]:[4,this.estimateSinglePose(s,a,i)]);case 1:return u=c.sent(),[3,4];case 2:return[4,this.estimateMultiplePoses(s,a,i)];case 3:u=c.sent(),c.label=4;case 4:for(l=0;l<u.length;++l)for(h=0;h<u[l].keypoints.length;++h)u[l].keypoints[h].name=Y[h],u[l].keypoints[h].y*=a.height,u[l].keypoints[h].x*=a.width;return[2,u]}})})},e.prototype.estimateSinglePose=function(t,e,n){return V(this,0,void 0,function(){var r,l,h,c,f=this;return G(this,function(p){switch(p.label){case 0:return this.cropRegion||(this.cropRegion=xe(null==this.cropRegion,e)),r=i(function(){var e=o([[f.cropRegion.yMin,f.cropRegion.xMin,f.cropRegion.yMax,f.cropRegion.xMax]]),n=a([1],"int32"),r=[f.modelInputResolution.height,f.modelInputResolution.width];return s(u.cropAndResize(t,e,n,r,"bilinear",0),"int32")}),t.dispose(),[4,this.runSinglePersonPoseModel(r)];case 1:if(l=p.sent(),r.dispose(),l.score<this.minPoseScore)return this.reset(),[2,[]];for(h=0;h<l.keypoints.length;++h)l.keypoints[h].y=this.cropRegion.yMin+l.keypoints[h].y*this.cropRegion.height,l.keypoints[h].x=this.cropRegion.xMin+l.keypoints[h].x*this.cropRegion.width;return null!=n&&this.enableSmoothing&&(l.keypoints=this.keypointFilter.apply(l.keypoints,n,1)),c=function(t,e,n,r){for(var i={},o=0,a=Y;o<a.length;o++){var s=a[o];i[s]=[e[n[s]].y*r.height,e[n[s]].x*r.width]}if(function(t,e){return(t[e.left_hip].score>.2||t[e.right_hip].score>.2)&&(t[e.left_shoulder].score>.2||t[e.right_shoulder].score>.2)}(e,n)){var u=(i.left_hip[0]+i.right_hip[0])/2,l=(i.left_hip[1]+i.right_hip[1])/2,h=function(t,e,n,r,i){for(var o=["left_shoulder","right_shoulder","left_hip","right_hip"],a=0,s=0,u=0;u<o.length;u++)(p=Math.abs(r-n[o[u]][0]))>a&&(a=p),(d=Math.abs(i-n[o[u]][1]))>s&&(s=d);for(var l=0,h=0,c=0,f=Object.keys(n);c<f.length;c++){var p,d,m=f[c];t[e[m]].score<.2||((p=Math.abs(r-n[m][0]))>l&&(l=p),(d=Math.abs(i-n[m][1]))>h&&(h=d))}return[a,s,l,h]}(e,n,i,u,l),c=h[0],f=h[1],p=h[2],d=h[3],m=Math.max(1.9*f,1.9*c,1.2*p,1.2*d),y=[u-(m=Math.min(m,Math.max(l,r.width-l,u,r.height-u))),l-m];if(m>Math.max(r.width,r.height)/2)return xe(null==t,r);var g=2*m;return{yMin:y[0]/r.height,xMin:y[1]/r.width,yMax:(y[0]+g)/r.height,xMax:(y[1]+g)/r.width,height:(y[0]+g)/r.height-y[0]/r.height,width:(y[1]+g)/r.width-y[1]/r.width}}return xe(null==t,r)}(this.cropRegion,l.keypoints,this.keypointIndexByName,e),this.cropRegion=this.filterCropRegion(c),[2,[l]]}})})},e.prototype.estimateMultiplePoses=function(t,e,n){return V(this,0,void 0,function(){var r,i,o,a,h,c,f,p,d,m,y,g=this;return G(this,function(v){switch(v.label){case 0:return e.width>e.height?(i=this.multiPoseMaxDimension,o=Math.round(this.multiPoseMaxDimension*e.height/e.width),r=u.resizeBilinear(t,[o,i]),h=i,c=32*Math.ceil(o/32),a=l(r,[[0,0],[0,c-o],[0,0],[0,0]])):(i=Math.round(this.multiPoseMaxDimension*e.width/e.height),o=this.multiPoseMaxDimension,r=u.resizeBilinear(t,[o,i]),h=32*Math.ceil(i/32),c=o,a=l(r,[[0,0],[0,0],[0,h-i],[0,0]])),r.dispose(),t.dispose(),f=s(a,"int32"),a.dispose(),[4,this.runMultiPersonPoseModel(f)];case 1:for(p=v.sent(),f.dispose(),p=p.filter(function(t){return t.score>=g.minPoseScore}),m=0;m<p.length;++m)for(d=0;d<p[m].keypoints.length;++d)p[m].keypoints[d].y*=c/o,p[m].keypoints[d].x*=h/i;if(this.enableTracking&&(this.tracker.apply(p,n),this.enableSmoothing)){for(m=0;m<p.length;++m)this.keypointFilterMap.has(p[m].id)||this.keypointFilterMap.set(p[m].id,new jt(ve)),p[m].keypoints=this.keypointFilterMap.get(p[m].id).apply(p[m].keypoints,n,1);y=this.tracker.getTrackIDs(),this.keypointFilterMap.forEach(function(t,e){y.has(e)||g.keypointFilterMap.delete(e)})}return[2,p]}})})},e.prototype.filterCropRegion=function(t){if(t){var e=this.cropRegionFilterYMin.apply(t.yMin),n=this.cropRegionFilterXMin.apply(t.xMin),r=this.cropRegionFilterYMax.apply(t.yMax),i=this.cropRegionFilterXMax.apply(t.xMax);return{yMin:e,xMin:n,yMax:r,xMax:i,height:r-e,width:i-n}}return this.cropRegionFilterYMin.reset(),this.cropRegionFilterXMin.reset(),this.cropRegionFilterYMax.reset(),this.cropRegionFilterXMax.reset(),null},e.prototype.dispose=function(){this.moveNetModel.dispose()},e.prototype.reset=function(){this.cropRegion=null,this.resetFilters()},e.prototype.resetFilters=function(){this.keypointFilter.reset(),this.cropRegionFilterYMin.reset(),this.cropRegionFilterXMin.reset(),this.cropRegionFilterYMax.reset(),this.cropRegionFilterXMax.reset()},e}();function Te(n){return void 0===n&&(n=ye),V(this,0,void 0,function(){var r,i,o,a;return G(this,function(s){switch(s.label){case 0:return r=function(t){var e,n=null==t?ye:H({},t);if(null==n.modelType)n.modelType="SinglePose.Lightning";else if(me.indexOf(n.modelType)<0)throw new Error("Invalid architecture ".concat(n.modelType,". ")+"Should be one of ".concat(me));if(null==n.enableSmoothing&&(n.enableSmoothing=!0),null!=n.minPoseScore&&(n.minPoseScore<0||n.minPoseScore>1))throw new Error("minPoseScore should be between 0.0 and 1.0");if(null!=n.multiPoseMaxDimension&&(n.multiPoseMaxDimension%32!=0||n.multiPoseMaxDimension<32))throw new Error("multiPoseMaxDimension must be a multiple of 32 and higher than 0");if("MultiPose.Lightning"===n.modelType&&null==n.enableTracking&&(n.enableTracking=!0),"MultiPose.Lightning"===n.modelType&&!0===n.enableTracking)if(null==n.trackerType&&(n.trackerType=se.BoundingBox),n.trackerType===se.Keypoint)null!=n.trackerConfig?n.trackerConfig=function(t){var e=ke(be,t);return e.keypointTrackerParams=H({},be.keypointTrackerParams),null!=t.keypointTrackerParams&&(null!=t.keypointTrackerParams.keypointConfidenceThreshold&&(e.keypointTrackerParams.keypointConfidenceThreshold=t.keypointTrackerParams.keypointConfidenceThreshold),null!=t.keypointTrackerParams.keypointFalloff&&(e.keypointTrackerParams.keypointFalloff=t.keypointTrackerParams.keypointFalloff),null!=t.keypointTrackerParams.minNumberOfKeypoints&&(e.keypointTrackerParams.minNumberOfKeypoints=t.keypointTrackerParams.minNumberOfKeypoints)),e}(n.trackerConfig):n.trackerConfig=be;else{if(n.trackerType!==se.BoundingBox)throw new Error("Tracker type not supported by MoveNet");null!=n.trackerConfig?n.trackerConfig=(e=n.trackerConfig,ke(we,e)):n.trackerConfig=we}return n}(n),o=!0,r.modelUrl?(o="string"==typeof r.modelUrl&&r.modelUrl.indexOf("https://tfhub.dev")>-1,[4,R(r.modelUrl,{fromTFHub:o})]):[3,2];case 1:return i=s.sent(),[3,4];case 2:return a=void 0,"SinglePose.Lightning"===r.modelType?a="https://tfhub.dev/google/tfjs-model/movenet/singlepose/lightning/4":"SinglePose.Thunder"===r.modelType?a="https://tfhub.dev/google/tfjs-model/movenet/singlepose/thunder/4":"MultiPose.Lightning"===r.modelType&&(a="https://tfhub.dev/google/tfjs-model/movenet/multipose/lightning/1"),[4,R(a,{fromTFHub:o})];case 3:i=s.sent(),s.label=4;case 4:return"webgl"===t()&&e().set("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD",0),[2,new Se(i,r)]}})})}var Me={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:{height:257,width:257}},_e=["MobileNetV1","ResNet50"],Ee={MobileNetV1:[8,16],ResNet50:[16]},Ae=[8,16,32],Fe={MobileNetV1:[.5,.75,1],ResNet50:[1]},Pe=[1,2,4],Oe={maxPoses:1,flipHorizontal:!1},Re={maxPoses:5,flipHorizontal:!1,scoreThreshold:.5,nmsRadius:20},Ie=[-123.15,-115.9,-103.06];function Ce(t){return Math.floor(t/2)}var Le=function(){function t(t,e){this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=e}return t.prototype.enqueue=function(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)},t.prototype.dequeue=function(){var t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t},t.prototype.empty=function(){return-1===this.numberOfElements},t.prototype.size=function(){return this.numberOfElements+1},t.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},t.prototype.max=function(){return this.priorityQueue[0]},t.prototype.swim=function(t){for(;t>0&&this.less(Ce(t),t);)this.exchange(t,Ce(t)),t=Ce(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(e<this.numberOfElements&&this.less(e,e+1)&&e++,!this.less(t,e))break;this.exchange(t,e),t=e}},t.prototype.getValueAt=function(t){return this.getElementValue(this.priorityQueue[t])},t.prototype.less=function(t,e){return this.getValueAt(t)<this.getValueAt(e)},t.prototype.exchange=function(t,e){var n=this.priorityQueue[t];this.priorityQueue[t]=this.priorityQueue[e],this.priorityQueue[e]=n},t}();function je(t,e,n,r,i,o){for(var a=o.shape,s=a[0],u=a[1],l=!0,h=Math.max(n-i,0),c=Math.min(n+i+1,s),f=h;f<c;++f){for(var p=Math.max(r-i,0),d=Math.min(r+i+1,u),m=p;m<d;++m)if(o.get(f,m,t)>e){l=!1;break}if(!l)break}return l}function Ne(t){return V(this,0,void 0,function(){return G(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}function Be(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+17)}}function ze(t,e,n){var r=Be(t.heatmapY,t.heatmapX,t.id,n),i=r.y,o=r.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+i}}function De(t,e,n,r){var i=n.x,o=n.y;return t.some(function(t){var n,a,s,u,l=t.keypoints;return n=o,a=i,(s=l[r].y-n)*s+(u=l[r].x-a)*u<=e})}var Ue=Y.reduce(function(t,e,n){return t[e]=n,t},{}),He=[["nose","left_eye"],["left_eye","left_ear"],["nose","right_eye"],["right_eye","right_ear"],["nose","left_shoulder"],["left_shoulder","left_elbow"],["left_elbow","left_wrist"],["left_shoulder","left_hip"],["left_hip","left_knee"],["left_knee","left_ankle"],["nose","right_shoulder"],["right_shoulder","right_elbow"],["right_elbow","right_wrist"],["right_shoulder","right_hip"],["right_hip","right_knee"],["right_knee","right_ankle"]].map(function(t){var e=t[0],n=t[1];return[Ue[e],Ue[n]]}),Ve=He.map(function(t){return t[1]}),Ge=He.map(function(t){return t[0]});function Ke(t,e,n){return t<e?e:t>n?n:t}function Ye(t,e,n,r){return{y:Ke(Math.round(t.y/e),0,n-1),x:Ke(Math.round(t.x/e),0,r-1)}}function Xe(t,e){return{x:t.x+e.x,y:t.y+e.y}}function We(t,e,n,r,i,o,a,s){void 0===s&&(s=2);for(var u=r.shape,l=u[0],h=u[1],c={y:e.y,x:e.x},f=Xe(c,function(t,e,n){var r=n.shape[2]/2;return{y:n.get(e.y,e.x,t),x:n.get(e.y,e.x,r+t)}}(t,Ye(c,o,l,h),a)),p=0;p<s;p++){var d=Ye(f,o,l,h),m=Be(d.y,d.x,n,i);f=Xe({x:d.x*o,y:d.y*o},{x:m.x,y:m.y})}var y=Ye(f,o,l,h),g=r.get(y.y,y.x,n);return{y:f.y,x:f.x,name:Y[n],score:g}}function qe(t,e,n,r,i,o){var a=e.shape[2],s=Ve.length,u=new Array(a),l=t.part,h=t.score,c=ze(l,r,n);u[l.id]={score:h,name:Y[l.id],y:c.y,x:c.x};for(var f=s-1;f>=0;--f){var p=Ve[f],d=Ge[f];u[p]&&!u[d]&&(u[d]=We(f,u[p],d,e,n,r,o))}for(f=0;f<s;++f)p=Ge[f],d=Ve[f],u[p]&&!u[d]&&(u[d]=We(f,u[p],d,e,n,r,i));return u}function Qe(t,e,n){return n.reduce(function(n,r,i){var o=r.y,a=r.x,s=r.score;return De(t,e,{y:o,x:a},i)||(n+=s),n},0)/n.length}function Je(t,e,n,r,i,o,a,s){return void 0===a&&(a=.5),void 0===s&&(s=20),V(this,0,void 0,function(){var u,l,h,c,f,p,d,m,y,g,v,b;return G(this,function(w){switch(w.label){case 0:return[4,Ne([t,e,n,r])];case 1:for(u=w.sent(),l=u[0],h=u[1],c=u[2],f=u[3],p=[],d=function(t,e,n){for(var r=n.shape,i=r[0],o=r[1],a=r[2],s=new Le(i*o*a,function(t){return t.score}),u=0;u<i;++u)for(var l=0;l<o;++l)for(var h=0;h<a;++h){var c=n.get(u,l,h);c<t||je(h,c,u,l,1,n)&&s.enqueue({score:c,part:{heatmapY:u,heatmapX:l,id:h}})}return s}(a,0,l),m=s*s;p.length<o&&!d.empty();)y=d.dequeue(),g=ze(y.part,i,h),De(p,m,g,y.part.id)||(v=qe(y,l,h,i,c,f),b=Qe(p,m,v),p.push({keypoints:v,score:b}));return[2,p]}})})}function Ze(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];switch(e.length){case 0:t="fn main() ";break;case 1:t="fn main(".concat(e[0]," : i32)");break;default:throw Error("Unreachable")}return t}var $e=function(){function t(t){this.variableNames=["A","B"],this.size=!0,this.workgroupSize=[32,1,1],this.outputShape=[t[0],1],this.dispatchLayout=C.flatDispatchLayout(this.outputShape),this.dispatch=C.computeDispatch(this.dispatchLayout,this.outputShape,this.workgroupSize),this.shaderKey="getpointsConfidenceOp"}return t.prototype.getUserCode=function(){return"\n ".concat(Ze("index")," {\n if (index < uniforms.size) {\n let y = B[index * 2];\n let x = B[index * 2 + 1];\n let outIndex = y * uniforms.aShape.x * uniforms.aShape.z + x * uniforms.aShape.z + index;\n result[index] = A[outIndex];\n }\n }\n ")},t}();var tn=function(){function t(t){if(this.variableNames=["A","B"],this.size=!0,this.supportedLastDimension=2,2!==t.length||t[1]!==this.supportedLastDimension)throw new Error("GetOffsetVectorsProgram only supports shape of [x, ".concat(this.supportedLastDimension,"], but current shape is ").concat(t));this.workgroupSize=[32,1,1],this.outputShape=t;var e=[t[0],1];this.dispatchLayout=C.flatDispatchLayout(e),this.dispatch=C.computeDispatch(this.dispatchLayout,e,this.workgroupSize),this.shaderKey="GetOffsetVectors"}return t.prototype.getUserCode=function(){return"\n fn getOffsetPoint(y: i32, x: i32, index: i32) -> vec2<i32> {\n let outIndexY = y * uniforms.bShape.x * uniforms.bShape.y + x * uniforms.bShape.y + index;\n let outIndexX = outIndexY + uniforms.bShape.z;\n let outY = i32(B[outIndexY]);\n let outX = i32(B[outIndexX]);\n return vec2<i32>(outY, outX);\n }\n\n ".concat(Ze("index")," {\n if (index < uniforms.size) {\n let indexY = index * ").concat(this.supportedLastDimension,";\n let indexX = indexY + 1;\n let heatmapY = A[indexY];\n let heatmapX = A[indexX];\n let out = getOffsetPoint(i32(heatmapY), i32(heatmapX), index);\n result[indexY] = f32(out[0]);\n result[indexX] = f32(out[1]);\n }\n }\n ")},t}();function en(t){var e=t.shape,r=e[0],o=e[1],a=e[2];return i(function(){var e,s,u=p(t,[r*o,a]),l=O(u,0),h=n(M(l,P(o,"int32")),1),c=n((e=l,s=o,i(function(){var t=M(e,P(s,"int32"));return w(e,S(t,P(s,"int32")))})),1);return _([h,c],1)})}function nn(t,e,n){return i(function(){var r=function(t,e){for(var n=[],r=0;r<Y.length;r++){var i=rn(t.get(r,0).valueOf(),t.get(r,1).valueOf(),r,e),a=i.x,s=i.y;n.push(s),n.push(a)}return o(n,[Y.length,2])}(t,n);return y(s(S(t.toTensor(),P(e,"int32")),"float32"),r)})}function rn(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+Y.length)}}function on(t,e,n){return V(this,0,void 0,function(){var r,i,o,a,s,u,l,h,c,f;return G(this,function(p){switch(p.label){case 0:return r=0,i=en(t),[4,Promise.all([t.buffer(),e.buffer(),i.buffer()])];case 1:return o=p.sent(),a=o[0],s=o[1],u=o[2],[4,(l=nn(u,n,s)).buffer()];case 2:return h=p.sent(),c=Array.from(function(t,e){for(var n=e.shape[0],r=new Float32Array(n),i=0;i<n;i++){var o=e.get(i,0),a=e.get(i,1);r[i]=t.get(o,a,i)}return r}(a,u)),f=c.map(function(t,e){return r+=t,{y:h.get(e,0),x:h.get(e,1),score:t,name:Y[e]}}),i.dispose(),l.dispose(),[2,{keypoints:f,score:r/f.length}]}})})}function an(t,e,n){return V(this,0,void 0,function(){var r,o,a;return G(this,function(u){return r=en(t),o=function(t,e,n){return i(function(){var r=function(t,e){if(v()instanceof I)return function(t,e){var n=v(),r=new tn(t.shape),i=n.runWebGPUProgram(r,[t,e],"float32");return b().makeTensorFromTensorInfo(i)}(t,e);throw new Error("getOffsetVectorsGPU is not supported in this backend!")}(t,n);return y(s(S(t,P(e,"int32")),"float32"),r)})}(r,n,e),a=function(t,e){if(v()instanceof I)return function(t,e){var n=v(),r=new $e(e.shape),i=n.runWebGPUProgram(r,[t,e],"float32");return b().makeTensorFromTensorInfo(i)}(t,e);throw new Error("getPointsConfidenceWebGPU is not supported in this backend!")}(t,r),[2,[o,a]]})})}function sn(t,e){return(t-1)%e==0}var un="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",ln="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";function hn(t,e){return function(t,e){return(t-1)%e==0}(t,e)?t:Math.floor(t/e)*e+1}var cn=function(){function t(t,e){this.posenetModel=t;var n=this.posenetModel.inputs[0].shape;F.assert(-1===n[1]&&-1===n[2],function(){return"Input shape [".concat(n[1],", ").concat(n[2],"] ")+"must both be equal to or -1"});var r,i,o=(r=e.inputResolution,i=e.outputStride,{height:hn(r.height,i),width:hn(r.width,i)});!function(t){F.assert(Ae.indexOf(t)>=0,function(){return"outputStride of ".concat(t," is invalid. ")+"It must be either 8 or 16."})}(e.outputStride),function(t,e){F.assert(sn(t.height,e),function(){return"height of ".concat(t.height," is invalid for output stride ")+"".concat(e,".")}),F.assert(sn(t.width,e),function(){return"width of ".concat(t.width," is invalid for output stride ")+"".concat(e,".")})}(o,e.outputStride),this.inputResolution=o,this.outputStride=e.outputStride,this.architecture=e.architecture}return t.prototype.estimatePoses=function(t,e){return void 0===e&&(e=Oe),V(this,0,void 0,function(){return G(this,function(n){return[2,this.estimatePosesGPU(t,e,!1)]})})},t.prototype.estimatePosesGPU=function(t,e,n){return void 0===e&&(e=Oe),void 0===n&&(n=!1),V(this,0,void 0,function(){var r,i,o,a,s,u,l,h,p,m,g,v,b,w,x,k,S,T;return G(this,function(M){switch(M.label){case 0:return r=function(t){var e=t;if(null==e.maxPoses&&(e.maxPoses=1),e.maxPoses<=0)throw new Error("Invalid maxPoses ".concat(e.maxPoses,". Should be > 0."));if(e.maxPoses>1){if((e=H(H({},Re),e)).scoreThreshold<0||e.scoreThreshold>1)throw new Error("Invalid scoreThreshold ".concat(e.scoreThreshold,". ")+"Should be in range [0.0, 1.0]");if(e.nmsRadius<=0)throw new Error("Invalid nmsRadius ".concat(e.nmsRadius,"."))}return e}(e),null==t?[2,n?[[],[]]:[]]:(this.maxPoses=r.maxPoses,i=bt(t,{outputTensorSize:this.inputResolution,keepAspectRatio:!0,borderMode:"replicate"}),o=i.imageTensor,a=i.padding,s="ResNet50"===this.architecture?y(o,Ie):vt(o,[-1,1]),u=this.posenetModel.predict(s),"ResNet50"===this.architecture?(l=f(u[2],[0]),h=f(u[3],[0]),p=f(u[0],[0]),m=f(u[1],[0])):(l=f(u[0],[0]),h=f(u[1],[0]),p=f(u[2],[0]),m=f(u[3],[0])),g=d(h),1!==this.maxPoses?[3,5]:n?[4,an(g,l,this.outputStride)]:[3,2]);case 1:return b=M.sent(),x=b[0],w=b[1],v=[x,w],[3,4];case 2:return[4,on(g,l,this.outputStride)];case 3:x=M.sent(),v=[x],M.label=4;case 4:return[3,7];case 5:if(n)throw new Error("GPU renderer only supports single pose!");return[4,Je(g,l,p,m,this.outputStride,this.maxPoses,r.scoreThreshold,r.nmsRadius)];case 6:v=M.sent(),M.label=7;case 7:if(n){if(!0===r.flipHorizontal)throw new Error("flipHorizontal is not supported!");k=this.getCanvasInfo(ut(t),this.inputResolution,a)}else T=ut(t),S=function(t,e,n,r){var i=e.height,o=e.width,a=i/(n.height*(1-r.top-r.bottom)),s=o/(n.width*(1-r.left-r.right)),u=-r.top*n.height,l=-r.left*n.width;if(1===s&&1===a&&0===u&&0===l)return t;for(var h=0,c=t;h<c.length;h++)for(var f=0,p=c[h].keypoints;f<p.length;f++){var d=p[f];d.x=(d.x+l)*s,d.y=(d.y+u)*a}return t}(v,T,this.inputResolution,a),r.flipHorizontal&&(S=function(t,e){for(var n=0,r=t;n<r.length;n++)for(var i=0,o=r[n].keypoints;i<o.length;i++){var a=o[i];a.x=e.width-1-a.x}return t}(S,T));return o.dispose(),s.dispose(),c(u),l.dispose(),h.dispose(),p.dispose(),m.dispose(),g.dispose(),[2,n?[v,k]:S]}})})},t.prototype.getCanvasInfo=function(t,e,n){var r=t.height,i=t.width,o=r/(e.height*(1-n.top-n.bottom)),a=i/(e.width*(1-n.left-n.right)),s=-n.top*e.height;return[-n.left*e.width,s,a,o,t.width,t.height]},t.prototype.dispose=function(){this.posenetModel.dispose()},t.prototype.reset=function(){},t}();function fn(t){return void 0===t&&(t=Me),V(this,0,void 0,function(){var e,n,r,i,o;return G(this,function(a){switch(a.label){case 0:return"ResNet50"!==(e=function(t){var e=t||Me;if(null==e.architecture&&(e.architecture="MobileNetV1"),_e.indexOf(e.architecture)<0)throw new Error("Invalid architecture ".concat(e.architecture,". ")+"Should be one of ".concat(_e));if(null==e.inputResolution&&(e.inputResolution={height:257,width:257}),null==e.outputStride&&(e.outputStride=16),Ee[e.architecture].indexOf(e.outputStride)<0)throw new Error("Invalid outputStride ".concat(e.outputStride,". ")+"Should be one of ".concat(Ee[e.architecture]," ")+"for architecture ".concat(e.architecture,"."));if(null==e.multiplier&&(e.multiplier=1),Fe[e.architecture].indexOf(e.multiplier)<0)throw new Error("Invalid multiplier ".concat(e.multiplier,". ")+"Should be one of ".concat(Fe[e.architecture]," ")+"for architecture ".concat(e.architecture,"."));if(null==e.quantBytes&&(e.quantBytes=4),Pe.indexOf(e.quantBytes)<0)throw new Error("Invalid quantBytes ".concat(e.quantBytes,". ")+"Should be one of ".concat(Pe," ")+"for architecture ".concat(e.architecture,"."));if("MobileNetV1"===e.architecture&&32===e.outputStride&&1!==e.multiplier)throw new Error("When using an output stride of 32, you must select 1 as the multiplier.");return e}(t)).architecture?[3,2]:(s=e.outputStride,u=e.quantBytes,l="model-stride".concat(s,".json"),n=4===u?ln+"float/"+l:ln+"quant".concat(u,"/")+l,[4,R(e.modelUrl||n)]);case 1:return r=a.sent(),[2,new cn(r,e)];case 2:return i=function(t,e,n){var r={1:"100",.75:"075",.5:"050"},i="model-stride".concat(t,".json");return 4===n?un+"float/".concat(r[e],"/")+i:un+"quant".concat(n,"/").concat(r[e],"/")+i}(e.outputStride,e.multiplier,e.quantBytes),[4,R(e.modelUrl||i)];case 3:return o=a.sent(),[2,new cn(o,e)]}var s,u,l})})}function pn(t,e){return V(this,0,void 0,function(){var n,r;return G(this,function(i){switch(t){case ue.PoseNet:return[2,fn(e)];case ue.BlazePose:if(r=void 0,null!=(n=e)){if("tfjs"===n.runtime)return[2,ae(e)];if("mediapipe"===n.runtime)return[2,st(e)];r=n.runtime}throw new Error("Expect modelConfig.runtime to be either 'tfjs' "+"or 'mediapipe', but got ".concat(r));case ue.MoveNet:return[2,Te(e)];default:throw new Error("".concat(t," is not a supported model name."))}})})}var dn={keypointsToNormalizedKeypoints:It},mn={modelType:{SINGLEPOSE_LIGHTNING:"SinglePose.Lightning",SINGLEPOSE_THUNDER:"SinglePose.Thunder",MULTIPOSE_LIGHTNING:"MultiPose.Lightning"}};export{ue as SupportedModels,se as TrackerType,dn as calculators,pn as createDetector,mn as movenet,de as util};
|
|
19
|
-
//# sourceMappingURL=pose-detection.esm-
|
|
19
|
+
//# sourceMappingURL=pose-detection.esm-EvS-BndH.mjs.map
|