@swan-admin/swan-web-component 1.0.122 → 1.0.124
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-C4Y72f4m.mjs +3 -0
- package/dist/BodyScan-C4Y72f4m.mjs.map +1 -0
- package/dist/BodyScan-CAAzIoLb.js +3 -0
- package/dist/BodyScan-CAAzIoLb.js.map +1 -0
- package/dist/{FaceScan-lUHosRqk.js → FaceScan-ClDsOhwN.js} +2 -2
- package/dist/{FaceScan-lUHosRqk.js.map → FaceScan-ClDsOhwN.js.map} +1 -1
- package/dist/{FaceScan-BdcqQIJ5.mjs → FaceScan-DEgrAZfU.mjs} +2 -2
- package/dist/{FaceScan-BdcqQIJ5.mjs.map → FaceScan-DEgrAZfU.mjs.map} +1 -1
- package/dist/Modal-Bo7k1S9H.js +3 -0
- package/dist/Modal-Bo7k1S9H.js.map +1 -0
- package/dist/Modal-CsO6kDBZ.mjs +3 -0
- package/dist/Modal-CsO6kDBZ.mjs.map +1 -0
- 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/index.mjs.map +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
- package/dist/Modal-DxgejzjH.js +0 -3
- package/dist/Modal-DxgejzjH.js.map +0 -1
- package/dist/Modal-TzaSySDr.mjs +0 -3
- package/dist/Modal-TzaSySDr.mjs.map +0 -1
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
* =============================================================================
|
|
18
18
|
*/function l(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}u(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 c(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 f(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 p(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 d=["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"],m=["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"],y={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]},g={left:[1,3,5,7,9,11,13,15],right:[2,4,6,8,10,12,14,16],middle:[0]},v=[[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]],b=[[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 w(t){return t instanceof SVGAnimatedLength?t.baseVal.value:t}function x(t){return c(this,0,void 0,function(){var n,r;return f(this,function(i){switch(i.label){case 0:return n=document.createElement("canvas"),t instanceof e.Tensor?[4,e.browser.toPixels(t,n)]:[3,2];case 1:return i.sent(),[3,3];case 2:n.width=w(t.width),n.height=w(t.height),r=n.getContext("2d"),t instanceof ImageData?r.putImageData(t,0,0):r.drawImage(t,0,0),i.label=3;case 3:return[2,n]}})})}function k(t){return c(this,0,void 0,function(){var n,r,i,o,a,s;return f(this,function(u){switch(u.label){case 0:return t instanceof e.Tensor?(n=t.shape.slice(0,2),r=n[0],i=n[1],o=ImageData.bind,[4,e.browser.toPixels(t)]):[3,2];case 1:return[2,new(o.apply(ImageData,[void 0,u.sent(),i,r]))];case 2:return a=document.createElement("canvas"),s=a.getContext("2d"),a.width=w(t.width),a.height=w(t.height),s.drawImage(t,0,0),[2,s.getImageData(0,0,a.width,a.height)]}})})}function T(t){return c(this,0,void 0,function(){var n,r;return f(this,function(i){switch(i.label){case 0:return t instanceof SVGImageElement||t instanceof OffscreenCanvas?[4,x(t)]:[3,2];case 1:return r=i.sent(),[3,3];case 2:r=t,i.label=3;case 3:return n=r,[2,e.browser.fromPixels(n,4)]}})})}function S(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 M={runtime:"mediapipe",enableSmoothing:!0,enableSegmentation:!1,smoothSegmentation:!0,modelType:"full"},_=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,this.mask]})})},t.prototype.toImageData=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,k(this.mask)]})})},t.prototype.toTensor=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,T(this.mask)]})})},t.prototype.getUnderlyingType=function(){return"canvasimagesource"},t}();function E(t){return S(t),"person"}var A=function(){function t(t){var e,n=this;switch(this.width=0,this.height=0,this.selfieMode=!1,this.poseSolution=new s.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:E,mask:new _(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:m[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:m[e]}})),r},t.prototype.estimatePoses=function(t,n,r){return c(this,0,void 0,function(){var i,o;return f(this,function(a){switch(a.label){case 0:return n&&n.flipHorizontal&&n.flipHorizontal!==this.selfieMode&&(this.selfieMode=n.flipHorizontal,this.poseSolution.setOptions({selfieMode:this.selfieMode})),t instanceof e.Tensor?(o=ImageData.bind,[4,e.browser.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},r)];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 F(t){return c(this,0,void 0,function(){var e,n;return f(this,function(r){switch(r.label){case 0:return e=function(t){if(null==t)return h({},M);var e=h({},t);return e.runtime="mediapipe",null==e.enableSegmentation&&(e.enableSegmentation=M.enableSegmentation),null==e.enableSmoothing&&(e.enableSmoothing=M.enableSmoothing),null==e.smoothSegmentation&&(e.smoothSegmentation=M.smoothSegmentation),null==e.modelType&&(e.modelType=M.modelType),e}(t),[4,(n=new A(e)).initialize()];case 1:return r.sent(),[2,n]}})})}function P(t){return t instanceof e.Tensor?{height:t.shape[0],width:t.shape[1]}:{height:t.height,width:t.width}}function O(t){return t-2*Math.PI*Math.floor((t+Math.PI)/(2*Math.PI))}function R(t){return t instanceof e.Tensor?t:e.browser.fromPixels(t)}function I(t,e,n){return C(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 C(t,n){e.util.assert(0!==t.width,function(){return"".concat(n," width cannot be 0.")}),e.util.assert(0!==t.height,function(){return"".concat(n," height cannot be 0.")})}function L(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 O(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 j(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 N(t,e,n,r,i,o,a){return t[e][i]*(t[n][o]*t[r][a]-t[n][a]*t[r][o])}function z(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 N(t,r,i,o,a,s,u)+N(t,i,o,r,a,s,u)+N(t,o,r,i,a,s,u)}function B(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,c=Math.cos(l)*s-Math.sin(l)*u,f=Math.sin(l)*s+Math.cos(l)*u;c=c*e.width+e.xCenter,f=f*e.height+e.yCenter;var p=a.z*e.width,d=h({},a);d.x=c,d.y=f,d.z=p,r.push(d)}return r}function D(t,n){var r=function(t,e,n,r){var i=(r-n)/255;return{scale:i,offset:n-0*i}}(0,0,n[0],n[1]);return e.tidy(function(){return e.add(e.mul(t,r.scale),r.offset)})}function U(t,n,r){var i,o,a,s,u,l,h,c,f,p,d,m,y=n.outputTensorSize,g=n.keepAspectRatio,v=n.borderMode,b=n.outputTensorFloatRange,w=P(t),x=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}}(w,r),k=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;C(e,"targetSize"),C(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}}(x,y,g),T=(i=x,o=w.width,a=w.height,s=i.width,u=i.height,l=Math.cos(i.rotation),h=Math.sin(i.rotation),c=i.xCenter,f=i.yCenter,p=1/o,d=1/a,(m=new Array(16))[0]=s*l*1*p,m[1]=-u*h*p,m[2]=0,m[3]=(-.5*s*l*1+.5*u*h+c)*p,m[4]=s*h*1*d,m[5]=u*l*d,m[6]=0,m[7]=(-.5*u*l-.5*s*h*1+f)*d,m[8]=0,m[9]=0,m[10]=s*p,m[11]=0,m[12]=0,m[13]=0,m[14]=0,m[15]=1,j(m));return{imageTensor:e.tidy(function(){var n=R(t),r=e.tensor2d(I(T,w,y),[1,8]),i="zero"===v?"constant":"nearest",o=e.image.transform(e.expandDims(e.cast(n,"float32")),r,"bilinear",i,0,[y.height,y.width]);return null!=b?D(o,b):o}),padding:k,transformationMatrix:T}}function H(t,e,n,r){return 1===r?.5*(t+e):t+(e-t)*n/(r-1)}function V(t){return null!=t&&null!=t.currentTime}function G(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 K(t,n,r,i){return c(this,0,void 0,function(){var i,o,a,s,u;return f(this,function(l){switch(l.label){case 0:return t.sort(function(t,e){return Math.max.apply(Math,e.score)-Math.max.apply(Math,t.score)}),i=e.tensor2d(t.map(function(t){return[t.locationData.relativeBoundingBox.yMin,t.locationData.relativeBoundingBox.xMin,t.locationData.relativeBoundingBox.yMax,t.locationData.relativeBoundingBox.xMax]})),o=e.tensor1d(t.map(function(t){return t.score[0]})),[4,e.image.nonMaxSuppressionAsync(i,o,n,r)];case 1:return[4,(a=l.sent()).array()];case 2:return s=l.sent(),u=t.filter(function(t,e){return s.indexOf(e)>-1}),e.dispose([i,o,a]),[2,u]}})})}function q(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 Y(t,n,r){return c(this,0,void 0,function(){var i,o,a,s,u,l,c,p,d,m,y,g,v,b,w,x,k,T,S,M,_,E,A,F;return f(this,function(f){switch(f.label){case 0:if(i=e.squeeze(n,[0]),o=i.shape,a=o[0],s=o[1],u=o[2],t.length!==u)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(u));return l=[],[4,i.buffer()];case 1:for(c=f.sent(),p=0;p<t.length;p++)if(d=t[p],m=h({},d),l.push(m),y=Math.trunc(m.x*s),g=Math.trunc(m.y*a),!(y<0||y>=s||g<0||y>=a)){for(v=Math.trunc((r.kernelSize-1)/2),b=Math.max(0,y-v),w=Math.min(s,y+v+1),x=Math.max(0,g-v),k=Math.min(a,g+v+1),T=0,S=0,M=0,_=0,E=x;E<k;++E)for(A=b;A<w;++A)F=c.get(E,A,p),T+=F,_=Math.max(_,F),S+=A*F,M+=E*F;_>=r.minConfidenceToRefine&&T>0&&(m.x=S/s/T,m.y=M/a/T)}return i.dispose(),[2,l]}})})}function X(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 W(t,n,r){return c(this,0,void 0,function(){var i,o,a,s,u;return f(this,function(l){switch(l.label){case 0:return i=t[0],o=t[1],a=function(t,n,r){return e.tidy(function(){var i,o,a,s;r.reverseOutputOrder?(o=e.squeeze(e.slice(t,[0,r.boxCoordOffset+0],[-1,1])),i=e.squeeze(e.slice(t,[0,r.boxCoordOffset+1],[-1,1])),s=e.squeeze(e.slice(t,[0,r.boxCoordOffset+2],[-1,1])),a=e.squeeze(e.slice(t,[0,r.boxCoordOffset+3],[-1,1]))):(i=e.squeeze(e.slice(t,[0,r.boxCoordOffset+0],[-1,1])),o=e.squeeze(e.slice(t,[0,r.boxCoordOffset+1],[-1,1])),a=e.squeeze(e.slice(t,[0,r.boxCoordOffset+2],[-1,1])),s=e.squeeze(e.slice(t,[0,r.boxCoordOffset+3],[-1,1]))),o=e.add(e.mul(e.div(o,r.xScale),n.w),n.x),i=e.add(e.mul(e.div(i,r.yScale),n.h),n.y),r.applyExponentialOnBoxSize?(a=e.mul(e.exp(e.div(a,r.hScale)),n.h),s=e.mul(e.exp(e.div(s,r.wScale)),n.w)):(a=e.mul(e.div(a,r.hScale),n.h),s=e.mul(e.div(s,r.wScale),n.h));var u=e.sub(i,e.div(a,2)),l=e.sub(o,e.div(s,2)),h=e.add(i,e.div(a,2)),c=e.add(o,e.div(s,2)),f=e.concat([e.reshape(u,[r.numBoxes,1]),e.reshape(l,[r.numBoxes,1]),e.reshape(h,[r.numBoxes,1]),e.reshape(c,[r.numBoxes,1])],1);if(r.numKeypoints)for(var p=0;p<r.numKeypoints;++p){var d=r.keypointCoordOffset+p*r.numValuesPerKeypoint,m=void 0,y=void 0;r.reverseOutputOrder?(m=e.squeeze(e.slice(t,[0,d],[-1,1])),y=e.squeeze(e.slice(t,[0,d+1],[-1,1]))):(y=e.squeeze(e.slice(t,[0,d],[-1,1])),m=e.squeeze(e.slice(t,[0,d+1],[-1,1])));var g=e.add(e.mul(e.div(m,r.xScale),n.w),n.x),v=e.add(e.mul(e.div(y,r.yScale),n.h),n.y);f=e.concat([f,e.reshape(g,[r.numBoxes,1]),e.reshape(v,[r.numBoxes,1])],1)}return f})}(o,n,r),s=e.tidy(function(){var t=i;return r.sigmoidScore?(null!=r.scoreClippingThresh&&(t=e.clipByValue(i,-r.scoreClippingThresh,r.scoreClippingThresh)),t=e.sigmoid(t)):t}),[4,Q(a,s,r)];case 1:return u=l.sent(),e.dispose([a,s]),[2,u]}})})}function Q(t,e,n){return c(this,0,void 0,function(){var r,i,o,a,s,u,l,h,c,p,d,m;return f(this,function(f){switch(f.label){case 0:return r=[],[4,t.data()];case 1:return i=f.sent(),[4,e.data()];case 2:for(o=f.sent(),a=0;a<n.numBoxes;++a)if(!(null!=n.minScoreThresh&&o[a]<n.minScoreThresh||(s=a*n.numCoords,u=J(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,p=0;p<c;p+=n.numValuesPerKeypoint)d=s+n.keypointCoordOffset+p,m={x:i[d+0],y:n.flipVertically?1-i[d+1]:i[d+1]},h.relativeKeypoints.push(m);r.push(u)}return[2,r]}})})}function J(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 Z(t,e){return"none"===t?e:function(t){return 1/(1+Math.exp(-t))}(e)}function $(t,e,n,r){return c(this,0,void 0,function(){var i,o,a,s,u,l,h,c;return f(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=Z(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 tt(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),O(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 et(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 nt=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}(),rt=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 nt(this.getAlpha(this.minCutOff)),this.dx=new nt(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}(),it=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 p([],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 rt(e.config)}),this.yFilters=t.map(function(t){return new rt(e.config)}),this.zFilters=t.map(function(t){return new rt(e.config)}))},t}(),ot=function(){function t(t){this.config=t,this.window=[],this.lowPassFilter=new nt(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}(),at=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 p([],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 ot(e.config)}),this.yFilters=t.map(function(t){return new ot(e.config)}),this.zFilters=t.map(function(t){return new ot(e.config)}))},t}(),st=function(){function t(t){if(null!=t.velocityFilter)this.keypointsFilter=new at(t.velocityFilter);else{if(null==t.oneEuroFilter)throw new Error("Either configure velocityFilter or oneEuroFilter, but got "+"".concat(t,"."));this.keypointsFilter=new it(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?q(t,n):t,s=this.keypointsFilter.apply(a,e,o);return r?et(s,n):s},t}(),ut=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 nt(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}(),lt={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"},ct={maxPoses:1,flipHorizontal:!1},ft={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},pt={shiftX:0,shiftY:0,scaleX:1.25,scaleY:1.25},dt={outputTensorSize:{width:224,height:224},keepAspectRatio:!0,outputTensorFloatRange:[-1,1],borderMode:"zero"},mt={outputTensorSize:{width:256,height:256},keepAspectRatio:!0,outputTensorFloatRange:[0,1],borderMode:"zero"},yt={numLandmarks:39,inputImageWidth:256,inputImageHeight:256,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},gt={numLandmarks:39,inputImageWidth:1,inputImageHeight:1,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},vt={kernelSize:7,minConfidenceToRefine:.5},bt={alpha:.1},wt={oneEuroFilter:{frequency:30,minCutOff:.05,beta:80,derivateCutOff:1,minAllowedObjectScale:1e-6}},xt={oneEuroFilter:{frequency:30,minCutOff:.01,beta:10,derivateCutOff:1,minAllowedObjectScale:1e-6}},kt={oneEuroFilter:{frequency:30,minCutOff:.1,beta:40,derivateCutOff:1,minAllowedObjectScale:1e-6,disableValueScaling:!0}},Tt={activation:"none"},St={combineWithPreviousRatio:.7},Mt=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,x(this.mask)]})})},t.prototype.toImageData=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,k(this.mask)]})})},t.prototype.toTensor=function(){return c(this,0,void 0,function(){return f(this,function(t){return[2,this.mask]})})},t.prototype.getUnderlyingType=function(){return"tensor"},t}();function _t(t){return S(t),"person"}var Et=function(){function t(t,n,r,i,o,a){this.detectorModel=t,this.landmarkModel=n,this.enableSmoothing=r,this.enableSegmentation=i,this.smoothSegmentation=o,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=H(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:H(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}(lt);var s=e.tensor1d(this.anchors.map(function(t){return t.width})),u=e.tensor1d(this.anchors.map(function(t){return t.height})),l=e.tensor1d(this.anchors.map(function(t){return t.xCenter})),h=e.tensor1d(this.anchors.map(function(t){return t.yCenter}));this.anchorTensor={x:l,y:h,w:s,h:u},this.prevFilteredSegmentationMask=this.enableSegmentation?e.tensor2d([],[0,0]):null}return t.prototype.estimatePoses=function(t,n,r){return c(this,0,void 0,function(){var i,o,a,s,u,l,c,p,d,y,g,v,b,w,x,k,T,S,M,_,E,A,F;return f(this,function(f){switch(f.label){case 0:return i=function(t){var e;if(null==(e=null==t?ct: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}(n),null==t?(this.reset(),[2,[]]):(this.maxPoses=i.maxPoses,this.timestamp=null!=r?1e3*r:V(t)?1e6*t.currentTime:null,o=P(t),a=e.tidy(function(){return e.cast(R(t),"float32")}),null!=(s=this.regionOfInterest)?[3,2]:[4,this.detectPose(a)]);case 1:if(0===(u=f.sent()).length)return this.reset(),a.dispose(),[2,[]];l=u[0],s=this.poseDetectionToRoi(l,o),f.label=2;case 2:return[4,this.poseLandmarksByRoi(s,a)];case 3:return c=f.sent(),a.dispose(),null==c?(this.reset(),[2,[]]):(p=c.landmarks,d=c.auxiliaryLandmarks,y=c.poseScore,g=c.worldLandmarks,v=c.segmentationMask,b=this.poseLandmarkFiltering(p,d,g,o),w=b.actualLandmarksFiltered,x=b.auxiliaryLandmarksFiltered,k=b.actualWorldLandmarksFiltered,T=this.poseLandmarksToRoi(x,o),this.regionOfInterest=T,S=this.smoothSegmentation&&null!=v?this.poseSegmentationFiltering(v):v,null!=(M=null!=w?q(w,o):null)&&M.forEach(function(t,e){t.name=m[e]}),null!=(_=k)&&_.forEach(function(t,e){t.name=m[e]}),E={score:y,keypoints:M,keypoints3D:_},null!==S&&(A=e.tidy(function(){var t=e.expandDims(S,2),n=e.pad(t,[[0,0],[0,0],[0,1]]);return e.mirrorPad(n,[[0,0],[0,0],[0,2]],"symmetric")}),this.smoothSegmentation||e.dispose(S),F={maskValueToLabel:_t,mask:new Mt(A)},E.segmentation=F),[2,[E]])}})})},t.prototype.poseSegmentationFiltering=function(t){var n=this.prevFilteredSegmentationMask;return 0===n.size?this.prevFilteredSegmentationMask=t:(this.prevFilteredSegmentationMask=function(t,n,r){return"webgl"===e.getBackend()?function(t,n,r){var i=r.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(i,");\n\n setOutput(outputValue);\n }\n")},a=e.backend();return e.tidy(function(){var r=a.compileAndRun(o,[t,n]);return e.engine().makeTensorFromDataId(r.dataId,r.shape,r.dtype)})}(t,n,r):e.tidy(function(){var i=e.sub(n,.5),o=e.square(i),a=e.sub(1,e.minimum(1,e.mul(o,e.add(5.68842,e.mul(o,e.add(-.748699,e.mul(o,e.add(-57.8051,e.mul(o,e.add(291.309,e.mul(o,-624.717)))))))))));return e.add(n,e.mul(e.sub(t,n),e.mul(a,r.combineWithPreviousRatio)))})}(n,t,St),e.dispose(t)),e.dispose(n),this.prevFilteredSegmentationMask},t.prototype.dispose=function(){this.detectorModel.dispose(),this.landmarkModel.dispose(),e.dispose([this.anchorTensor.x,this.anchorTensor.y,this.anchorTensor.w,this.anchorTensor.h,this.prevFilteredSegmentationMask])},t.prototype.reset=function(){this.regionOfInterest=null,this.enableSegmentation&&(e.dispose(this.prevFilteredSegmentationMask),this.prevFilteredSegmentationMask=e.tensor2d([],[0,0])),this.visibilitySmoothingFilterActual=null,this.visibilitySmoothingFilterAuxiliary=null,this.landmarksSmoothingFilterActual=null,this.landmarksSmoothingFilterAuxiliary=null},t.prototype.detectPose=function(t){return c(this,0,void 0,function(){var n,r,i,o,a,s,u,l,h,c;return f(this,function(f){switch(f.label){case 0:return n=U(t,dt),r=n.imageTensor,i=n.padding,o=this.detectorModel.predict(r),a=function(t){return e.tidy(function(){var n=function(t){return e.tidy(function(){return[e.slice(t,[0,0,0],[1,-1,1]),e.slice(t,[0,0,1],[1,-1,-1])]})}(t),r=n[0],i=n[1];return{boxes:e.squeeze(i),logits:e.squeeze(r)}})}(o),s=a.boxes,[4,W([u=a.logits,s],this.anchorTensor,ft)];case 1:return 0===(l=f.sent()).length?(e.dispose([r,o,u,s]),[2,l]):[4,K(l,this.maxPoses,.3)];case 2:return h=f.sent(),c=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,i),e.dispose([r,o,u,s]),[2,c]}})})},t.prototype.poseDetectionToRoi=function(t,e){return tt(L(t,e,{rotationVectorEndKeypointIndex:1,rotationVectorStartKeypointIndex:0,rotationVectorTargetAngleDegree:90}),e,pt)},t.prototype.poseLandmarksByRoi=function(t,n){return c(this,0,void 0,function(){var r,i,o,a,s,u,l,c,p,d,m,y,g,v;return f(this,function(f){switch(f.label){case 0:if(r=P(n),i=U(n,mt,t),o=i.imageTensor,a=i.padding,s=i.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 u=["ld_3d","output_poseflag","activation_heatmap","world_3d"],this.enableSegmentation&&u.push("activation_segmentation"),l=this.landmarkModel.execute(o,u),[4,this.tensorsToPoseLandmarksAndSegmentation(l)];case 1:return null==(c=f.sent())?(e.dispose(l),e.dispose(o),[2,null]):(p=c.landmarks,d=c.auxiliaryLandmarks,m=c.poseScore,y=c.worldLandmarks,g=c.segmentationMask,[4,this.poseLandmarksAndSegmentationInverseProjection(r,t,a,s,p,d,y,g)]);case 2:return v=f.sent(),e.dispose(l),e.dispose(o),[2,h({poseScore:m},v)]}})})},t.prototype.poseLandmarksAndSegmentationInverseProjection=function(t,n,r,i,o,a,s,u){return c(this,0,void 0,function(){var l,c,p,d,m,y;return f(this,function(f){return l=X(o,r),c=X(a,r),p=B(l,n),d=B(c,n),m=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,c=Math.sin(u)*a+Math.cos(u)*s,f=h({},o);f.x=l,f.y=c,n.push(f)}return n}(s,n),y=null,this.enableSegmentation&&(y=e.tidy(function(){var n=u.shape,r=n[0],o=n[1],a=function(t){var e=j(new Array(16).fill(0));e[0][0]=z(t,0,0),e[1][0]=-z(t,0,1),e[2][0]=z(t,0,2),e[3][0]=-z(t,0,3),e[0][2]=z(t,2,0),e[1][2]=-z(t,2,1),e[2][2]=z(t,2,2),e[3][2]=-z(t,2,3),e[0][1]=-z(t,1,0),e[1][1]=z(t,1,1),e[2][1]=-z(t,1,2),e[3][1]=z(t,1,3),e[0][3]=-z(t,3,0),e[1][3]=z(t,3,1),e[2][3]=-z(t,3,2),e[3][3]=z(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}(i),s=e.tensor2d(I(a,{width:o,height:r},t),[1,8]),l=[1,r,o,1];return e.squeeze(e.image.transform(e.reshape(u,l),s,"bilinear","constant",0,[t.height,t.width]),[0,3])}),e.dispose(u)),[2,{landmarks:p,auxiliaryLandmarks:d,worldLandmarks:m,segmentationMask:y}]})})},t.prototype.tensorsToPoseLandmarksAndSegmentation=function(t){return c(this,0,void 0,function(){var n,r,i,o,a,s,u,l,c,p,d,m,y;return f(this,function(f){switch(f.label){case 0:return n=t[0],r=t[1],i=t[2],o=t[3],a=this.enableSegmentation?t[4]:null,[4,r.data()];case 1:return(s=f.sent()[0])<.5?[2,null]:[4,$(n,yt)];case 2:return[4,Y(f.sent(),i,vt)];case 3:return u=f.sent(),l=u.slice(0,33),c=u.slice(33,35),[4,$(o,gt)];case 4:return p=f.sent(),d=p.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,d),y=this.enableSegmentation?function(t,n){return e.tidy(function(){var r=e.squeeze(t,[0]),i=r.shape[2];if(1===i){var o=r;switch(n.activation){case"none":break;case"sigmoid":o=e.sigmoid(o);break;case"softmax":throw new Error("Softmax activation requires two channels.");default:throw new Error("Activation not supported (".concat(n.activation,")"))}var a=o;return e.squeeze(a,[2])}throw new Error("Unsupported number of tensor channels ".concat(i))})}(a,Tt):null,[2,{landmarks:l,auxiliaryLandmarks:c,poseScore:s,worldLandmarks:m,segmentationMask:y}]}})})},t.prototype.poseLandmarksToRoi=function(t,e){return tt(L(G(t),e,{rotationVectorStartKeypointIndex:0,rotationVectorEndKeypointIndex:1,rotationVectorTargetAngleDegree:90}),e,pt)},t.prototype.poseLandmarkFiltering=function(t,e,n,r){var i,o,a;if(null!=this.timestamp&&this.enableSmoothing){var s=L(G(e),r,{rotationVectorEndKeypointIndex:0,rotationVectorStartKeypointIndex:1,rotationVectorTargetAngleDegree:90});null==this.visibilitySmoothingFilterActual&&(this.visibilitySmoothingFilterActual=new ut(bt)),i=this.visibilitySmoothingFilterActual.apply(t),null==this.visibilitySmoothingFilterAuxiliary&&(this.visibilitySmoothingFilterAuxiliary=new ut(bt)),o=this.visibilitySmoothingFilterAuxiliary.apply(e),a=this.visibilitySmoothingFilterActual.apply(n),null==this.landmarksSmoothingFilterActual&&(this.landmarksSmoothingFilterActual=new st(wt)),i=this.landmarksSmoothingFilterActual.apply(i,this.timestamp,r,!0,s),null==this.landmarksSmoothingFilterAuxiliary&&(this.landmarksSmoothingFilterAuxiliary=new st(xt)),o=this.landmarksSmoothingFilterAuxiliary.apply(o,this.timestamp,r,!0,s),null==this.worldLandmarksSmoothingFilterActual&&(this.worldLandmarksSmoothingFilterActual=new st(kt)),a=this.worldLandmarksSmoothingFilterActual.apply(n,this.timestamp)}else i=t,o=e,a=n;return{actualLandmarksFiltered:i,auxiliaryLandmarksFiltered:o,actualWorldLandmarksFiltered:a}},t}();function At(t){return c(this,0,void 0,function(){var e,r,i,o,a,s;return f(this,function(u){switch(u.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),r="string"==typeof e.detectorModelUrl&&e.detectorModelUrl.indexOf("https://tfhub.dev")>-1,i="string"==typeof e.landmarkModelUrl&&e.landmarkModelUrl.indexOf("https://tfhub.dev")>-1,[4,Promise.all([n.loadGraphModel(e.detectorModelUrl,{fromTFHub:r}),n.loadGraphModel(e.landmarkModelUrl,{fromTFHub:i})])];case 1:return o=u.sent(),a=o[0],s=o[1],[2,new Et(a,s,e.enableSmoothing,e.enableSegmentation,e.smoothSegmentation,e.modelType)]}})})}exports.TrackerType=void 0,exports.SupportedModels=void 0;var Ft,Pt=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:p([],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}(),Ot=function(t){function e(e){return t.call(this,e)||this}return l(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}(Pt),Rt=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 l(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,p([1],n.map(function(t){return t.x}),!1)),i=Math.max.apply(Math,p([0],n.map(function(t){return t.x}),!1)),o=Math.min.apply(Math,p([1],n.map(function(t){return t.y}),!1));return(i-r)*(Math.max.apply(Math,p([0],n.map(function(t){return t.y}),!1))-o)},e}(Pt);function It(t){switch(t){case exports.SupportedModels.BlazePose:return m.reduce(function(t,e,n){return t[e]=n,t},{});case exports.SupportedModels.PoseNet:case exports.SupportedModels.MoveNet:return d.reduce(function(t,e,n){return t[e]=n,t},{});default:throw new Error("Model ".concat(t," is not supported."))}}(Ft=exports.TrackerType||(exports.TrackerType={})).Keypoint="keypoint",Ft.BoundingBox="boundingBox",function(t){t.MoveNet="MoveNet",t.BlazePose="BlazePose",t.PoseNet="PoseNet"}(exports.SupportedModels||(exports.SupportedModels={}));var Ct=Object.freeze({__proto__:null,getKeypointIndexBySide:function(t){switch(t){case exports.SupportedModels.BlazePose:return y;case exports.SupportedModels.PoseNet:case exports.SupportedModels.MoveNet:return g;default:throw new Error("Model ".concat(t," is not supported."))}},getAdjacentPairs:function(t){switch(t){case exports.SupportedModels.BlazePose:return b;case exports.SupportedModels.PoseNet:case exports.SupportedModels.MoveNet:return v;default:throw new Error("Model ".concat(t," is not supported."))}},getKeypointIndexByName:It}),Lt=["SinglePose.Lightning","SinglePose.Thunder","MultiPose.Lightning"],jt={modelType:"SinglePose.Lightning",enableSmoothing:!0},Nt={},zt={frequency:30,minCutOff:2.5,beta:300,derivateCutOff:2.5,thresholdCutOff:.5,thresholdBeta:5,disableValueScaling:!0},Bt={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}},Dt={maxTracks:18,maxAge:1e3,minSimilarity:.15,trackerParams:{}};function Ut(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 Ht(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 Vt=function(){function t(t,e){this.moveNetModel=t,this.modelInputResolution={height:0,width:0},this.keypointIndexByName=It(exports.SupportedModels.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 it(zt),this.cropRegionFilterYMin=new nt(.9),this.cropRegionFilterXMin=new nt(.9),this.cropRegionFilterYMax=new nt(.9),this.cropRegionFilterXMax=new nt(.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===exports.TrackerType.Keypoint?this.tracker=new Rt(e.trackerConfig):e.trackerType===exports.TrackerType.BoundingBox&&(this.tracker=new Ot(e.trackerConfig)),this.enableSmoothing&&(this.keypointFilterMap=new Map))}return t.prototype.runSinglePersonPoseModel=function(t){return c(this,0,void 0,function(){var n,r,i,o,a;return f(this,function(s){switch(s.label){case 0:if(4!==(n=this.moveNetModel.execute(t)).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"===e.getBackend()?[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]}})})},t.prototype.runMultiPersonPoseModel=function(t){return c(this,0,void 0,function(){var n,r,i,o,a,s,u,l;return f(this,function(h){switch(h.label){case 0:if(3!==(n=this.moveNetModel.execute(t)).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"===e.getBackend()?[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]}})})},t.prototype.estimatePoses=function(t,n,r){return void 0===n&&(n=Nt),c(this,0,void 0,function(){var i,o,a,s,u,l;return f(this,function(c){switch(c.label){case 0:return n=function(t){return null==t?Nt:h({},t)}(n),null==t?(this.reset(),[2,[]]):(null==r?V(t)&&(r=1e6*t.currentTime):r*=1e3,i=R(t),o=P(i),a=e.expandDims(i,0),t instanceof e.Tensor||i.dispose(),s=[],this.multiPoseModel?[3,2]:[4,this.estimateSinglePose(a,o,r)]);case 1:return s=c.sent(),[3,4];case 2:return[4,this.estimateMultiplePoses(a,o,r)];case 3:s=c.sent(),c.label=4;case 4:for(u=0;u<s.length;++u)for(l=0;l<s[u].keypoints.length;++l)s[u].keypoints[l].name=d[l],s[u].keypoints[l].y*=o.height,s[u].keypoints[l].x*=o.width;return[2,s]}})})},t.prototype.estimateSinglePose=function(t,n,r){return c(this,0,void 0,function(){var i,o,a,s,u=this;return f(this,function(l){switch(l.label){case 0:return this.cropRegion||(this.cropRegion=Ut(null==this.cropRegion,n)),i=e.tidy(function(){var n=e.tensor2d([[u.cropRegion.yMin,u.cropRegion.xMin,u.cropRegion.yMax,u.cropRegion.xMax]]),r=e.zeros([1],"int32"),i=[u.modelInputResolution.height,u.modelInputResolution.width];return e.cast(e.image.cropAndResize(t,n,r,i,"bilinear",0),"int32")}),t.dispose(),[4,this.runSinglePersonPoseModel(i)];case 1:if(o=l.sent(),i.dispose(),o.score<this.minPoseScore)return this.reset(),[2,[]];for(a=0;a<o.keypoints.length;++a)o.keypoints[a].y=this.cropRegion.yMin+o.keypoints[a].y*this.cropRegion.height,o.keypoints[a].x=this.cropRegion.xMin+o.keypoints[a].x*this.cropRegion.width;return null!=r&&this.enableSmoothing&&(o.keypoints=this.keypointFilter.apply(o.keypoints,r,1)),s=function(t,e,n,r){for(var i={},o=0,a=d;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],m=h[3],y=Math.max(1.9*f,1.9*c,1.2*p,1.2*m),g=[u-(y=Math.min(y,Math.max(l,r.width-l,u,r.height-u))),l-y];if(y>Math.max(r.width,r.height)/2)return Ut(null==t,r);var v=2*y;return{yMin:g[0]/r.height,xMin:g[1]/r.width,yMax:(g[0]+v)/r.height,xMax:(g[1]+v)/r.width,height:(g[0]+v)/r.height-g[0]/r.height,width:(g[1]+v)/r.width-g[1]/r.width}}return Ut(null==t,r)}(this.cropRegion,o.keypoints,this.keypointIndexByName,n),this.cropRegion=this.filterCropRegion(s),[2,[o]]}})})},t.prototype.estimateMultiplePoses=function(t,n,r){return c(this,0,void 0,function(){var i,o,a,s,u,l,h,c,p,d,m,y=this;return f(this,function(f){switch(f.label){case 0:return n.width>n.height?(o=this.multiPoseMaxDimension,a=Math.round(this.multiPoseMaxDimension*n.height/n.width),i=e.image.resizeBilinear(t,[a,o]),u=o,l=32*Math.ceil(a/32),s=e.pad(i,[[0,0],[0,l-a],[0,0],[0,0]])):(o=Math.round(this.multiPoseMaxDimension*n.width/n.height),a=this.multiPoseMaxDimension,i=e.image.resizeBilinear(t,[a,o]),u=32*Math.ceil(o/32),l=a,s=e.pad(i,[[0,0],[0,0],[0,u-o],[0,0]])),i.dispose(),t.dispose(),h=e.cast(s,"int32"),s.dispose(),[4,this.runMultiPersonPoseModel(h)];case 1:for(c=f.sent(),h.dispose(),c=c.filter(function(t){return t.score>=y.minPoseScore}),d=0;d<c.length;++d)for(p=0;p<c[d].keypoints.length;++p)c[d].keypoints[p].y*=l/a,c[d].keypoints[p].x*=u/o;if(this.enableTracking&&(this.tracker.apply(c,r),this.enableSmoothing)){for(d=0;d<c.length;++d)this.keypointFilterMap.has(c[d].id)||this.keypointFilterMap.set(c[d].id,new it(zt)),c[d].keypoints=this.keypointFilterMap.get(c[d].id).apply(c[d].keypoints,r,1);m=this.tracker.getTrackIDs(),this.keypointFilterMap.forEach(function(t,e){m.has(e)||y.keypointFilterMap.delete(e)})}return[2,c]}})})},t.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},t.prototype.dispose=function(){this.moveNetModel.dispose()},t.prototype.reset=function(){this.cropRegion=null,this.resetFilters()},t.prototype.resetFilters=function(){this.keypointFilter.reset(),this.cropRegionFilterYMin.reset(),this.cropRegionFilterXMin.reset(),this.cropRegionFilterYMax.reset(),this.cropRegionFilterXMax.reset()},t}();function Gt(t){return void 0===t&&(t=jt),c(this,0,void 0,function(){var r,i,o,a;return f(this,function(s){switch(s.label){case 0:return r=function(t){var e,n=null==t?jt:h({},t);if(null==n.modelType)n.modelType="SinglePose.Lightning";else if(Lt.indexOf(n.modelType)<0)throw new Error("Invalid architecture ".concat(n.modelType,". ")+"Should be one of ".concat(Lt));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=exports.TrackerType.BoundingBox),n.trackerType===exports.TrackerType.Keypoint)null!=n.trackerConfig?n.trackerConfig=function(t){var e=Ht(Bt,t);return e.keypointTrackerParams=h({},Bt.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=Bt;else{if(n.trackerType!==exports.TrackerType.BoundingBox)throw new Error("Tracker type not supported by MoveNet");null!=n.trackerConfig?n.trackerConfig=(e=n.trackerConfig,Ht(Dt,e)):n.trackerConfig=Dt}return n}(t),o=!0,r.modelUrl?(o="string"==typeof r.modelUrl&&r.modelUrl.indexOf("https://tfhub.dev")>-1,[4,n.loadGraphModel(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,n.loadGraphModel(a,{fromTFHub:o})];case 3:i=s.sent(),s.label=4;case 4:return"webgl"===e.getBackend()&&e.env().set("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD",0),[2,new Vt(i,r)]}})})}var Kt={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:{height:257,width:257}},qt=["MobileNetV1","ResNet50"],Yt={MobileNetV1:[8,16],ResNet50:[16]},Xt=[8,16,32],Wt={MobileNetV1:[.5,.75,1],ResNet50:[1]},Qt=[1,2,4],Jt={maxPoses:1,flipHorizontal:!1},Zt={maxPoses:5,flipHorizontal:!1,scoreThreshold:.5,nmsRadius:20},$t=[-123.15,-115.9,-103.06];function te(t){return Math.floor(t/2)}var ee=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(te(t),t);)this.exchange(t,te(t)),t=te(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 ne(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 re(t){return c(this,0,void 0,function(){return f(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}function ie(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+17)}}function oe(t,e,n){var r=ie(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 ae(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 se=d.reduce(function(t,e,n){return t[e]=n,t},{}),ue=[["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[se[e],se[n]]}),le=ue.map(function(t){return t[1]}),he=ue.map(function(t){return t[0]});function ce(t,e,n){return t<e?e:t>n?n:t}function fe(t,e,n,r){return{y:ce(Math.round(t.y/e),0,n-1),x:ce(Math.round(t.x/e),0,r-1)}}function pe(t,e){return{x:t.x+e.x,y:t.y+e.y}}function de(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=pe(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,fe(c,o,l,h),a)),p=0;p<s;p++){var m=fe(f,o,l,h),y=ie(m.y,m.x,n,i);f=pe({x:m.x*o,y:m.y*o},{x:y.x,y:y.y})}var g=fe(f,o,l,h),v=r.get(g.y,g.x,n);return{y:f.y,x:f.x,name:d[n],score:v}}function me(t,e,n,r,i,o){var a=e.shape[2],s=le.length,u=new Array(a),l=t.part,h=t.score,c=oe(l,r,n);u[l.id]={score:h,name:d[l.id],y:c.y,x:c.x};for(var f=s-1;f>=0;--f){var p=le[f],m=he[f];u[p]&&!u[m]&&(u[m]=de(f,u[p],m,e,n,r,o))}for(f=0;f<s;++f)p=he[f],m=le[f],u[p]&&!u[m]&&(u[m]=de(f,u[p],m,e,n,r,i));return u}function ye(t,e,n){return n.reduce(function(n,r,i){var o=r.y,a=r.x,s=r.score;return ae(t,e,{y:o,x:a},i)||(n+=s),n},0)/n.length}function ge(t,e,n,r,i,o,a,s){return void 0===a&&(a=.5),void 0===s&&(s=20),c(this,0,void 0,function(){var u,l,h,c,p,d,m,y,g,v,b,w;return f(this,function(f){switch(f.label){case 0:return[4,re([t,e,n,r])];case 1:for(u=f.sent(),l=u[0],h=u[1],c=u[2],p=u[3],d=[],m=function(t,e,n){for(var r=n.shape,i=r[0],o=r[1],a=r[2],s=new ee(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||ne(h,c,u,l,1,n)&&s.enqueue({score:c,part:{heatmapY:u,heatmapX:l,id:h}})}return s}(a,0,l),y=s*s;d.length<o&&!m.empty();)g=m.dequeue(),v=oe(g.part,i,h),ae(d,y,v,g.part.id)||(b=me(g,l,h,i,c,p),w=ye(d,y,b),d.push({keypoints:b,score:w}));return[2,d]}})})}function ve(){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 be=function(){function t(t){this.variableNames=["A","B"],this.size=!0,this.workgroupSize=[32,1,1],this.outputShape=[t[0],1],this.dispatchLayout=r.webgpu_util.flatDispatchLayout(this.outputShape),this.dispatch=r.webgpu_util.computeDispatch(this.dispatchLayout,this.outputShape,this.workgroupSize),this.shaderKey="getpointsConfidenceOp"}return t.prototype.getUserCode=function(){return"\n ".concat(ve("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 we=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=r.webgpu_util.flatDispatchLayout(e),this.dispatch=r.webgpu_util.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(ve("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 xe(t){var n=t.shape,r=n[0],i=n[1],o=n[2];return e.tidy(function(){var n,a,s=e.reshape(t,[r*i,o]),u=e.argMax(s,0),l=e.expandDims(e.div(u,e.scalar(i,"int32")),1),h=e.expandDims((n=u,a=i,e.tidy(function(){var t=e.div(n,e.scalar(a,"int32"));return e.sub(n,e.mul(t,e.scalar(a,"int32")))})),1);return e.concat([l,h],1)})}function ke(t,n,r){return e.tidy(function(){var i=function(t,n){for(var r=[],i=0;i<d.length;i++){var o=Te(t.get(i,0).valueOf(),t.get(i,1).valueOf(),i,n),a=o.x,s=o.y;r.push(s),r.push(a)}return e.tensor2d(r,[d.length,2])}(t,r);return e.add(e.cast(e.mul(t.toTensor(),e.scalar(n,"int32")),"float32"),i)})}function Te(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+d.length)}}function Se(t,e,n){return c(this,0,void 0,function(){var r,i,o,a,s,u,l,h,c,p;return f(this,function(f){switch(f.label){case 0:return r=0,i=xe(t),[4,Promise.all([t.buffer(),e.buffer(),i.buffer()])];case 1:return o=f.sent(),a=o[0],s=o[1],u=o[2],[4,(l=ke(u,n,s)).buffer()];case 2:return h=f.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)),p=c.map(function(t,e){return r+=t,{y:h.get(e,0),x:h.get(e,1),score:t,name:d[e]}}),i.dispose(),l.dispose(),[2,{keypoints:p,score:r/p.length}]}})})}function Me(t,n,i){return c(this,0,void 0,function(){var o,a,s;return f(this,function(u){return o=xe(t),a=function(t,n,i){return e.tidy(function(){var o=function(t,n){if(e.backend()instanceof r.WebGPUBackend)return function(t,n){var r=e.backend(),i=new we(t.shape),o=r.runWebGPUProgram(i,[t,n],"float32");return e.engine().makeTensorFromTensorInfo(o)}(t,n);throw new Error("getOffsetVectorsGPU is not supported in this backend!")}(t,i);return e.add(e.cast(e.mul(t,e.scalar(n,"int32")),"float32"),o)})}(o,i,n),s=function(t,n){if(e.backend()instanceof r.WebGPUBackend)return function(t,n){var r=e.backend(),i=new be(n.shape),o=r.runWebGPUProgram(i,[t,n],"float32");return e.engine().makeTensorFromTensorInfo(o)}(t,n);throw new Error("getPointsConfidenceWebGPU is not supported in this backend!")}(t,o),[2,[a,s]]})})}function _e(t,e){return(t-1)%e==0}var Ee="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",Ae="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";function Fe(t,e){return function(t,e){return(t-1)%e==0}(t,e)?t:Math.floor(t/e)*e+1}var Pe=function(){function t(t,n){this.posenetModel=t;var r=this.posenetModel.inputs[0].shape;e.util.assert(-1===r[1]&&-1===r[2],function(){return"Input shape [".concat(r[1],", ").concat(r[2],"] ")+"must both be equal to or -1"});var i,o,a=(i=n.inputResolution,o=n.outputStride,{height:Fe(i.height,o),width:Fe(i.width,o)});!function(t){e.util.assert(Xt.indexOf(t)>=0,function(){return"outputStride of ".concat(t," is invalid. ")+"It must be either 8 or 16."})}(n.outputStride),function(t,n){e.util.assert(_e(t.height,n),function(){return"height of ".concat(t.height," is invalid for output stride ")+"".concat(n,".")}),e.util.assert(_e(t.width,n),function(){return"width of ".concat(t.width," is invalid for output stride ")+"".concat(n,".")})}(a,n.outputStride),this.inputResolution=a,this.outputStride=n.outputStride,this.architecture=n.architecture}return t.prototype.estimatePoses=function(t,e){return void 0===e&&(e=Jt),c(this,0,void 0,function(){return f(this,function(n){return[2,this.estimatePosesGPU(t,e,!1)]})})},t.prototype.estimatePosesGPU=function(t,n,r){return void 0===n&&(n=Jt),void 0===r&&(r=!1),c(this,0,void 0,function(){var i,o,a,s,u,l,c,p,d,m,y,g,v,b,w,x,k,T;return f(this,function(f){switch(f.label){case 0:return i=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({},Zt),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}(n),null==t?[2,r?[[],[]]:[]]:(this.maxPoses=i.maxPoses,o=U(t,{outputTensorSize:this.inputResolution,keepAspectRatio:!0,borderMode:"replicate"}),a=o.imageTensor,s=o.padding,u="ResNet50"===this.architecture?e.add(a,$t):D(a,[-1,1]),l=this.posenetModel.predict(u),"ResNet50"===this.architecture?(c=e.squeeze(l[2],[0]),p=e.squeeze(l[3],[0]),d=e.squeeze(l[0],[0]),m=e.squeeze(l[1],[0])):(c=e.squeeze(l[0],[0]),p=e.squeeze(l[1],[0]),d=e.squeeze(l[2],[0]),m=e.squeeze(l[3],[0])),y=e.sigmoid(p),1!==this.maxPoses?[3,5]:r?[4,Me(y,c,this.outputStride)]:[3,2]);case 1:return v=f.sent(),w=v[0],b=v[1],g=[w,b],[3,4];case 2:return[4,Se(y,c,this.outputStride)];case 3:w=f.sent(),g=[w],f.label=4;case 4:return[3,7];case 5:if(r)throw new Error("GPU renderer only supports single pose!");return[4,ge(y,c,d,m,this.outputStride,this.maxPoses,i.scoreThreshold,i.nmsRadius)];case 6:g=f.sent(),f.label=7;case 7:if(r){if(!0===i.flipHorizontal)throw new Error("flipHorizontal is not supported!");x=this.getCanvasInfo(P(t),this.inputResolution,s)}else T=P(t),k=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}(g,T,this.inputResolution,s),i.flipHorizontal&&(k=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}(k,T));return a.dispose(),u.dispose(),e.dispose(l),c.dispose(),p.dispose(),d.dispose(),m.dispose(),y.dispose(),[2,r?[g,x]:k]}})})},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 Oe(t){return void 0===t&&(t=Kt),c(this,0,void 0,function(){var e,r,i,o,a;return f(this,function(s){switch(s.label){case 0:return"ResNet50"!==(e=function(t){var e=t||Kt;if(null==e.architecture&&(e.architecture="MobileNetV1"),qt.indexOf(e.architecture)<0)throw new Error("Invalid architecture ".concat(e.architecture,". ")+"Should be one of ".concat(qt));if(null==e.inputResolution&&(e.inputResolution={height:257,width:257}),null==e.outputStride&&(e.outputStride=16),Yt[e.architecture].indexOf(e.outputStride)<0)throw new Error("Invalid outputStride ".concat(e.outputStride,". ")+"Should be one of ".concat(Yt[e.architecture]," ")+"for architecture ".concat(e.architecture,"."));if(null==e.multiplier&&(e.multiplier=1),Wt[e.architecture].indexOf(e.multiplier)<0)throw new Error("Invalid multiplier ".concat(e.multiplier,". ")+"Should be one of ".concat(Wt[e.architecture]," ")+"for architecture ".concat(e.architecture,"."));if(null==e.quantBytes&&(e.quantBytes=4),Qt.indexOf(e.quantBytes)<0)throw new Error("Invalid quantBytes ".concat(e.quantBytes,". ")+"Should be one of ".concat(Qt," ")+"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]:(u=e.outputStride,l=e.quantBytes,h="model-stride".concat(u,".json"),r=4===l?Ae+"float/"+h:Ae+"quant".concat(l,"/")+h,[4,n.loadGraphModel(e.modelUrl||r)]);case 1:return i=s.sent(),[2,new Pe(i,e)];case 2:return o=function(t,e,n){var r={1:"100",.75:"075",.5:"050"},i="model-stride".concat(t,".json");return 4===n?Ee+"float/".concat(r[e],"/")+i:Ee+"quant".concat(n,"/").concat(r[e],"/")+i}(e.outputStride,e.multiplier,e.quantBytes),[4,n.loadGraphModel(e.modelUrl||o)];case 3:return a=s.sent(),[2,new Pe(a,e)]}var u,l,h})})}var Re={keypointsToNormalizedKeypoints:et};exports.calculators=Re,exports.createDetector=function(t,e){return c(this,0,void 0,function(){var n,r;return f(this,function(i){switch(t){case exports.SupportedModels.PoseNet:return[2,Oe(e)];case exports.SupportedModels.BlazePose:if(r=void 0,null!=(n=e)){if("tfjs"===n.runtime)return[2,At(e)];if("mediapipe"===n.runtime)return[2,F(e)];r=n.runtime}throw new Error("Expect modelConfig.runtime to be either 'tfjs' "+"or 'mediapipe', but got ".concat(r));case exports.SupportedModels.MoveNet:return[2,Gt(e)];default:throw new Error("".concat(t," is not a supported model name."))}})})},exports.movenet={modelType:{SINGLEPOSE_LIGHTNING:"SinglePose.Lightning",SINGLEPOSE_THUNDER:"SinglePose.Thunder",MULTIPOSE_LIGHTNING:"MultiPose.Lightning"}},exports.util=Ct;
|
|
19
|
-
//# sourceMappingURL=pose-detection.esm-
|
|
19
|
+
//# sourceMappingURL=pose-detection.esm-DFB9u8DH.js.map
|