forked from hepengwei/visualization-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk-tensorflow_models.js
More file actions
1 lines (1 loc) · 108 KB
/
Copy pathchunk-tensorflow_models.js
File metadata and controls
1 lines (1 loc) · 108 KB
1
"use strict";(self.webpackChunkvisualization_collection=self.webpackChunkvisualization_collection||[]).push([[968],{42428:function(t,e,n){n.d(e,{N7:function(){return Yt},oV:function(){return Kt},wX:function(){return Gt}});var i=n(38986),r=n(38985),o=n(513),a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},a(t,e)};function s(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var u=function(){return u=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},u.apply(this,arguments)};function l(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{u(i.next(t))}catch(t){o(t)}}function s(t){try{u(i.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function h(t,e){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(t){return t instanceof SVGAnimatedLength?t.baseVal.value:t}function f(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(r){switch(r.label){case 0:return e=document.createElement("canvas"),t instanceof i.Tensor?[4,i.browser.toPixels(t,e)]:[3,2];case 1:return r.sent(),[3,3];case 2:e.width=c(t.width),e.height=c(t.height),n=e.getContext("2d"),t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0),r.label=3;case 3:return[2,e]}}))}))}function p(t){return l(this,void 0,void 0,(function(){var e,n,r,o,a,s;return h(this,(function(u){switch(u.label){case 0:return t instanceof i.Tensor?(e=t.shape.slice(0,2),n=e[0],r=e[1],o=ImageData.bind,[4,i.browser.toPixels(t)]):[3,2];case 1:return[2,new(o.apply(ImageData,[void 0,u.sent(),r,n]))];case 2:return a=document.createElement("canvas"),s=a.getContext("2d"),a.width=c(t.width),a.height=c(t.height),s.drawImage(t,0,0),[2,s.getImageData(0,0,a.width,a.height)]}}))}))}function d(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(r){switch(r.label){case 0:return t instanceof SVGImageElement||t instanceof OffscreenCanvas?[4,f(t)]:[3,2];case 1:return n=r.sent(),[3,3];case 2:n=t,r.label=3;case 3:return e=n,[2,i.browser.fromPixels(e,4)]}}))}))}function m(t){if(t<0||t>=256)throw new Error("Mask value must be in range [0, 255] but got "+t);if(!Number.isInteger(t))throw new Error("Mask value must be an integer but got "+t)}function g(t){var e=t.shape[2],n=(0,i.argMax)(t,2),r=(0,i.reshape)(n,[-1]);return(0,i.oneHot)(r,e)}function y(t,e){return(0,i.tidy)((function(){return(0,i.cast)((0,i.greater)(t,(0,i.scalar)(e)),"int32")}))}function v(t,e){var n=e.shape,r=n[0],o=n[1],a=n[2];return(0,i.tidy)((function(){var n=g(e),s=(0,i.expandDims)((0,i.range)(0,a,1,"int32"),1),u=(0,i.cast)((0,i.matMul)(n,s),"int32"),l=(0,i.reshape)(u,[r,o]),h=(0,i.add)(l,(0,i.scalar)(1,"int32"));return(0,i.sub)(function(t,e){return(0,i.mul)(t,e)}(h,t),(0,i.scalar)(1,"int32"))}))}var w=function(){function t(t,e){this.model=t,this.outputStride=e;var n=this.model.inputs[0].shape;i.util.assert(-1===n[1]&&-1===n[2],(function(){return"Input shape ["+n[1]+", "+n[2]+"] must both be equal to or -1"}))}return t.prototype.predict=function(t){var e=this;return(0,i.tidy)((function(){var n=e.preprocessInput((0,i.cast)(t,"float32")),r=(0,i.expandDims)(n,0),o=e.model.predict(r).map((function(t){return(0,i.squeeze)(t,[0])})),a=e.nameOutputResults(o);return{heatmapScores:(0,i.sigmoid)(a.heatmap),offsets:a.offsets,displacementFwd:a.displacementFwd,displacementBwd:a.displacementBwd,segmentation:a.segmentation,partHeatmaps:a.partHeatmaps,longOffsets:a.longOffsets,partOffsets:a.partOffsets}}))},t.prototype.dispose=function(){this.model.dispose()},t}(),x=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.preprocessInput=function(t){return(0,i.tidy)((function(){return(0,i.sub)((0,i.div)(t,127.5),1)}))},e.prototype.nameOutputResults=function(t){return{offsets:t[0],segmentation:t[1],partHeatmaps:t[2],longOffsets:t[3],heatmap:t[4],displacementFwd:t[5],displacementBwd:t[6],partOffsets:t[7]}},e}(w),b=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],k=b.length,S=b.reduce((function(t,e,n){return t[e]=n,t}),{});function M(t,e,n){var i=t[0],r=t[1],o=e[0],a=e[1],s=n.top,u=n.bottom;return[a/(n.left+n.right+r),o/(s+u+i)]}function T(t,e,n,i){return{y:i.get(t,e,n),x:i.get(t,e,n+k)}}function P(t,e,n){var i=T(t.heatmapY,t.heatmapX,t.id,n),r=i.y,o=i.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+r}}function _(t,e,n){return t<e?e:t>n?n:t}function F(t,e){return{x:t.x+e.x,y:t.y+e.y}}function O(t,e,n){void 0===n&&(n=.3);for(var i=0,r=0,o=0;o<t.length;o++)e.keypoints[o].score>n&&(r+=1,i+=Math.pow(t[o].x-e.keypoints[o].position.x,2)+Math.pow(t[o].y-e.keypoints[o].position.y,2));return 0===r?i=1/0:i/=r,i}function E(t,e,n,i,r,o,a){for(var s=a[0],u=a[1],l=n(t),h=l.y*i+l.x,c=r[k*(2*h)+e],f=r[k*(2*h+1)+e],p=t.y+c,d=t.x+f,m=0;m<o;m++){p=Math.min(p,s-1);var g=n({x:d=Math.min(d,u-1),y:p}),y=g.y*i+g.x;p+=c=r[k*(2*y)+e],d+=f=r[k*(2*y+1)+e]}return{x:d,y:p}}function z(t,e,n,i,r,o,a,s,u,l){for(var h=r[0],c=r[1],f=o[0],p=o[1],d=s[0],m=s[1],g=[],y=function(t){return function(t,e,n,i){var r=e[0],o=e[1],a=n[0],s=n[1],u=Math.round(((r+t.y+1)*s-1)/i);return{x:Math.round(((o+t.x+1)*a-1)/i),y:u}}(t,[h,c],[f,p],u)},v=0;v<i;v++){var w=E(t,v,y,a,e,l,[d,m]);g.push(w)}for(var x=-1,b=1/0,k=0;k<n.length;k++){var S=O(g,n[k]);S<b&&(x=k,b=S)}return x}function R(t,e){var n=t[0],i=t[1];return[Math.round((i-1)/e+1),Math.round((n-1)/e+1)]}function I(t,e,n,r,o,a,s,u,l,h,c){for(var f=s[0],p=s[1],d=t.shape,m=d[0],g=d[1],y=e.shape.slice(0,2),v=y[0],w=y[1],x=(0,i.reshape)(e,[v,w,2,k]),b=new Float32Array(c*k*3).fill(0),S=0;S<n.length;S++)for(var T=S*k*3,P=n[S],_=0;_<k;_++){var F=P.keypoints[_],O=T+3*_;b[O]=F.score,b[O+1]=F.position.y,b[O+2]=F.position.x}var E=M([r,o],[f,p],u),z=E[0],R=E[1],I=(0,i.tensor)(b,[c,k,3]),A=u.top,C=u.left,B={variableNames:["segmentation","longOffsets","poses"],outputShape:[m,g],userCode:"\n int convertToPositionInOutput(int pos, int pad, float scale, int stride) {\n return round(((float(pos + pad) + 1.0) * scale - 1.0) / float(stride));\n }\n\n float convertToPositionInOutputFloat(\n int pos, int pad, float scale, int stride) {\n return ((float(pos + pad) + 1.0) * scale - 1.0) / float(stride);\n }\n\n float dist(float x1, float y1, float x2, float y2) {\n return pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0);\n }\n\n float sampleLongOffsets(float h, float w, int d, int k) {\n float fh = fract(h);\n float fw = fract(w);\n int clH = int(ceil(h));\n int clW = int(ceil(w));\n int flH = int(floor(h));\n int flW = int(floor(w));\n float o11 = getLongOffsets(flH, flW, d, k);\n float o12 = getLongOffsets(flH, clW, d, k);\n float o21 = getLongOffsets(clH, flW, d, k);\n float o22 = getLongOffsets(clH, clW, d, k);\n float o1 = mix(o11, o12, fw);\n float o2 = mix(o21, o22, fw);\n return mix(o1, o2, fh);\n }\n\n int findNearestPose(int h, int w) {\n float prob = getSegmentation(h, w);\n if (prob < 1.0) {\n return -1;\n }\n\n // Done(Tyler): convert from output space h/w to strided space.\n float stridedH = convertToPositionInOutputFloat(\n h, "+A+", "+R+", "+a+");\n float stridedW = convertToPositionInOutputFloat(\n w, "+C+", "+z+", "+a+");\n\n float minDist = 1000000.0;\n int iMin = -1;\n for (int i = 0; i < "+c+"; i++) {\n float curDistSum = 0.0;\n int numKpt = 0;\n for (int k = 0; k < "+k+"; k++) {\n float dy = sampleLongOffsets(stridedH, stridedW, 0, k);\n float dx = sampleLongOffsets(stridedH, stridedW, 1, k);\n\n float y = float(h) + dy;\n float x = float(w) + dx;\n\n for (int s = 0; s < "+l+"; s++) {\n int yRounded = round(min(y, float("+(r-1)+")));\n int xRounded = round(min(x, float("+(o-1)+")));\n\n float yStrided = convertToPositionInOutputFloat(\n yRounded, "+A+", "+R+", "+a+");\n float xStrided = convertToPositionInOutputFloat(\n xRounded, "+C+", "+z+", "+a+");\n\n float dy = sampleLongOffsets(yStrided, xStrided, 0, k);\n float dx = sampleLongOffsets(yStrided, xStrided, 1, k);\n\n y = y + dy;\n x = x + dx;\n }\n\n float poseScore = getPoses(i, k, 0);\n float poseY = getPoses(i, k, 1);\n float poseX = getPoses(i, k, 2);\n if (poseScore > "+h+") {\n numKpt = numKpt + 1;\n curDistSum = curDistSum + dist(x, y, poseX, poseY);\n }\n }\n if (numKpt > 0 && curDistSum / float(numKpt) < minDist) {\n minDist = curDistSum / float(numKpt);\n iMin = i;\n }\n }\n return iMin;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int nearestPose = findNearestPose(coords[0], coords[1]);\n setOutput(float(nearestPose));\n }\n "};return(0,i.backend)().compileAndRun(B,[t,x,I])}function A(){return"webgl"===(0,i.getBackend)()}function C(t,e,n,r,o,a,s,u,c,f,p,d){var m=s[0],g=s[1];return void 0===c&&(c=.2),void 0===f&&(f=8),void 0===p&&(p=.3),void 0===d&&(d=10),l(this,void 0,void 0,(function(){var s,l,y,v,w;return h(this,(function(h){switch(h.label){case 0:return s=n.filter((function(t){return t.score>=c})),A()?(y=(0,i.tidy)((function(){var n=I(t,e,s,r,o,a,[m,g],u,f,p,d),l=(0,i.engine)().makeTensorFromDataId(n.dataId,n.shape,n.dtype);return s.map((function(t,e){return function(t,e){return(0,i.tidy)((function(){return(0,i.cast)((0,i.equal)(t,(0,i.scalar)(e)),"int32")}))}(l,e)}))})),[4,Promise.all(y.map((function(t){return t.data()})))]):[3,2];case 1:return l=h.sent(),y.forEach((function(t){return t.dispose()})),[3,5];case 2:return[4,t.data()];case 3:return v=h.sent(),[4,e.data()];case 4:w=h.sent(),l=function(t,e,n,i,r,o,a,s,u,l){var h=a[0],c=a[1];void 0===l&&(l=5);for(var f=n.map((function(t){return new Uint8Array(i*r).fill(0)})),p=s.top,d=s.left,m=M([i,r],[h,c],s),g=m[0],y=m[1],v=R([h,c],o)[0],w=0;w<i;w+=1)for(var x=0;x<r;x+=1){var b=w*r+x;if(1===t[b]){var k=z({x:x,y:w},e,n,l,[p,d],[g,y],v,[i,r],o,u);k>=0&&(f[k][b]=1)}}return f}(v,w,s,r,o,a,[m,g],u,f),h.label=5;case 5:return[2,l.map((function(t,e){return{data:t,pose:s[e],width:o,height:r}}))]}}))}))}function B(t,e,n,r,o,a,s,u,c,f,p,d,m){var g=u[0],y=u[1];return void 0===f&&(f=.2),void 0===p&&(p=8),void 0===d&&(d=.3),void 0===m&&(m=10),l(this,void 0,void 0,(function(){var u,l,v,w,x,b;return h(this,(function(h){switch(h.label){case 0:return u=r.filter((function(t){return t.score>=f})),A()?(v=(0,i.tidy)((function(){var r=I(t,e,u,o,a,s,[g,y],c,p,d,m),l=(0,i.engine)().makeTensorFromDataId(r.dataId,r.shape,r.dtype);return u.map((function(t,e){return function(t,e,n){return(0,i.tidy)((function(){return(0,i.sub)((0,i.mul)((0,i.cast)((0,i.equal)(t,(0,i.scalar)(n)),"int32"),(0,i.add)(e,1)),1)}))}(l,n,e)}))})),[4,Promise.all(v.map((function(t){return t.data()})))]):[3,2];case 1:return l=h.sent(),v.forEach((function(t){return t.dispose()})),[3,6];case 2:return[4,t.data()];case 3:return w=h.sent(),[4,e.data()];case 4:return x=h.sent(),[4,n.data()];case 5:b=h.sent(),l=function(t,e,n,i,r,o,a,s,u,l,h){var c=s[0],f=s[1];void 0===h&&(h=5);for(var p=i.map((function(t){return new Int32Array(r*o).fill(-1)})),d=u.top,m=u.left,g=M([r,o],[c,f],u),y=g[0],v=g[1],w=R([c,f],a)[0],x=0;x<r;x+=1)for(var b=0;b<o;b+=1){var k=x*o+b;if(1===t[k]){var S=z({x:b,y:x},e,i,h,[d,m],[y,v],w,[r,o],a,l);S>=0&&(p[S][k]=n[k])}}return p}(w,x,b,u,o,a,s,[g,y],c,p),h.label=6;case 6:return[2,l.map((function(t,e){return{pose:u[e],data:t,height:o,width:a}}))]}}))}))}function D(t){return Math.floor(t/2)}[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map((function(t){var e=t[0],n=t[1];return[S[e],S[n]]}));var L=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(D(t),t);)this.exchange(t,D(t)),t=D(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 V(t,e,n,i,r,o){for(var a=o.shape,s=a[0],u=a[1],l=!0,h=Math.max(n-r,0),c=Math.min(n+r+1,s),f=h;f<c;++f){for(var p=Math.max(i-r,0),d=Math.min(i+r+1,u),m=p;m<d;++m)if(o.get(f,m,t)>e){l=!1;break}if(!l)break}return l}var H=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]].map((function(t){var e=t[0],n=t[1];return[S[e],S[n]]})),q=H.map((function(t){return t[1]})),N=H.map((function(t){return t[0]}));function K(t,e,n,i){return{y:_(Math.round(t.y/e),0,n-1),x:_(Math.round(t.x/e),0,i-1)}}function j(t,e,n,i,r,o,a,s){void 0===s&&(s=2);for(var u=i.shape,l=u[0],h=u[1],c=function(t,e,n){var i=n.shape[2]/2;return{y:n.get(e.y,e.x,t),x:n.get(e.y,e.x,i+t)}}(t,K(e.position,o,l,h),a),f=F(e.position,c),p=0;p<s;p++){var d=K(f,o,l,h),m=T(d.y,d.x,n,r);f=F({x:d.x*o,y:d.y*o},{x:m.x,y:m.y})}var g=K(f,o,l,h),y=i.get(g.y,g.x,n);return{position:f,part:b[n],score:y}}function U(t,e,n,i,r,o){var a=e.shape[2],s=q.length,u=new Array(a),l=t.part,h=t.score,c=P(l,i,n);u[l.id]={score:h,part:b[l.id],position:c};for(var f=s-1;f>=0;--f){var p=q[f],d=N[f];u[p]&&!u[d]&&(u[d]=j(f,u[p],d,e,n,i,o))}for(f=0;f<s;++f)p=N[f],d=q[f],u[p]&&!u[d]&&(u[d]=j(f,u[p],d,e,n,i,r));return u}function W(t,e,n,i){var r=n.x,o=n.y;return t.some((function(t){var n,a,s,u,l=t.keypoints[i].position;return n=o,a=r,(s=l.y-n)*s+(u=l.x-a)*u<=e}))}function Y(t,e,n){var i=n.reduce((function(n,i,r){var o=i.position,a=i.score;return W(t,e,o,r)||(n+=a),n}),0);return i/n.length}function X(t,e,n,i,r,o,a,s){void 0===a&&(a=.5),void 0===s&&(s=20);for(var u=[],l=function(t,e,n){for(var i=n.shape,r=i[0],o=i[1],a=i[2],s=new L(r*o*a,(function(t){return t.score})),u=0;u<r;++u)for(var l=0;l<o;++l)for(var h=0;h<a;++h){var c=n.get(u,l,h);c<t||V(h,c,u,l,1,n)&&s.enqueue({score:c,part:{heatmapY:u,heatmapX:l,id:h}})}return s}(a,0,t),h=s*s;u.length<o&&!l.empty();){var c=l.dequeue();if(!W(u,h,P(c.part,r,e),c.part.id)){var f=U(c,t,e,r,n,i),p=Y(u,h,f);u.push({keypoints:f,score:p})}}return u}var Q,G=[-123.15,-115.9,-103.06],Z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.preprocessInput=function(t){return(0,i.add)(t,G)},e.prototype.nameOutputResults=function(t){var e=t[0],n=t[1],i=t[2],r=t[3],o=t[4],a=t[5];return{offsets:o,segmentation:t[6],partHeatmaps:a,longOffsets:r,heatmap:i,displacementFwd:n,displacementBwd:e,partOffsets:t[7]}},e}(w),$="https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/",J="https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/";function tt(t){if("undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas||"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement)return function(t){if("offsetHeight"in t&&0!==t.offsetHeight&&"offsetWidth"in t&&0!==t.offsetWidth)return[t.offsetHeight,t.offsetWidth];if(null!=t.height&&null!=t.width)return[t.height,t.width];throw new Error("HTMLImageElement must have height and width attributes set.")}(t);if("undefined"!=typeof ImageData&&t instanceof ImageData)return[t.height,t.width];if("undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement)return function(t){return t.hasAttribute("height")&&t.hasAttribute("width")?[t.height,t.width]:[t.videoHeight,t.videoWidth]}(t);if(t instanceof i.Tensor)return[t.shape[0],t.shape[1]];throw new Error("error: Unknown input type: "+t+".")}function et(t,e){return function(t,e){return(t-1)%e==0}(t,e)?t:Math.floor(t/e)*e+1}var nt={low:"low",medium:"medium",high:"high",full:"full"},it=((Q={})[nt.low]=.25,Q[nt.medium]=.5,Q[nt.high]=.75,Q[nt.full]=1,Q);function rt(t,e,n){var r=n[0],o=n[1],a=function(t){if("string"==typeof t){var e=it[t];return i.util.assert("number"==typeof e,(function(){return"string value of inputResolution must be one of "+Object.values(nt).join(",")+" but was "+t+"."})),e}return i.util.assert("number"==typeof t&&t<=2&&t>=.1,(function(){return"inputResolution must be a string or number between 0.1 and 2, but was "+t})),t}(t);return[et(r*a,e),et(o*a,e)]}function ot(t,e,n,r,o){var a=e[0],s=e[1],u=n[0],l=n[1],h=r[0],c=h[0],f=h[1],p=r[1],d=p[0],m=p[1];return void 0===o&&(o=!1),(0,i.tidy)((function(){var e=i.image.resizeBilinear(t,[u,l],!0);return o&&(e=(0,i.sigmoid)(e)),function(t,e,n){var r=e[0],o=e[1],a=n[0],s=a[0],u=a[1],l=n[1],h=l[0],c=l[1];return(0,i.tidy)((function(){var e=(0,i.expandDims)(t);return(0,i.squeeze)(i.image.cropAndResize(e,[[s/(r+s+u-1),h/(o+h+c-1),(s+r-1)/(r+s+u-1),(h+o-1)/(o+h+c-1)]],[0],[r,o]),[0])}))}(e,[a,s],[[c,f],[d,m]])}))}function at(t,e){var n=e[0],r=e[1],o=tt(t),a=o[0],s=o[1],u=r/n,l=[0,0,0,0],h=l[0],c=l[1],f=l[2],p=l[3];s/a<u?(h=0,c=0,f=Math.round(.5*(u*a-s)),p=Math.round(.5*(u*a-s))):(h=Math.round(.5*(1/u*s-a)),c=Math.round(.5*(1/u*s-a)),f=0,p=0);var d=(0,i.tidy)((function(){var e=function(t){return t instanceof i.Tensor?t:i.browser.fromPixels(t)}(t);return e=(0,i.pad3d)(e,[[h,c],[f,p],[0,0]]),i.image.resizeBilinear(e,[n,r])}));return{resized:d,padding:{top:h,left:f,right:p,bottom:c}}}function st(t){return l(this,void 0,void 0,(function(){return h(this,(function(e){return[2,Promise.all(t.map((function(t){return t.buffer()})))]}))}))}function ut(t,e,n,i,r){var o=e[0],a=e[1],s=n[0],u=n[1],l=function(t,e,n,i,r){return void 0===i&&(i=0),void 0===r&&(r=0),1===n&&1===e&&0===i&&0===r?t:t.map((function(t){return function(t,e,n,i,r){return void 0===i&&(i=0),void 0===r&&(r=0),{score:t.score,keypoints:t.keypoints.map((function(t){var o=t.score,a=t.part,s=t.position;return{score:o,part:a,position:{x:s.x*n+r,y:s.y*e+i}}}))}}(t,e,n,i,r)}))}(t,(o+i.top+i.bottom)/s,(a+i.left+i.right)/u,-i.top,-i.left);return r?function(t,e){return e<=0?t:t.map((function(t){return function(t,e){return{score:t.score,keypoints:t.keypoints.map((function(t){var n=t.score,i=t.part,r=t.position;return{score:n,part:i,position:{x:e-1-r.x,y:r.y}}}))}}(t,e)}))}(l,a):l}var lt={architecture:"MobileNetV1",outputStride:16,quantBytes:4,multiplier:.75},ht=["MobileNetV1","ResNet50"],ct={MobileNetV1:[8,16,32],ResNet50:[32,16]},ft={MobileNetV1:[.5,.75,1],ResNet50:[1]},pt=[1,2,4],dt={flipHorizontal:!1,internalResolution:"medium",segmentationThreshold:.7,maxDetections:10,scoreThreshold:.4,nmsRadius:20},mt={flipHorizontal:!1,internalResolution:"medium",segmentationThreshold:.7,maxDetections:10,scoreThreshold:.4,nmsRadius:20,minKeypointScore:.3,refineSteps:10};function gt(t){var e=t.segmentationThreshold,n=t.maxDetections,i=t.scoreThreshold,r=t.nmsRadius;if(e<0||e>1)throw new Error("segmentationThreshold "+e+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid maxDetections "+n+". Should be > 0");if(i<0||i>1)throw new Error("Invalid scoreThreshold "+i+". Should be in range [0.0, 1.0]");if(r<=0)throw new Error("Invalid nmsRadius "+r+".")}function yt(t){var e=t.segmentationThreshold,n=t.maxDetections,i=t.scoreThreshold,r=t.nmsRadius,o=t.minKeypointScore,a=t.refineSteps;if(e<0||e>1)throw new Error("segmentationThreshold "+e+". Should be in range [0.0, 1.0]");if(n<=0)throw new Error("Invalid maxDetections "+n+". Should be > 0");if(i<0||i>1)throw new Error("Invalid scoreThreshold "+i+". Should be in range [0.0, 1.0]");if(r<=0)throw new Error("Invalid nmsRadius "+r+".");if(o<0||o>1)throw new Error("Invalid minKeypointScore "+o+".Should be in range [0.0, 1.0]");if(a<=0||a>20)throw new Error("Invalid refineSteps "+a+".Should be in range [1, 20]")}var vt=function(){function t(t){this.baseModel=t}return t.prototype.predictForPersonSegmentation=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd}},t.prototype.predictForPersonSegmentationAndPart=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,partHeatmapLogits:e.partHeatmaps,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd}},t.prototype.predictForMultiPersonInstanceSegmentationAndPart=function(t){var e=this.baseModel.predict(t);return{segmentLogits:e.segmentation,longOffsets:e.longOffsets,heatmapScores:e.heatmapScores,offsets:e.offsets,displacementFwd:e.displacementFwd,displacementBwd:e.displacementBwd,partHeatmaps:e.partHeatmaps}},t.prototype.segmentPersonActivation=function(t,e,n){var r=this;void 0===n&&(n=.5);var o=tt(t),a=o[0],s=o[1],u=rt(e,this.baseModel.outputStride,[a,s]),l=at(t,u),h=l.resized,c=l.padding,f=(0,i.tidy)((function(){var t=r.predictForPersonSegmentation(h),e=t.segmentLogits,o=t.heatmapScores,u=t.offsets,l=t.displacementFwd,f=t.displacementBwd,p=h.shape,d=p[0],m=p[1],g=ot(e,[a,s],[d,m],[[c.top,c.bottom],[c.left,c.right]],!0);return{segmentation:y((0,i.squeeze)(g),n),heatmapScores:o,offsets:u,displacementFwd:l,displacementBwd:f}})),p=f.segmentation,d=f.heatmapScores,m=f.offsets,g=f.displacementFwd,v=f.displacementBwd;return h.dispose(),{segmentation:p,heatmapScores:d,offsets:m,displacementFwd:g,displacementBwd:v,padding:c,internalResolutionHeightAndWidth:u}},t.prototype.segmentPerson=function(t,e){return void 0===e&&(e=dt),l(this,void 0,void 0,(function(){var n,i,r,o,a,s,l,c,f,p,d,m,g,y,v,w,x,b;return h(this,(function(h){switch(h.label){case 0:return gt(e=u(u({},dt),e)),n=this.segmentPersonActivation(t,e.internalResolution,e.segmentationThreshold),i=n.segmentation,r=n.heatmapScores,o=n.offsets,a=n.displacementFwd,s=n.displacementBwd,l=n.padding,c=n.internalResolutionHeightAndWidth,f=i.shape,p=f[0],d=f[1],[4,i.data()];case 1:return m=h.sent(),i.dispose(),[4,st([r,o,a,s])];case 2:return g=h.sent(),y=g[0],v=g[1],w=g[2],x=g[3],b=ut(b=X(y,v,w,x,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[p,d],c,l,!1),r.dispose(),o.dispose(),a.dispose(),s.dispose(),[2,{height:p,width:d,data:m,allPoses:b}]}}))}))},t.prototype.segmentMultiPerson=function(t,e){return void 0===e&&(e=mt),l(this,void 0,void 0,(function(){var n,r,o,a,s,l,c,f,p,d,m,g,v,w,x,b,k,S,M,T,P,_=this;return h(this,(function(h){switch(h.label){case 0:return yt(e=u(u({},mt),e)),n=tt(t),r=n[0],o=n[1],a=rt(e.internalResolution,this.baseModel.outputStride,[r,o]),s=at(t,a),l=s.resized,c=s.padding,f=(0,i.tidy)((function(){var t,n=_.predictForMultiPersonInstanceSegmentationAndPart(l),s=n.segmentLogits,u=n.longOffsets,h=n.heatmapScores,f=n.offsets,p=n.displacementFwd,d=n.displacementBwd,m=ot(s,[r,o],a,[[c.top,c.bottom],[c.left,c.right]],!0);return t=u,{segmentation:y((0,i.squeeze)(m),e.segmentationThreshold),longOffsets:t,heatmapScoresRaw:h,offsetsRaw:f,displacementFwdRaw:p,displacementBwdRaw:d}})),p=f.segmentation,d=f.longOffsets,m=f.heatmapScoresRaw,g=f.offsetsRaw,v=f.displacementFwdRaw,w=f.displacementBwdRaw,[4,st([m,g,v,w])];case 1:return x=h.sent(),b=x[0],k=x[1],S=x[2],M=x[3],T=ut(T=X(b,k,S,M,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[r,o],a,c,!1),[4,C(p,d,T,r,o,this.baseModel.outputStride,a,c,e.scoreThreshold,e.refineSteps,e.minKeypointScore,e.maxDetections)];case 2:return P=h.sent(),l.dispose(),p.dispose(),d.dispose(),m.dispose(),g.dispose(),v.dispose(),w.dispose(),[2,P]}}))}))},t.prototype.segmentPersonPartsActivation=function(t,e,n){var r=this;void 0===n&&(n=.5);var o=tt(t),a=o[0],s=o[1],u=rt(e,this.baseModel.outputStride,[a,s]),l=at(t,u),h=l.resized,c=l.padding,f=(0,i.tidy)((function(){var t=r.predictForPersonSegmentationAndPart(h),e=t.segmentLogits,o=t.partHeatmapLogits,u=t.heatmapScores,l=t.offsets,f=t.displacementFwd,p=t.displacementBwd,d=h.shape,m=d[0],g=d[1],w=ot(e,[a,s],[m,g],[[c.top,c.bottom],[c.left,c.right]],!0),x=ot(o,[a,s],[m,g],[[c.top,c.bottom],[c.left,c.right]],!0);return{partSegmentation:v(y((0,i.squeeze)(w),n),x),heatmapScores:u,offsets:l,displacementFwd:f,displacementBwd:p}})),p=f.partSegmentation,d=f.heatmapScores,m=f.offsets,g=f.displacementFwd,w=f.displacementBwd;return h.dispose(),{partSegmentation:p,heatmapScores:d,offsets:m,displacementFwd:g,displacementBwd:w,padding:c,internalResolutionHeightAndWidth:u}},t.prototype.segmentPersonParts=function(t,e){return void 0===e&&(e=dt),l(this,void 0,void 0,(function(){var n,i,r,o,a,s,l,c,f,p,d,m,g,y,v,w,x,b;return h(this,(function(h){switch(h.label){case 0:return gt(e=u(u({},dt),e)),n=this.segmentPersonPartsActivation(t,e.internalResolution,e.segmentationThreshold),i=n.partSegmentation,r=n.heatmapScores,o=n.offsets,a=n.displacementFwd,s=n.displacementBwd,l=n.padding,c=n.internalResolutionHeightAndWidth,f=i.shape,p=f[0],d=f[1],[4,i.data()];case 1:return m=h.sent(),i.dispose(),[4,st([r,o,a,s])];case 2:return g=h.sent(),y=g[0],v=g[1],w=g[2],x=g[3],b=ut(b=X(y,v,w,x,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[p,d],c,l,!1),r.dispose(),o.dispose(),a.dispose(),s.dispose(),[2,{height:p,width:d,data:m,allPoses:b}]}}))}))},t.prototype.segmentMultiPersonParts=function(t,e){return void 0===e&&(e=mt),l(this,void 0,void 0,(function(){var n,r,o,a,s,l,c,f,p,d,m,v,w,x,b,k,S,M,T,P,_,F,O=this;return h(this,(function(h){switch(h.label){case 0:return yt(e=u(u({},mt),e)),n=tt(t),r=n[0],o=n[1],a=rt(e.internalResolution,this.baseModel.outputStride,[r,o]),s=at(t,a),l=s.resized,c=s.padding,f=(0,i.tidy)((function(){var t=O.predictForMultiPersonInstanceSegmentationAndPart(l),n=t.segmentLogits,s=t.longOffsets,u=t.heatmapScores,h=t.offsets,f=t.displacementFwd,p=t.displacementBwd,d=t.partHeatmaps,m=ot(n,[r,o],a,[[c.top,c.bottom],[c.left,c.right]],!0),v=ot(d,[r,o],a,[[c.top,c.bottom],[c.left,c.right]],!0),w=s,x=y((0,i.squeeze)(m),e.segmentationThreshold),b=function(t){var e=t.shape,n=e[0],r=e[1],o=e[2];return(0,i.tidy)((function(){var e=g(t),a=(0,i.expandDims)((0,i.range)(0,o,1,"int32"),1),s=(0,i.cast)((0,i.matMul)(e,a),"int32");return(0,i.reshape)(s,[n,r])}))}(v);return{segmentation:x,longOffsets:w,heatmapScoresRaw:u,offsetsRaw:h,displacementFwdRaw:f,displacementBwdRaw:p,partSegmentation:b}})),p=f.segmentation,d=f.longOffsets,m=f.heatmapScoresRaw,v=f.offsetsRaw,w=f.displacementFwdRaw,x=f.displacementBwdRaw,b=f.partSegmentation,[4,st([m,v,w,x])];case 1:return k=h.sent(),S=k[0],M=k[1],T=k[2],P=k[3],_=ut(_=X(S,M,T,P,this.baseModel.outputStride,e.maxDetections,e.scoreThreshold,e.nmsRadius),[r,o],a,c,!1),[4,B(p,d,b,_,r,o,this.baseModel.outputStride,a,c,e.scoreThreshold,e.refineSteps,e.minKeypointScore,e.maxDetections)];case 2:return F=h.sent(),l.dispose(),p.dispose(),d.dispose(),m.dispose(),v.dispose(),w.dispose(),x.dispose(),b.dispose(),[2,F]}}))}))},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function wt(t){return l(this,void 0,void 0,(function(){var e,n,o,a,s,u;return h(this,(function(l){switch(l.label){case 0:if(e=t.outputStride,n=t.quantBytes,o=t.multiplier,null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return a=function(t,e,n){var i={1:"100",.75:"075",.5:"050"},r="model-stride"+t+".json";return 4===n?J+"float/"+i[e]+"/"+r:J+"quant"+n+"/"+i[e]+"/"+r}(e,o,n),[4,(0,r.YL)(t.modelUrl||a)];case 1:return s=l.sent(),u=new x(s,e),[2,new vt(u)]}}))}))}function xt(t){return l(this,void 0,void 0,(function(){var e,n,o,a,s;return h(this,(function(u){switch(u.label){case 0:if(e=t.outputStride,n=t.quantBytes,null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return o=function(t,e){var n="model-stride"+t+".json";return 4===e?$+"float/"+n:$+"quant"+e+"/"+n}(e,n),[4,(0,r.YL)(t.modelUrl||o)];case 1:return a=u.sent(),s=new Z(a,e),[2,new vt(s)]}}))}))}function bt(t){return void 0===t&&(t=lt),l(this,void 0,void 0,(function(){return h(this,(function(e){return"ResNet50"===(t=function(t){if(null==(t=t||lt).architecture&&(t.architecture="MobileNetV1"),ht.indexOf(t.architecture)<0)throw new Error("Invalid architecture "+t.architecture+". Should be one of "+ht);if(null==t.outputStride&&(t.outputStride=16),ct[t.architecture].indexOf(t.outputStride)<0)throw new Error("Invalid outputStride "+t.outputStride+". Should be one of "+ct[t.architecture]+" for architecture "+t.architecture+".");if(null==t.multiplier&&(t.multiplier=1),ft[t.architecture].indexOf(t.multiplier)<0)throw new Error("Invalid multiplier "+t.multiplier+". Should be one of "+ft[t.architecture]+" for architecture "+t.architecture+".");if(null==t.quantBytes&&(t.quantBytes=4),pt.indexOf(t.quantBytes)<0)throw new Error("Invalid quantBytes "+t.quantBytes+". Should be one of "+pt+" for architecture "+t.architecture+".");return t}(t)).architecture?[2,xt(t)]:"MobileNetV1"===t.architecture?[2,wt(t)]:[2,null]}))}))}var kt=["left_face","right_face","left_upper_arm_front","left_upper_arm_back","right_upper_arm_front","right_upper_arm_back","left_lower_arm_front","left_lower_arm_back","right_lower_arm_front","right_lower_arm_back","left_hand","right_hand","torso_front","torso_back","left_upper_leg_front","left_upper_leg_back","right_upper_leg_front","right_upper_leg_back","left_lower_leg_front","left_lower_leg_back","right_lower_leg_front","right_lower_leg_back","left_feet","right_feet"],St=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,f(this.mask)]}))}))},t.prototype.toImageData=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.mask]}))}))},t.prototype.toTensor=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,d(this.mask)]}))}))},t.prototype.getUnderlyingType=function(){return"imagedata"},t}();function Mt(t){if(m(t),255!==t)throw new Error("Foreground id must be 255 but got "+t);return"person"}function Tt(t){if(m(t),t>=kt.length)throw new Error("Invalid body part value "+t);return kt[t]}var Pt=function(){function t(t){this.bodyPixModel=t}return t.prototype.segmentPeople=function(t,e){return l(this,void 0,void 0,(function(){var n,i,r,o;return h(this,(function(a){switch(a.label){case 0:return t instanceof ImageBitmap&&((n=document.createElement("canvas")).getContext("2d").drawImage(t,0,0),t=n),e.segmentBodyParts?e.multiSegmentation?[4,this.bodyPixModel.segmentMultiPersonParts(t,e)]:[3,2]:[3,5];case 1:return r=a.sent(),[3,4];case 2:return[4,this.bodyPixModel.segmentPersonParts(t,e)];case 3:r=[a.sent()],a.label=4;case 4:return i=r.map((function(t){var e=t.data,n=t.width,i=t.height,r=new Uint8ClampedArray(n*i*4).fill(0);return e.forEach((function(t,e){-1===t?(r[4*e]=kt.length,r[4*e+3]=0):(r[4*e]=t,r[4*e+3]=255)})),{maskValueToLabel:Tt,mask:new St(new ImageData(r,n,i))}})),[3,10];case 5:return e.multiSegmentation?[4,this.bodyPixModel.segmentMultiPerson(t,e)]:[3,7];case 6:return o=a.sent(),[3,9];case 7:return[4,this.bodyPixModel.segmentPerson(t,e)];case 8:o=[a.sent()],a.label=9;case 9:i=o.map((function(t){var e=t.data,n=t.width,i=t.height,r=new Uint8ClampedArray(n*i*4).fill(0);return e.forEach((function(t,e){0===t?(r[4*e]=0,r[4*e+3]=0):(r[4*e]=255,r[4*e+3]=255)})),{maskValueToLabel:Mt,mask:new St(new ImageData(r,n,i))}})),a.label=10;case 10:return[2,i]}}))}))},t.prototype.dispose=function(){this.bodyPixModel.dispose()},t.prototype.reset=function(){},t}();function _t(t){return l(this,void 0,void 0,(function(){return h(this,(function(e){return[2,bt(t).then((function(t){return new Pt(t)}))]}))}))}var Ft={runtime:"mediapipe",modelType:"general"},Ot=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.mask]}))}))},t.prototype.toImageData=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,p(this.mask)]}))}))},t.prototype.toTensor=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,d(this.mask)]}))}))},t.prototype.getUnderlyingType=function(){return"canvasimagesource"},t}();function Et(t){return m(t),"person"}var zt=function(){function t(t){var e,n=this;this.selfieMode=!1,this.selfieSegmentationSolution=new o.SelfieSegmentation({locateFile:function(e,n){return t.solutionPath?t.solutionPath.replace(/\/+$/,"")+"/"+e:n+"/"+e}}),e="landscape"===t.modelType?1:0,this.selfieSegmentationSolution.setOptions({modelSelection:e,selfieMode:this.selfieMode}),this.selfieSegmentationSolution.onResults((function(t){n.segmentation=[{maskValueToLabel:Et,mask:new Ot(t.segmentationMask)}]}))}return t.prototype.segmentPeople=function(t,e){return l(this,void 0,void 0,(function(){var n,r;return h(this,(function(o){switch(o.label){case 0:return e&&e.flipHorizontal&&e.flipHorizontal!==this.selfieMode&&(this.selfieMode=e.flipHorizontal,this.selfieSegmentationSolution.setOptions({selfieMode:this.selfieMode})),t instanceof i.Tensor?(r=ImageData.bind,[4,i.browser.toPixels(t)]):[3,2];case 1:return n=new(r.apply(ImageData,[void 0,o.sent(),t.shape[1],t.shape[0]])),[3,3];case 2:n=t,o.label=3;case 3:return t=n,[4,this.selfieSegmentationSolution.send({image:t})];case 4:return o.sent(),[2,this.segmentation]}}))}))},t.prototype.dispose=function(){this.selfieSegmentationSolution.close()},t.prototype.reset=function(){this.selfieSegmentationSolution.reset(),this.segmentation=null,this.selfieMode=!1},t.prototype.initialize=function(){return this.selfieSegmentationSolution.initialize()},t}();function Rt(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(i){switch(i.label){case 0:return e=function(t){if(null==t)return u({},Ft);var e=u({},t);return e.runtime="mediapipe",null==e.modelType&&(e.modelType=Ft.modelType),e}(t),[4,(n=new zt(e)).initialize()];case 1:return i.sent(),[2,n]}}))}))}function It(t){return t instanceof i.Tensor?{height:t.shape[0],width:t.shape[1]}:{height:t.height,width:t.width}}function At(t,e){i.util.assert(0!==t.width,(function(){return e+" width cannot be 0."})),i.util.assert(0!==t.height,(function(){return e+" height cannot be 0."}))}function Ct(t,e,n){var r=e.outputTensorSize,o=e.keepAspectRatio,a=e.borderMode,s=e.outputTensorFloatRange,u=It(t),l=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}}(u,n),h=function(t,e,n){if(void 0===n&&(n=!1),!n)return{top:0,left:0,right:0,bottom:0};var i=e.height,r=e.width;At(e,"targetSize"),At(t,"roi");var o,a,s=i/r,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}}(l,r,o),c=function(t,e,n,i){var r=t.width,o=t.height,a=i?-1:1,s=Math.cos(t.rotation),u=Math.sin(t.rotation),l=t.xCenter,h=t.yCenter,c=1/e,f=1/n,p=new Array(16);return p[0]=r*s*a*c,p[1]=-o*u*c,p[2]=0,p[3]=(-.5*r*s*a+.5*o*u+l)*c,p[4]=r*u*a*f,p[5]=o*s*f,p[6]=0,p[7]=(-.5*o*s-.5*r*u*a+h)*f,p[8]=0,p[9]=0,p[10]=r*c,p[11]=0,p[12]=0,p[13]=0,p[14]=0,p[15]=1,function(t){if(16!==t.length)throw new Error("Array length must be 16 but got "+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]]]}(p)}(l,u.width,u.height,!1),f=(0,i.tidy)((function(){var e,n=(e=t)instanceof i.Tensor?e:i.browser.fromPixels(e),o=(0,i.tensor2d)(function(t,e,n){return At(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]}(c,u,r),[1,8]),l="zero"===a?"constant":"nearest",h=i.image.transform((0,i.expandDims)((0,i.cast)(n,"float32")),o,"bilinear",l,0,[r.height,r.width]);return null!=s?function(t,e){var n=function(t,e,n,i){var r=(i-n)/255;return{scale:r,offset:n-0*r}}(0,0,e[0],e[1]);return(0,i.tidy)((function(){return(0,i.add)((0,i.mul)(t,n.scale),n.offset)}))}(h,s):h}));return{imageTensor:f,padding:h,transformationMatrix:c}}var Bt={runtime:"tfjs",modelType:"general",modelUrl:"https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1"},Dt={flipHorizontal:!1},Lt={outputTensorSize:{width:256,height:256},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},Vt={outputTensorSize:{width:256,height:144},keepAspectRatio:!1,borderMode:"zero",outputTensorFloatRange:[0,1]},Ht={activation:"none"},qt=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,f(this.mask)]}))}))},t.prototype.toImageData=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,p(this.mask)]}))}))},t.prototype.toTensor=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.mask]}))}))},t.prototype.getUnderlyingType=function(){return"tensor"},t}();function Nt(t){return m(t),"person"}var Kt,jt,Ut=function(){function t(t,e){this.modelType=t,this.model=e}return t.prototype.segmentPeople=function(t,e){return l(this,void 0,void 0,(function(){var n,r=this;return h(this,(function(o){return e=function(t){if(null==t)return u({},Dt);var e=u({},t);return null==e.flipHorizontal&&(e.flipHorizontal=Dt.flipHorizontal),e}(e),null==t?(this.reset(),[2,[]]):(n=(0,i.tidy)((function(){var e=Ct(t,"general"===r.modelType?Lt:Vt).imageTensor,n=(0,i.slice)(r.model.predict(e),[0,0,0,1],-1),o=It(t),a=function(t,e,n){return(0,i.tidy)((function(){var r=(0,i.squeeze)(t,[0]),o=r.shape[2];if(1===o){var a=r;switch(e.activation){case"none":break;case"sigmoid":a=(0,i.sigmoid)(a);break;case"softmax":throw new Error("Softmax activation requires two channels.");default:throw new Error("Activation not supported ("+e.activation+")")}var s=n?i.image.resizeBilinear(a,[n.height,n.width]):a;return(0,i.squeeze)(s,[2])}throw new Error("Unsupported number of tensor channels "+o)}))}(n,Ht,o),s=(0,i.expandDims)(a,2),u=(0,i.pad)(s,[[0,0],[0,0],[0,1]]);return(0,i.mirrorPad)(u,[[0,0],[0,0],[0,2]],"symmetric")})),[2,[{maskValueToLabel:Nt,mask:new qt(n)}]])}))}))},t.prototype.dispose=function(){this.model.dispose()},t.prototype.reset=function(){},t}();function Wt(t){return l(this,void 0,void 0,(function(){var e,n,i;return h(this,(function(o){switch(o.label){case 0:return e=function(t){if(null==t)return u({},Bt);var e=u({},t);if(e.runtime="tfjs",null==e.modelType&&(e.modelType=Bt.modelType),"general"!==e.modelType&&"landscape"!==e.modelType)throw new Error("Model type must be one of general or landscape, but got "+e.modelType);return null==e.modelUrl&&("general"===e.modelType?e.modelUrl="https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/general/1":e.modelUrl="https://tfhub.dev/mediapipe/tfjs-model/selfie_segmentation/landscape/1"),e}(t),n="string"==typeof e.modelUrl&&e.modelUrl.indexOf("https://tfhub.dev")>-1,[4,(0,r.YL)(e.modelUrl,{fromTFHub:n})];case 1:return i=o.sent(),[2,new Ut(e.modelType,i)]}}))}))}function Yt(t,e){return l(this,void 0,void 0,(function(){var n,i;return h(this,(function(r){switch(t){case Kt.MediaPipeSelfieSegmentation:if(n=void 0,null!=(i=e)){if("tfjs"===i.runtime)return[2,Wt(i)];if("mediapipe"===i.runtime)return[2,Rt(i)];n=i.runtime}throw new Error("Expect modelConfig.runtime to be either 'tfjs' or 'mediapipe', but got "+n);case Kt.BodyPix:return[2,_t(i=e)];default:throw new Error(t+" is not a supported model name.")}}))}))}(jt=Kt||(Kt={})).BodyPix="BodyPix",jt.MediaPipeSelfieSegmentation="MediaPipeSelfieSegmentation";function Xt(t,e,n,i,r,o){void 0===o&&(o={r:0,g:255,b:255,a:255});for(var a=-r;a<=r;a++)for(var s=-r;s<=r;s++)if(0!==a&&0!==s){var u=(e+a)*i+(n+s);t[4*u+0]=o.r,t[4*u+1]=o.g,t[4*u+2]=o.b,t[4*u+3]=o.a}}function Qt(t,e,n,i,r,o,a){void 0===a&&(a=1);for(var s=0,u=-a;u<=a;u++)for(var l=-a;l<=a;l++)if(0!==u&&0!==l){var h=(e+u)*i+(n+l);(!r[t[4*h]]||t[4*h+3]<o)&&(s+=1)}return s>0}function Gt(t,e,n,i,r,o){return void 0===e&&(e={r:0,g:0,b:0,a:0}),void 0===n&&(n={r:0,g:0,b:0,a:255}),void 0===i&&(i=!1),void 0===r&&(r=.5),void 0===o&&(o=Array.from(Array(256).keys())),l(this,void 0,void 0,(function(){var a,s,u,l,c,f,p,d,m,g,y,v,w,x;return h(this,(function(h){switch(h.label){case 0:return 0===(a=Array.isArray(t)?t:[t]).length?[2,null]:[4,Promise.all(a.map((function(t){return t.mask.toImageData()})))];case 1:for(s=h.sent(),u=s[0],l=u.width,c=u.height,f=new Uint8ClampedArray(l*c*4),p=Math.round(255*r),d=new Array(256).fill(!1),o.forEach((function(t){return d[t]=!0})),m=0;m<c;m++)for(g=0;g<l;g++)for(f[4*(y=m*l+g)+0]=n.r,f[4*y+1]=n.g,f[4*y+2]=n.b,f[4*y+3]=n.a,v=0,w=s;v<w.length;v++)x=w[v],d[x.data[4*y]]&&x.data[4*y+3]>=p&&(f[4*y]=e.r,f[4*y+1]=e.g,f[4*y+2]=e.b,f[4*y+3]=e.a,i&&m-1>=0&&m+1<c&&g-1>=0&&g+1<l&&Qt(x.data,m,g,l,d,p)&&Xt(f,m,g,l,1));return[2,new ImageData(f,l,c)]}}))}))}},96064:function(t,e,n){n.d(e,{D5:function(){return At},cH:function(){return _e},oV:function(){return Ft}});var i=n(20264),r=n(38986),o=n(38985),a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function s(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var u=function(){return(u=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function l(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{u(i.next(t))}catch(t){o(t)}}function s(t){try{u(i.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((i=i.apply(t,e||[])).next())}))}function h(t,e){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,i=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){a.label=o[1];break}if(6===o[0]&&a.label<r[1]){a.label=r[1],r=o;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(o);break}r[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var i=Array(t),r=0;for(e=0;e<n;e++)for(var o=arguments[e],a=0,s=o.length;a<s;a++,r++)i[r]=o[a];return i}var f=["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"],p=["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"],d={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]},m={left:[1,3,5,7,9,11,13,15],right:[2,4,6,8,10,12,14,16],middle:[0]},g=[[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]],y=[[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 v(t){return t instanceof SVGAnimatedLength?t.baseVal.value:t}function w(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(i){switch(i.label){case 0:return e=document.createElement("canvas"),t instanceof r.Tensor?[4,r.browser.toPixels(t,e)]:[3,2];case 1:return i.sent(),[3,3];case 2:e.width=v(t.width),e.height=v(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 x(t){return l(this,void 0,void 0,(function(){var e,n,i,o,a,s;return h(this,(function(u){switch(u.label){case 0:return t instanceof r.Tensor?(e=t.shape.slice(0,2),n=e[0],i=e[1],o=ImageData.bind,[4,r.browser.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=v(t.width),a.height=v(t.height),s.drawImage(t,0,0),[2,s.getImageData(0,0,a.width,a.height)]}}))}))}function b(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(i){switch(i.label){case 0:return t instanceof SVGImageElement||t instanceof OffscreenCanvas?[4,w(t)]:[3,2];case 1:return n=i.sent(),[3,3];case 2:n=t,i.label=3;case 3:return e=n,[2,r.browser.fromPixels(e,4)]}}))}))}function k(t){if(t<0||t>=256)throw new Error("Mask value must be in range [0, 255] but got "+t);if(!Number.isInteger(t))throw new Error("Mask value must be an integer but got "+t)}var S={runtime:"mediapipe",enableSmoothing:!0,enableSegmentation:!1,smoothSegmentation:!0,modelType:"full"},M=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.mask]}))}))},t.prototype.toImageData=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,x(this.mask)]}))}))},t.prototype.toTensor=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,b(this.mask)]}))}))},t.prototype.getUnderlyingType=function(){return"canvasimagesource"},t}();function T(t){return k(t),"person"}var P=function(){function t(t){var e,n=this;switch(this.width=0,this.height=0,this.selfieMode=!1,this.poseSolution=new i.Pose({locateFile:function(e,n){return t.solutionPath?t.solutionPath.replace(/\/+$/,"")+"/"+e:n+"/"+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:T,mask:new M(t.segmentationMask)}),n.poses=[e]}}))}return t.prototype.translateOutput=function(t,e){var n=this,i={keypoints:t.map((function(t,e){return{x:t.x*n.width,y:t.y*n.height,z:t.z,score:t.visibility,name:p[e]}}))};return null!=e&&(i.keypoints3D=e.map((function(t,e){return{x:t.x,y:t.y,z:t.z,score:t.visibility,name:p[e]}}))),i},t.prototype.estimatePoses=function(t,e,n){return l(this,void 0,void 0,(function(){var i,o;return h(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.Tensor?(o=ImageData.bind,[4,r.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},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 _(t){return l(this,void 0,void 0,(function(){var e,n;return h(this,(function(i){switch(i.label){case 0:return e=function(t){if(null==t)return u({},S);var e=u({},t);return e.runtime="mediapipe",null==e.enableSegmentation&&(e.enableSegmentation=S.enableSegmentation),null==e.enableSmoothing&&(e.enableSmoothing=S.enableSmoothing),null==e.smoothSegmentation&&(e.smoothSegmentation=S.smoothSegmentation),null==e.modelType&&(e.modelType=S.modelType),e}(t),[4,(n=new P(e)).initialize()];case 1:return i.sent(),[2,n]}}))}))}function F(t){return t instanceof r.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 E(t){return t instanceof r.Tensor?t:r.browser.fromPixels(t)}function z(t,e,n){return R(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 R(t,e){r.util.assert(0!==t.width,(function(){return e+" width cannot be 0."})),r.util.assert(0!==t.height,(function(){return e+" height cannot be 0."}))}function I(t,e,n){var i=n.rotationVectorStartKeypointIndex,r=n.rotationVectorEndKeypointIndex,o=t.locationData,a=o.relativeKeypoints[i].x*e.width,s=o.relativeKeypoints[i].y*e.height,u=o.relativeKeypoints[r].x*e.width,l=o.relativeKeypoints[r].y*e.height,h=2*Math.sqrt((u-a)*(u-a)+(l-s)*(l-s)),c=function(t,e,n){var i,r=t.locationData,o=n.rotationVectorStartKeypointIndex,a=n.rotationVectorEndKeypointIndex;i=n.rotationVectorTargetAngle?n.rotationVectorTargetAngle:Math.PI*n.rotationVectorTargetAngleDegree/180;var s=r.relativeKeypoints[o].x*e.width,u=r.relativeKeypoints[o].y*e.height,l=r.relativeKeypoints[a].x*e.width,h=r.relativeKeypoints[a].y*e.height;return O(i-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 A(t){if(16!==t.length)throw new Error("Array length must be 16 but got "+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 C(t,e,n,i,r,o,a){return t[e][r]*(t[n][o]*t[i][a]-t[n][a]*t[i][o])}function B(t,e,n){var i=(e+1)%4,r=(e+2)%4,o=(e+3)%4,a=(n+1)%4,s=(n+2)%4,u=(n+3)%4;return C(t,i,r,o,a,s,u)+C(t,r,o,i,a,s,u)+C(t,o,i,r,a,s,u)}function D(t,e,n){void 0===n&&(n={ignoreRotation:!1});for(var i=[],r=0,o=t;r<o.length;r++){var a=o[r],s=a.x-.5,l=a.y-.5,h=n.ignoreRotation?0:e.rotation,c=Math.cos(h)*s-Math.sin(h)*l,f=Math.sin(h)*s+Math.cos(h)*l;c=c*e.width+e.xCenter,f=f*e.height+e.yCenter;var p=a.z*e.width,d=u({},a);d.x=c,d.y=f,d.z=p,i.push(d)}return i}function L(t,e){var n=function(t,e,n,i){var r=(i-n)/255;return{scale:r,offset:n-0*r}}(0,0,e[0],e[1]);return(0,r.tidy)((function(){return(0,r.add)((0,r.mul)(t,n.scale),n.offset)}))}function V(t,e,n){var i,o,a,s,u,l,h,c,f,p,d,m,g=e.outputTensorSize,y=e.keepAspectRatio,v=e.borderMode,w=e.outputTensorFloatRange,x=F(t),b=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}}(x,n),k=function(t,e,n){if(void 0===n&&(n=!1),!n)return{top:0,left:0,right:0,bottom:0};var i=e.height,r=e.width;R(e,"targetSize"),R(t,"roi");var o,a,s=i/r,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}}(b,g,y),S=(i=b,o=x.width,a=x.height,!1,s=i.width,u=i.height,1,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,A(m));return{imageTensor:(0,r.tidy)((function(){var e=E(t),n=(0,r.tensor2d)(z(S,x,g),[1,8]),i="zero"===v?"constant":"nearest",o=r.image.transform((0,r.expandDims)((0,r.cast)(e,"float32")),n,"bilinear",i,0,[g.height,g.width]);return null!=w?L(o,w):o})),padding:k,transformationMatrix:S}}function H(t,e,n,i){return 1===i?.5*(t+e):t+(e-t)*n/(i-1)}function q(t){return null!=t&&null!=t.currentTime}function N(t){for(var e={locationData:{relativeKeypoints:[]}},n=Number.MAX_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER,r=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),i=Math.max(i,s.x),r=Math.min(r,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:r,xMax:i,yMax:o,width:i-n,height:o-r},e}function K(t,e,n,i){return l(this,void 0,void 0,(function(){var i,o,a,s,u;return h(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=(0,r.tensor2d)(t.map((function(t){return[t.locationData.relativeBoundingBox.yMin,t.locationData.relativeBoundingBox.xMin,t.locationData.relativeBoundingBox.yMax,t.locationData.relativeBoundingBox.xMax]}))),o=(0,r.tensor1d)(t.map((function(t){return t.score[0]}))),[4,r.image.nonMaxSuppressionAsync(i,o,e,n)];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})),(0,r.dispose)([i,o,a]),[2,u]}}))}))}function j(t,e){return t.map((function(t){var n=u(u({},t),{x:t.x*e.width,y:t.y*e.height});return null!=t.z&&(n.z=t.z*e.width),n}))}function U(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,l,c,f,p,d,m,g,y,v,w,x,b,k,S,M,T,P,_,F,O;return h(this,(function(h){switch(h.label){case 0:if(i=(0,r.squeeze)(e,[0]),o=i.shape,a=o[0],s=o[1],l=o[2],t.length!==l)throw new Error("Expected heatmap to have same number of channels as the number of landmarks. But got landmarks length: "+t.length+", heatmap length: "+l);return c=[],[4,i.buffer()];case 1:for(f=h.sent(),p=0;p<t.length;p++)if(d=t[p],m=u({},d),c.push(m),g=Math.trunc(m.x*s),y=Math.trunc(m.y*a),!(g<0||g>=s||y<0||g>=a)){for(v=Math.trunc((n.kernelSize-1)/2),w=Math.max(0,g-v),x=Math.min(s,g+v+1),b=Math.max(0,y-v),k=Math.min(a,y+v+1),S=0,M=0,T=0,P=0,_=b;_<k;++_)for(F=w;F<x;++F)O=f.get(_,F,p),S+=O,P=Math.max(P,O),M+=F*O,T+=_*O;P>=n.minConfidenceToRefine&&S>0&&(m.x=M/s/S,m.y=T/a/S)}return i.dispose(),[2,c]}}))}))}function W(t,e){var n=e.left,i=e.top,r=e.left+e.right,o=e.top+e.bottom;return t.map((function(t){return u(u({},t),{x:(t.x-n)/(1-r),y:(t.y-i)/(1-o),z:t.z/(1-r)})}))}function Y(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,u;return h(this,(function(l){switch(l.label){case 0:return i=t[0],o=t[1],a=function(t,e,n){return(0,r.tidy)((function(){var i,o,a,s;n.reverseOutputOrder?(o=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+0],[-1,1])),i=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+1],[-1,1])),s=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+2],[-1,1])),a=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+3],[-1,1]))):(i=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+0],[-1,1])),o=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+1],[-1,1])),a=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+2],[-1,1])),s=(0,r.squeeze)((0,r.slice)(t,[0,n.boxCoordOffset+3],[-1,1]))),o=(0,r.add)((0,r.mul)((0,r.div)(o,n.xScale),e.w),e.x),i=(0,r.add)((0,r.mul)((0,r.div)(i,n.yScale),e.h),e.y),n.applyExponentialOnBoxSize?(a=(0,r.mul)((0,r.exp)((0,r.div)(a,n.hScale)),e.h),s=(0,r.mul)((0,r.exp)((0,r.div)(s,n.wScale)),e.w)):(a=(0,r.mul)((0,r.div)(a,n.hScale),e.h),s=(0,r.mul)((0,r.div)(s,n.wScale),e.h));var u=(0,r.sub)(i,(0,r.div)(a,2)),l=(0,r.sub)(o,(0,r.div)(s,2)),h=(0,r.add)(i,(0,r.div)(a,2)),c=(0,r.add)(o,(0,r.div)(s,2)),f=(0,r.concat)([(0,r.reshape)(u,[n.numBoxes,1]),(0,r.reshape)(l,[n.numBoxes,1]),(0,r.reshape)(h,[n.numBoxes,1]),(0,r.reshape)(c,[n.numBoxes,1])],1);if(n.numKeypoints)for(var p=0;p<n.numKeypoints;++p){var d=n.keypointCoordOffset+p*n.numValuesPerKeypoint,m=void 0,g=void 0;n.reverseOutputOrder?(m=(0,r.squeeze)((0,r.slice)(t,[0,d],[-1,1])),g=(0,r.squeeze)((0,r.slice)(t,[0,d+1],[-1,1]))):(g=(0,r.squeeze)((0,r.slice)(t,[0,d],[-1,1])),m=(0,r.squeeze)((0,r.slice)(t,[0,d+1],[-1,1])));var y=(0,r.add)((0,r.mul)((0,r.div)(m,n.xScale),e.w),e.x),v=(0,r.add)((0,r.mul)((0,r.div)(g,n.yScale),e.h),e.y);f=(0,r.concat)([f,(0,r.reshape)(y,[n.numBoxes,1]),(0,r.reshape)(v,[n.numBoxes,1])],1)}return f}))}(o,e,n),s=(0,r.tidy)((function(){var t=i;return n.sigmoidScore?(null!=n.scoreClippingThresh&&(t=(0,r.clipByValue)(i,-n.scoreClippingThresh,n.scoreClippingThresh)),t=(0,r.sigmoid)(t)):t})),[4,X(a,s,n)];case 1:return u=l.sent(),(0,r.dispose)([a,s]),[2,u]}}))}))}function X(t,e,n){return l(this,void 0,void 0,(function(){var i,r,o,a,s,u,l,c,f,p,d,m;return h(this,(function(h){switch(h.label){case 0:return i=[],[4,t.data()];case 1:return r=h.sent(),[4,e.data()];case 2:for(o=h.sent(),a=0;a<n.numBoxes;++a)if(!(null!=n.minScoreThresh&&o[a]<n.minScoreThresh||(s=a*n.numCoords,u=Q(r[s+0],r[s+1],r[s+2],r[s+3],o[a],n.flipVertically,a),(l=u.locationData.relativeBoundingBox).width<0||l.height<0))){if(n.numKeypoints>0)for((c=u.locationData).relativeKeypoints=[],f=n.numKeypoints*n.numValuesPerKeypoint,p=0;p<f;p+=n.numValuesPerKeypoint)d=s+n.keypointCoordOffset+p,m={x:r[d+0],y:n.flipVertically?1-r[d+1]:r[d+1]},c.relativeKeypoints.push(m);i.push(u)}return[2,i]}}))}))}function Q(t,e,n,i,r,o,a){return{score:[r],ind:a,locationData:{relativeBoundingBox:{xMin:e,yMin:o?1-n:t,xMax:i,yMax:o?1-t:n,width:i-e,height:n-t}}}}function G(t,e){return"none"===t?e:function(t){return 1/(1+Math.exp(-t))}(e)}function Z(t,e,n,i){return l(this,void 0,void 0,(function(){var r,o,a,s,u,l,c,f;return h(this,(function(h){switch(h.label){case 0:return n=n||e.flipHorizontally||!1,i=i||e.flipVertically||!1,r=t.size,o=r/e.numLandmarks,[4,t.data()];case 1:for(a=h.sent(),s=[],u=0;u<e.numLandmarks;++u)l=u*o,(f={x:0,y:0}).x=n?e.inputImageWidth-a[l]:a[l],o>1&&(f.y=i?e.inputImageHeight-a[l+1]:a[l+1]),o>2&&(f.z=a[l+2]),o>3&&(f.score=G(e.visibilityActivation,a[l+3])),s.push(f);for(c=0;c<s.length;++c)(f=s[c]).x=f.x/e.inputImageWidth,f.y=f.y/e.inputImageHeight,f.z=f.z/e.inputImageWidth/(e.normalizeZ||1);return[2,s]}}))}))}function $(t,e,n){var i=t.width,r=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+i*n.shiftX,t.yCenter=t.yCenter+r*n.shiftY;else{var a=(e.width*i*n.shiftX*Math.cos(o)-e.height*r*n.shiftY*Math.sin(o))/e.width,s=(e.width*i*n.shiftX*Math.sin(o)+e.height*r*n.shiftY*Math.cos(o))/e.height;t.xCenter=t.xCenter+a,t.yCenter=t.yCenter+s}if(n.squareLong){var u=Math.max(i*e.width,r*e.height);i=u/e.width,r=u/e.height}else if(n.squareShort){var l=Math.min(i*e.width,r*e.height);i=l/e.width,r=l/e.height}return t.width=i*n.scaleX,t.height=r*n.scaleY,t}function J(t,e){return t.map((function(t){var n=u(u({},t),{x:t.x/e.width,y:t.y/e.height});return null!=t.z&&(t.z=t.z/e.width),n}))}var tt=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}(),et=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 tt(this.getAlpha(this.minCutOff)),this.dx=new tt(this.getAlpha(this.derivateCutOff)),this.lastTimestamp=0}return t.prototype.apply=function(t,e,n){if(null==t)return t;var i=Math.trunc(e);if(this.lastTimestamp>=i)return t;0!==this.lastTimestamp&&0!==i&&(this.frequency=1/(1e-6*(i-this.lastTimestamp))),this.lastTimestamp=i;var r=this.x.hasLastRawValue()?(t-this.x.lastRawValue())*n*this.frequency:0,o=this.dx.applyWithAlpha(r,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}(),nt=function(){function t(t){this.config=t}return t.prototype.apply=function(t,e,n){var i=this;if(null==t)return this.reset(),null;this.initializeFiltersIfEmpty(t);var r=1;if(!this.config.disableValueScaling){if(n<this.config.minAllowedObjectScale)return c(t);r=1/n}return t.map((function(t,n){var o=u(u({},t),{x:i.xFilters[n].apply(t.x,e,r),y:i.yFilters[n].apply(t.y,e,r)});return null!=t.z&&(o.z=i.zFilters[n].apply(t.z,e,r)),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 et(e.config)})),this.yFilters=t.map((function(t){return new et(e.config)})),this.zFilters=t.map((function(t){return new et(e.config)})))},t}(),it=function(){function t(t){this.config=t,this.window=[],this.lowPassFilter=new tt(1),this.lastValue=0,this.lastValueScale=1,this.lastTimestamp=-1}return t.prototype.apply=function(t,e,n){if(null==t)return t;var i,r=Math.trunc(e);if(this.lastTimestamp>=r)return t;if(-1===this.lastTimestamp)i=1;else{for(var o=t*n-this.lastValue*this.lastValueScale,a=r-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);i=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=r,this.lowPassFilter.applyWithAlpha(t,i)},t}(),rt=function(){function t(t){this.config=t}return t.prototype.apply=function(t,e,n){var i=this;if(null==t)return this.reset(),null;var r=1;if(!this.config.disableValueScaling){if(n<this.config.minAllowedObjectScale)return c(t);r=1/n}return this.initializeFiltersIfEmpty(t),t.map((function(t,n){var o=u(u({},t),{x:i.xFilters[n].apply(t.x,e,r),y:i.yFilters[n].apply(t.y,e,r)});return null!=t.z&&(o.z=i.zFilters[n].apply(t.z,e,r)),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 it(e.config)})),this.yFilters=t.map((function(t){return new it(e.config)})),this.zFilters=t.map((function(t){return new it(e.config)})))},t}(),ot=function(){function t(t){if(null!=t.velocityFilter)this.keypointsFilter=new rt(t.velocityFilter);else{if(null==t.oneEuroFilter)throw new Error("Either configure velocityFilter or oneEuroFilter, but got "+t+".");this.keypointsFilter=new nt(t.oneEuroFilter)}}return t.prototype.apply=function(t,e,n,i,r){if(void 0===i&&(i=!1),null==t)return this.keypointsFilter.reset(),null;var o=null!=r?function(t,e){return(t.width*e.width+t.height*e.height)/2}(r,n):1,a=i?j(t,n):t,s=this.keypointsFilter.apply(a,e,o);return i?J(s,n):s},t}(),at=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 tt(e.alpha)})));for(var n=[],i=0;i<t.length;++i){var r=t[i],o=u({},r);o.score=this.visibilityFilters[i].apply(r.score),n.push(o)}return n},t}(),st={reduceBoxesInLowestlayer:!1,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},ut={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"},lt={maxPoses:1,flipHorizontal:!1},ht={applyExponentialOnBoxSize:!1,flipVertically:!1,ignoreClasses:[],numClasses: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},ct={shiftX:0,shiftY:0,scaleX:1.25,scaleY:1.25,squareLong:!0},ft={outputTensorSize:{width:224,height:224},keepAspectRatio:!0,outputTensorFloatRange:[-1,1],borderMode:"zero"},pt={outputTensorSize:{width:256,height:256},keepAspectRatio:!0,outputTensorFloatRange:[0,1],borderMode:"zero"},dt={numLandmarks:39,inputImageWidth:256,inputImageHeight:256,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},mt={numLandmarks:39,inputImageWidth:1,inputImageHeight:1,visibilityActivation:"sigmoid",flipHorizontally:!1,flipVertically:!1},gt={kernelSize:7,minConfidenceToRefine:.5},yt={alpha:.1},vt={oneEuroFilter:{frequency:30,minCutOff:.05,beta:80,derivateCutOff:1,minAllowedObjectScale:1e-6}},wt={oneEuroFilter:{frequency:30,minCutOff:.01,beta:10,derivateCutOff:1,minAllowedObjectScale:1e-6}},xt={oneEuroFilter:{frequency:30,minCutOff:.1,beta:40,derivateCutOff:1,minAllowedObjectScale:1e-6,disableValueScaling:!0}},bt={activation:"none"},kt={combineWithPreviousRatio:.7},St=function(){function t(t){this.mask=t}return t.prototype.toCanvasImageSource=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,w(this.mask)]}))}))},t.prototype.toImageData=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,x(this.mask)]}))}))},t.prototype.toTensor=function(){return l(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.mask]}))}))},t.prototype.getUnderlyingType=function(){return"tensor"},t}();function Mt(t){return k(t),"person"}var Tt=function(){function t(t,e,n,i,o,a){this.detectorModel=t,this.landmarkModel=e,this.enableSmoothing=n,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 i=[],r=[],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]);i.push(a[c]/f),r.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 g=0;g<p;++g)for(var y=0;y<d;++y)for(var v=0;v<i.length;++v){var w={xCenter:(y+t.anchorOffsetX)/d,yCenter:(g+t.anchorOffsetY)/p,width:0,height:0};t.fixedAnchorSize?(w.width=1,w.height=1):(w.width=r[v],w.height=i[v]),e.push(w)}n=s}return e}(st);var s=(0,r.tensor1d)(this.anchors.map((function(t){return t.width}))),u=(0,r.tensor1d)(this.anchors.map((function(t){return t.height}))),l=(0,r.tensor1d)(this.anchors.map((function(t){return t.xCenter}))),h=(0,r.tensor1d)(this.anchors.map((function(t){return t.yCenter})));this.anchorTensor={x:l,y:h,w:s,h:u},this.prevFilteredSegmentationMask=this.enableSegmentation?(0,r.tensor2d)([],[0,0]):null}return t.prototype.estimatePoses=function(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,l,c,f,d,m,g,y,v,w,x,b,k,S,M,T,P,_,O,z;return h(this,(function(h){switch(h.label){case 0:return i=function(t){var e;if(null==(e=null==t?lt:u({},t)).maxPoses&&(e.maxPoses=1),e.maxPoses<=0)throw new Error("Invalid maxPoses "+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=i.maxPoses,this.timestamp=null!=n?1e3*n:q(t)?1e6*t.currentTime:null,o=F(t),a=(0,r.tidy)((function(){return(0,r.cast)(E(t),"float32")})),null!=(s=this.regionOfInterest)?[3,2]:[4,this.detectPose(a)]);case 1:if(0===(l=h.sent()).length)return this.reset(),a.dispose(),[2,[]];c=l[0],s=this.poseDetectionToRoi(c,o),h.label=2;case 2:return[4,this.poseLandmarksByRoi(s,a)];case 3:return f=h.sent(),a.dispose(),null==f?(this.reset(),[2,[]]):(d=f.landmarks,m=f.auxiliaryLandmarks,g=f.poseScore,y=f.worldLandmarks,v=f.segmentationMask,w=this.poseLandmarkFiltering(d,m,y,o),x=w.actualLandmarksFiltered,b=w.auxiliaryLandmarksFiltered,k=w.actualWorldLandmarksFiltered,S=this.poseLandmarksToRoi(b,o),this.regionOfInterest=S,M=this.smoothSegmentation&&null!=v?this.poseSegmentationFiltering(v):v,null!=(T=null!=x?j(x,o):null)&&T.forEach((function(t,e){t.name=p[e]})),null!=(P=k)&&P.forEach((function(t,e){t.name=p[e]})),_={score:g,keypoints:T,keypoints3D:P},null!==M&&(O=(0,r.tidy)((function(){var t=(0,r.expandDims)(M,2),e=(0,r.pad)(t,[[0,0],[0,0],[0,1]]);return(0,r.mirrorPad)(e,[[0,0],[0,0],[0,2]],"symmetric")})),this.smoothSegmentation||(0,r.dispose)(M),z={maskValueToLabel:Mt,mask:new St(O)},_.segmentation=z),[2,[_]])}}))}))},t.prototype.poseSegmentationFiltering=function(t){var e=this.prevFilteredSegmentationMask;return 0===e.size?this.prevFilteredSegmentationMask=t:(this.prevFilteredSegmentationMask=function(t,e,n){return"webgl"===(0,r.getBackend)()?function(t,e,n){var i=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 * "+i+");\n\n setOutput(outputValue);\n }\n"},a=(0,r.backend)();return(0,r.tidy)((function(){var n=a.compileAndRun(o,[t,e]);return(0,r.engine)().makeTensorFromDataId(n.dataId,n.shape,n.dtype)}))}(t,e,n):(0,r.tidy)((function(){var i=(0,r.sub)(e,.5),o=(0,r.square)(i),a=(0,r.sub)(1,(0,r.minimum)(1,(0,r.mul)(o,(0,r.add)(5.68842,(0,r.mul)(o,(0,r.add)(-.748699,(0,r.mul)(o,(0,r.add)(-57.8051,(0,r.mul)(o,(0,r.add)(291.309,(0,r.mul)(o,-624.717)))))))))));return(0,r.add)(e,(0,r.mul)((0,r.sub)(t,e),(0,r.mul)(a,n.combineWithPreviousRatio)))}))}(e,t,kt),(0,r.dispose)(t)),(0,r.dispose)(e),this.prevFilteredSegmentationMask},t.prototype.dispose=function(){this.detectorModel.dispose(),this.landmarkModel.dispose(),(0,r.dispose)([this.anchorTensor.x,this.anchorTensor.y,this.anchorTensor.w,this.anchorTensor.h,this.prevFilteredSegmentationMask])},t.prototype.reset=function(){this.regionOfInterest=null,this.enableSegmentation&&((0,r.dispose)(this.prevFilteredSegmentationMask),this.prevFilteredSegmentationMask=(0,r.tensor2d)([],[0,0])),this.visibilitySmoothingFilterActual=null,this.visibilitySmoothingFilterAuxiliary=null,this.landmarksSmoothingFilterActual=null,this.landmarksSmoothingFilterAuxiliary=null},t.prototype.detectPose=function(t){return l(this,void 0,void 0,(function(){var e,n,i,o,a,s,u,l,c,f;return h(this,(function(h){switch(h.label){case 0:return e=V(t,ft),n=e.imageTensor,i=e.padding,o=this.detectorModel.predict(n),a=function(t){return(0,r.tidy)((function(){var e=function(t){return(0,r.tidy)((function(){return[(0,r.slice)(t,[0,0,0],[1,-1,1]),(0,r.slice)(t,[0,0,1],[1,-1,-1])]}))}(t),n=e[0],i=e[1];return{boxes:(0,r.squeeze)(i),logits:(0,r.squeeze)(n)}}))}(o),s=a.boxes,[4,Y([u=a.logits,s],this.anchorTensor,ht)];case 1:return 0===(l=h.sent()).length?((0,r.dispose)([n,o,u,s]),[2,l]):[4,K(l,this.maxPoses,.3)];case 2:return c=h.sent(),f=function(t,e){void 0===t&&(t=[]);for(var n=e.left,i=e.top,r=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-r),h=(u.yMin-i)/(1-o),c=u.width/(1-r),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-r),a=(t.y-i)/(1-o);t.x=e,t.y=a}))}return t}(c,i),(0,r.dispose)([n,o,u,s]),[2,f]}}))}))},t.prototype.poseDetectionToRoi=function(t,e){return $(I(t,e,{rotationVectorEndKeypointIndex:1,rotationVectorStartKeypointIndex:0,rotationVectorTargetAngleDegree:90}),e,ct)},t.prototype.poseLandmarksByRoi=function(t,e){return l(this,void 0,void 0,(function(){var n,i,o,a,s,l,c,f,p,d,m,g,y,v;return h(this,(function(h){switch(h.label){case 0:if(n=F(e),i=V(e,pt,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 "+this.modelType);return l=["ld_3d","output_poseflag","activation_heatmap","world_3d"],this.enableSegmentation&&l.push("activation_segmentation"),c=this.landmarkModel.execute(o,l),[4,this.tensorsToPoseLandmarksAndSegmentation(c)];case 1:return null==(f=h.sent())?((0,r.dispose)(c),(0,r.dispose)(o),[2,null]):(p=f.landmarks,d=f.auxiliaryLandmarks,m=f.poseScore,g=f.worldLandmarks,y=f.segmentationMask,[4,this.poseLandmarksAndSegmentationInverseProjection(n,t,a,s,p,d,g,y)]);case 2:return v=h.sent(),(0,r.dispose)(c),(0,r.dispose)(o),[2,u({poseScore:m},v)]}}))}))},t.prototype.poseLandmarksAndSegmentationInverseProjection=function(t,e,n,i,o,a,s,c){return l(this,void 0,void 0,(function(){var l,f,p,d,m,g;return h(this,(function(h){return l=W(o,n),f=W(a,n),p=D(l,e),d=D(f,e),m=function(t,e){for(var n=[],i=0,r=t;i<r.length;i++){var o=r[i],a=o.x,s=o.y,l=e.rotation,h=Math.cos(l)*a-Math.sin(l)*s,c=Math.sin(l)*a+Math.cos(l)*s,f=u({},o);f.x=h,f.y=c,n.push(f)}return n}(s,e),g=null,this.enableSegmentation&&(g=(0,r.tidy)((function(){var e=c.shape,n=e[0],o=e[1],a=function(t){var e=A(new Array(16).fill(0));e[0][0]=B(t,0,0),e[1][0]=-B(t,0,1),e[2][0]=B(t,0,2),e[3][0]=-B(t,0,3),e[0][2]=B(t,2,0),e[1][2]=-B(t,2,1),e[2][2]=B(t,2,2),e[3][2]=-B(t,2,3),e[0][1]=-B(t,1,0),e[1][1]=B(t,1,1),e[2][1]=-B(t,1,2),e[3][1]=B(t,1,3),e[0][3]=-B(t,3,0),e[1][3]=B(t,3,1),e[2][3]=-B(t,3,2),e[3][3]=B(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],i=0;i<e.length;i++)for(var r=0;r<e.length;r++)e[i][r]/=n;return e}(i),s=(0,r.tensor2d)(z(a,{width:o,height:n},t),[1,8]),u=[1,n,o,1];return(0,r.squeeze)(r.image.transform((0,r.reshape)(c,u),s,"bilinear","constant",0,[t.height,t.width]),[0,3])})),(0,r.dispose)(c)),[2,{landmarks:p,auxiliaryLandmarks:d,worldLandmarks:m,segmentationMask:g}]}))}))},t.prototype.tensorsToPoseLandmarksAndSegmentation=function(t){return l(this,void 0,void 0,(function(){var e,n,i,o,a,s,l,c,f,p,d,m,g;return h(this,(function(h){switch(h.label){case 0:return e=t[0],n=t[1],i=t[2],o=t[3],a=this.enableSegmentation?t[4]:null,[4,n.data()];case 1:return(s=h.sent()[0])<.5?[2,null]:[4,Z(e,dt)];case 2:return[4,U(h.sent(),i,gt)];case 3:return l=h.sent(),c=l.slice(0,33),f=l.slice(33,35),[4,Z(o,mt)];case 4:return p=h.sent(),d=p.slice(0,33),m=function(t,e,n){void 0===n&&(n=!0);for(var i=[],r=0;r<t.length;r++){var o=u({},e[r]);n&&(o.score=t[r].score),i.push(o)}return i}(c,d,!0),g=this.enableSegmentation?function(t,e,n){return(0,r.tidy)((function(){var n=(0,r.squeeze)(t,[0]),i=n.shape[2];if(1===i){var o=n;switch(e.activation){case"none":break;case"sigmoid":o=(0,r.sigmoid)(o);break;case"softmax":throw new Error("Softmax activation requires two channels.");default:throw new Error("Activation not supported ("+e.activation+")")}var a=o;return(0,r.squeeze)(a,[2])}throw new Error("Unsupported number of tensor channels "+i)}))}(a,bt):null,[2,{landmarks:c,auxiliaryLandmarks:f,poseScore:s,worldLandmarks:m,segmentationMask:g}]}}))}))},t.prototype.poseLandmarksToRoi=function(t,e){return $(I(N(t),e,{rotationVectorStartKeypointIndex:0,rotationVectorEndKeypointIndex:1,rotationVectorTargetAngleDegree:90}),e,ct)},t.prototype.poseLandmarkFiltering=function(t,e,n,i){var r,o,a;if(null!=this.timestamp&&this.enableSmoothing){var s=I(N(e),i,{rotationVectorEndKeypointIndex:0,rotationVectorStartKeypointIndex:1,rotationVectorTargetAngleDegree:90});null==this.visibilitySmoothingFilterActual&&(this.visibilitySmoothingFilterActual=new at(yt)),r=this.visibilitySmoothingFilterActual.apply(t),null==this.visibilitySmoothingFilterAuxiliary&&(this.visibilitySmoothingFilterAuxiliary=new at(yt)),o=this.visibilitySmoothingFilterAuxiliary.apply(e),a=this.visibilitySmoothingFilterActual.apply(n),null==this.landmarksSmoothingFilterActual&&(this.landmarksSmoothingFilterActual=new ot(vt)),r=this.landmarksSmoothingFilterActual.apply(r,this.timestamp,i,!0,s),null==this.landmarksSmoothingFilterAuxiliary&&(this.landmarksSmoothingFilterAuxiliary=new ot(wt)),o=this.landmarksSmoothingFilterAuxiliary.apply(o,this.timestamp,i,!0,s),null==this.worldLandmarksSmoothingFilterActual&&(this.worldLandmarksSmoothingFilterActual=new ot(xt)),a=this.worldLandmarksSmoothingFilterActual.apply(n,this.timestamp)}else r=t,o=e,a=n;return{actualLandmarksFiltered:r,auxiliaryLandmarksFiltered:o,actualWorldLandmarksFiltered:a}},t}();function Pt(t){return l(this,void 0,void 0,(function(){var e,n,i,r,a,s;return h(this,(function(l){switch(l.label){case 0:return e=function(t){var e=u({},null==t?ut:t);if(null==e.enableSmoothing&&(e.enableSmoothing=ut.enableSmoothing),null==e.enableSegmentation&&(e.enableSegmentation=ut.enableSegmentation),null==e.smoothSegmentation&&(e.smoothSegmentation=ut.smoothSegmentation),null==e.modelType&&(e.modelType=ut.modelType),null==e.detectorModelUrl&&(e.detectorModelUrl=ut.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,i="string"==typeof e.landmarkModelUrl&&e.landmarkModelUrl.indexOf("https://tfhub.dev")>-1,[4,Promise.all([(0,o.YL)(e.detectorModelUrl,{fromTFHub:n}),(0,o.YL)(e.landmarkModelUrl,{fromTFHub:i})])];case 1:return r=l.sent(),a=r[0],s=r[1],[2,new Tt(a,s,e.enableSmoothing,e.enableSegmentation,e.smoothSegmentation,e.modelType)]}}))}))}var _t,Ft,Ot,Et=function(){function t(t){!function(t){if(t.maxTracks<1)throw new Error("Must specify 'maxTracks' to be at least 1, but encountered "+t.maxTracks);if(t.maxAge<=0)throw new Error("Must specify 'maxAge' to be positive, but encountered "+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 "+t.keypointTrackerParams.keypointConfidenceThreshold);if(t.keypointTrackerParams.minNumberOfKeypoints<1)throw new Error("Must specify 'minNumberOfKeypoints' to be at least 1, but encountered "+t.keypointTrackerParams.minNumberOfKeypoints);for(var e=0,n=t.keypointTrackerParams.keypointFalloff;e<n.length;e++){var i=n[e];if(i<=0)throw new Error("Must specify each keypoint falloff parameterto be positive but encountered "+i)}}}(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 i=Array.from(Array(e[0].length).keys()),r=[],o=0,a=Array.from(Array(t.length).keys());o<a.length;o++){var s=a[o];if(0!==i.length){for(var u=-1,l=-1,h=0,c=i;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=i.indexOf(u);i.splice(m,1)}else r.push(s)}else r.push(s)}for(var g=0,y=r;g<y.length;g++){s=y[g];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 i={id:n||this.nextTrackID(),lastTimestamp:e,keypoints:c(t.keypoints).map((function(t){return u({},t)}))};return void 0!==t.box&&(i.box=u({},t.box)),i},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}(),zt=function(t){function e(e){return t.call(this,e)||this}return s(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),i=Math.max(t.box.yMin,e.box.yMin),r=Math.min(t.box.xMax,e.box.xMax),o=Math.min(t.box.yMax,e.box.yMax);if(n>=r||i>=o)return 0;var a=(r-n)*(o-i);return a/(t.box.width*t.box.height+e.box.width*e.box.height-a)},e}(Et),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 s(e,t),e.prototype.computeSimilarity=function(t){if(0===t.length||0===this.tracks.length)return[[]];for(var e=[],n=0,i=t;n<i.length;n++){for(var r=i[n],o=[],a=0,s=this.tracks;a<s.length;a++){var u=s[a];o.push(this.oks(r,u))}e.push(o)}return e},e.prototype.oks=function(t,e){for(var n=this.area(e.keypoints)+1e-6,i=0,r=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)){r+=1;var u=Math.pow(a.x-s.x,2)+Math.pow(a.y-s.y,2),l=2*this.keypointFalloff[o];i+=Math.exp(-1*u/(2*n*Math.pow(l,2)))}}return r<this.minNumKeyoints?0:i/r},e.prototype.area=function(t){var e=this,n=t.filter((function(t){return t.score>e.keypointThreshold})),i=Math.min.apply(Math,c([1],n.map((function(t){return t.x})))),r=Math.max.apply(Math,c([0],n.map((function(t){return t.x})))),o=Math.min.apply(Math,c([1],n.map((function(t){return t.y}))));return(r-i)*(Math.max.apply(Math,c([0],n.map((function(t){return t.y}))))-o)},e}(Et);function It(t){switch(t){case Ft.BlazePose:return p.reduce((function(t,e,n){return t[e]=n,t}),{});case Ft.PoseNet:case Ft.MoveNet:return f.reduce((function(t,e,n){return t[e]=n,t}),{});default:throw new Error("Model "+t+" is not supported.")}}(Ot=_t||(_t={})).Keypoint="keypoint",Ot.BoundingBox="boundingBox",function(t){t.MoveNet="MoveNet",t.BlazePose="BlazePose",t.PoseNet="PoseNet"}(Ft||(Ft={}));var At=Object.freeze({__proto__:null,getKeypointIndexBySide:function(t){switch(t){case Ft.BlazePose:return d;case Ft.PoseNet:case Ft.MoveNet:return m;default:throw new Error("Model "+t+" is not supported.")}},getAdjacentPairs:function(t){switch(t){case Ft.BlazePose:return y;case Ft.PoseNet:case Ft.MoveNet:return g;default:throw new Error("Model "+t+" is not supported.")}},getKeypointIndexByName:It}),Ct=["SinglePose.Lightning","SinglePose.Thunder","MultiPose.Lightning"],Bt={modelType:"SinglePose.Lightning",enableSmoothing:!0},Dt={},Lt={frequency:30,minCutOff:2.5,beta:300,derivateCutOff:2.5,thresholdCutOff:.5,thresholdBeta:5,disableValueScaling:!0},Vt={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}},Ht={maxTracks:18,maxAge:1e3,minSimilarity:.15,trackerParams:{}};function qt(t,e){var n,i,r,o;return t?e.width>e.height?(n=1,i=e.height/e.width,r=0,o=(e.width/2-e.height/2)/e.width):(n=e.width/e.height,i=1,r=(e.height/2-e.width/2)/e.height,o=0):e.width>e.height?(n=e.width/e.height,i=1,r=(e.height/2-e.width/2)/e.height,o=0):(n=1,i=e.height/e.width,r=0,o=(e.width/2-e.height/2)/e.width),{yMin:r,xMin:o,yMax:r+n,xMax:o+i,height:n,width:i}}function Nt(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 Kt=function(){function t(t,e){this.moveNetModel=t,this.modelInputResolution={height:0,width:0},this.keypointIndexByName=It(Ft.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 nt(Lt),this.cropRegionFilterYMin=new tt(.9),this.cropRegionFilterXMin=new tt(.9),this.cropRegionFilterYMax=new tt(.9),this.cropRegionFilterXMax=new tt(.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===_t.Keypoint?this.tracker=new Rt(e.trackerConfig):e.trackerType===_t.BoundingBox&&(this.tracker=new zt(e.trackerConfig)),this.enableSmoothing&&(this.keypointFilterMap=new Map))}return t.prototype.runSinglePersonPoseModel=function(t){return l(this,void 0,void 0,(function(){var e,n,i,o,a;return h(this,(function(s){switch(s.label){case 0:if(4!==(e=this.moveNetModel.execute(t)).shape.length||1!==e.shape[0]||1!==e.shape[1]||17!==e.shape[2]||3!==e.shape[3])throw e.dispose(),new Error("Unexpected output shape from model: ["+e.shape+"]");return"webgpu"===(0,r.getBackend)()?[3,1]:(n=e.dataSync(),[3,3]);case 1:return[4,e.data()];case 2:n=s.sent(),s.label=3;case 3:for(e.dispose(),i={keypoints:[],score:0},o=0,a=0;a<17;++a)i.keypoints[a]={y:n[3*a],x:n[3*a+1],score:n[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 l(this,void 0,void 0,(function(){var e,n,i,o,a,s,u,l;return h(this,(function(h){switch(h.label){case 0:if(3!==(e=this.moveNetModel.execute(t)).shape.length||1!==e.shape[0]||56!==e.shape[2])throw e.dispose(),new Error("Unexpected output shape from model: ["+e.shape+"]");return"webgpu"===(0,r.getBackend)()?[3,1]:(n=e.dataSync(),[3,3]);case 1:return[4,e.data()];case 2:n=h.sent(),h.label=3;case 3:for(e.dispose(),i=[],o=n.length/56,a=0;a<o;++a)for(i[a]={keypoints:[]},s=56*a+51,i[a].box={yMin:n[s],xMin:n[s+1],yMax:n[s+2],xMax:n[s+3],width:n[s+3]-n[s+1],height:n[s+2]-n[s]},u=56*a+55,i[a].score=n[u],i[a].keypoints=[],l=0;l<17;++l)i[a].keypoints[l]={y:n[56*a+3*l],x:n[56*a+3*l+1],score:n[56*a+3*l+2]};return[2,i]}}))}))},t.prototype.estimatePoses=function(t,e,n){return void 0===e&&(e=Dt),l(this,void 0,void 0,(function(){var i,o,a,s,l,c;return h(this,(function(h){switch(h.label){case 0:return e=function(t){return null==t?Dt:u({},t)}(e),null==t?(this.reset(),[2,[]]):(null==n?q(t)&&(n=1e6*t.currentTime):n*=1e3,i=E(t),o=F(i),a=(0,r.expandDims)(i,0),t instanceof r.Tensor||i.dispose(),s=[],this.multiPoseModel?[3,2]:[4,this.estimateSinglePose(a,o,n)]);case 1:return s=h.sent(),[3,4];case 2:return[4,this.estimateMultiplePoses(a,o,n)];case 3:s=h.sent(),h.label=4;case 4:for(l=0;l<s.length;++l)for(c=0;c<s[l].keypoints.length;++c)s[l].keypoints[c].name=f[c],s[l].keypoints[c].y*=o.height,s[l].keypoints[c].x*=o.width;return[2,s]}}))}))},t.prototype.estimateSinglePose=function(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,u=this;return h(this,(function(l){switch(l.label){case 0:return this.cropRegion||(this.cropRegion=qt(null==this.cropRegion,e)),i=(0,r.tidy)((function(){var e=(0,r.tensor2d)([[u.cropRegion.yMin,u.cropRegion.xMin,u.cropRegion.yMax,u.cropRegion.xMax]]),n=(0,r.zeros)([1],"int32"),i=[u.modelInputResolution.height,u.modelInputResolution.width];return(0,r.cast)(r.image.cropAndResize(t,e,n,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!=n&&this.enableSmoothing&&(o.keypoints=this.keypointFilter.apply(o.keypoints,n,1)),s=function(t,e,n,i){for(var r={},o=0,a=f;o<a.length;o++){var s=a[o];r[s]=[e[n[s]].y*i.height,e[n[s]].x*i.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=(r.left_hip[0]+r.right_hip[0])/2,l=(r.left_hip[1]+r.right_hip[1])/2,h=function(t,e,n,i,r){for(var o=["left_shoulder","right_shoulder","left_hip","right_hip"],a=0,s=0,u=0;u<o.length;u++)(p=Math.abs(i-n[o[u]][0]))>a&&(a=p),(d=Math.abs(r-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(i-n[m][0]))>l&&(l=p),(d=Math.abs(r-n[m][1]))>h&&(h=d))}return[a,s,l,h]}(e,n,r,u,l),c=h[0],p=h[1],d=h[2],m=h[3],g=Math.max(1.9*p,1.9*c,1.2*d,1.2*m),y=[u-(g=Math.min(g,Math.max(l,i.width-l,u,i.height-u))),l-g];if(g>Math.max(i.width,i.height)/2)return qt(null==t,i);var v=2*g;return{yMin:y[0]/i.height,xMin:y[1]/i.width,yMax:(y[0]+v)/i.height,xMax:(y[1]+v)/i.width,height:(y[0]+v)/i.height-y[0]/i.height,width:(y[1]+v)/i.width-y[1]/i.width}}return qt(null==t,i)}(this.cropRegion,o.keypoints,this.keypointIndexByName,e),this.cropRegion=this.filterCropRegion(s),[2,[o]]}}))}))},t.prototype.estimateMultiplePoses=function(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,u,l,c,f,p,d,m,g=this;return h(this,(function(h){switch(h.label){case 0:return e.width>e.height?(o=this.multiPoseMaxDimension,a=Math.round(this.multiPoseMaxDimension*e.height/e.width),i=r.image.resizeBilinear(t,[a,o]),u=o,l=32*Math.ceil(a/32),s=(0,r.pad)(i,[[0,0],[0,l-a],[0,0],[0,0]])):(o=Math.round(this.multiPoseMaxDimension*e.width/e.height),a=this.multiPoseMaxDimension,i=r.image.resizeBilinear(t,[a,o]),u=32*Math.ceil(o/32),l=a,s=(0,r.pad)(i,[[0,0],[0,0],[0,u-o],[0,0]])),i.dispose(),t.dispose(),c=(0,r.cast)(s,"int32"),s.dispose(),[4,this.runMultiPersonPoseModel(c)];case 1:for(f=h.sent(),c.dispose(),f=f.filter((function(t){return t.score>=g.minPoseScore})),d=0;d<f.length;++d)for(p=0;p<f[d].keypoints.length;++p)f[d].keypoints[p].y*=l/a,f[d].keypoints[p].x*=u/o;if(this.enableTracking&&(this.tracker.apply(f,n),this.enableSmoothing)){for(d=0;d<f.length;++d)this.keypointFilterMap.has(f[d].id)||this.keypointFilterMap.set(f[d].id,new nt(Lt)),f[d].keypoints=this.keypointFilterMap.get(f[d].id).apply(f[d].keypoints,n,1);m=this.tracker.getTrackIDs(),this.keypointFilterMap.forEach((function(t,e){m.has(e)||g.keypointFilterMap.delete(e)}))}return[2,f]}}))}))},t.prototype.filterCropRegion=function(t){if(t){var e=this.cropRegionFilterYMin.apply(t.yMin),n=this.cropRegionFilterXMin.apply(t.xMin),i=this.cropRegionFilterYMax.apply(t.yMax),r=this.cropRegionFilterXMax.apply(t.xMax);return{yMin:e,xMin:n,yMax:i,xMax:r,height:i-e,width:r-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 jt(t){return void 0===t&&(t=Bt),l(this,void 0,void 0,(function(){var e,n,i,a;return h(this,(function(s){switch(s.label){case 0:return e=function(t){var e,n=null==t?Bt:u({},t);if(null==n.modelType)n.modelType="SinglePose.Lightning";else if(Ct.indexOf(n.modelType)<0)throw new Error("Invalid architecture "+n.modelType+". Should be one of "+Ct);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=_t.BoundingBox),n.trackerType===_t.Keypoint)null!=n.trackerConfig?n.trackerConfig=function(t){var e=Nt(Vt,t);return e.keypointTrackerParams=u({},Vt.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=Vt;else{if(n.trackerType!==_t.BoundingBox)throw new Error("Tracker type not supported by MoveNet");null!=n.trackerConfig?n.trackerConfig=(e=n.trackerConfig,Nt(Ht,e)):n.trackerConfig=Ht}return n}(t),i=!0,e.modelUrl?(i="string"==typeof e.modelUrl&&e.modelUrl.indexOf("https://tfhub.dev")>-1,[4,(0,o.YL)(e.modelUrl,{fromTFHub:i})]):[3,2];case 1:return n=s.sent(),[3,4];case 2:return a=void 0,"SinglePose.Lightning"===e.modelType?a="https://tfhub.dev/google/tfjs-model/movenet/singlepose/lightning/4":"SinglePose.Thunder"===e.modelType?a="https://tfhub.dev/google/tfjs-model/movenet/singlepose/thunder/4":"MultiPose.Lightning"===e.modelType&&(a="https://tfhub.dev/google/tfjs-model/movenet/multipose/lightning/1"),[4,(0,o.YL)(a,{fromTFHub:i})];case 3:n=s.sent(),s.label=4;case 4:return"webgl"===(0,r.getBackend)()&&(0,r.env)().set("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD",0),[2,new Kt(n,e)]}}))}))}var Ut={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:{height:257,width:257}},Wt=["MobileNetV1","ResNet50"],Yt={MobileNetV1:[8,16],ResNet50:[16]},Xt=[8,16,32],Qt={MobileNetV1:[.5,.75,1],ResNet50:[1]},Gt=[1,2,4],Zt={maxPoses:1,flipHorizontal:!1},$t={maxPoses:5,flipHorizontal:!1,scoreThreshold:.5,nmsRadius:20},Jt=[-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,i,r,o){for(var a=o.shape,s=a[0],u=a[1],l=!0,h=Math.max(n-r,0),c=Math.min(n+r+1,s),f=h;f<c;++f){for(var p=Math.max(i-r,0),d=Math.min(i+r+1,u),m=p;m<d;++m)if(o.get(f,m,t)>e){l=!1;break}if(!l)break}return l}function ie(t){return l(this,void 0,void 0,(function(){return h(this,(function(e){return[2,Promise.all(t.map((function(t){return t.buffer()})))]}))}))}function re(t,e,n,i){return{y:i.get(t,e,n),x:i.get(t,e,n+17)}}function oe(t,e,n){var i=re(t.heatmapY,t.heatmapX,t.id,n),r=i.y,o=i.x;return{x:t.heatmapX*e+o,y:t.heatmapY*e+r}}function ae(t,e,n,i){var r=n.x,o=n.y;return t.some((function(t){var n,a,s,u,l=t.keypoints;return n=o,a=r,(s=l[i].y-n)*s+(u=l[i].x-a)*u<=e}))}var se=f.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,i){return{y:ce(Math.round(t.y/e),0,n-1),x:ce(Math.round(t.x/e),0,i-1)}}function pe(t,e){return{x:t.x+e.x,y:t.y+e.y}}function de(t,e,n,i,r,o,a,s){void 0===s&&(s=2);for(var u=i.shape,l=u[0],h=u[1],c={y:e.y,x:e.x},p=pe(c,function(t,e,n){var i=n.shape[2]/2;return{y:n.get(e.y,e.x,t),x:n.get(e.y,e.x,i+t)}}(t,fe(c,o,l,h),a)),d=0;d<s;d++){var m=fe(p,o,l,h),g=re(m.y,m.x,n,r);p=pe({x:m.x*o,y:m.y*o},{x:g.x,y:g.y})}var y=fe(p,o,l,h),v=i.get(y.y,y.x,n);return{y:p.y,x:p.x,name:f[n],score:v}}function me(t,e,n,i,r,o){var a=e.shape[2],s=le.length,u=new Array(a),l=t.part,h=t.score,c=oe(l,i,n);u[l.id]={score:h,name:f[l.id],y:c.y,x:c.x};for(var p=s-1;p>=0;--p){var d=le[p],m=he[p];u[d]&&!u[m]&&(u[m]=de(p,u[d],m,e,n,i,o))}for(p=0;p<s;++p)d=he[p],m=le[p],u[d]&&!u[m]&&(u[m]=de(p,u[d],m,e,n,i,r));return u}function ge(t,e,n){return n.reduce((function(n,i,r){var o=i.y,a=i.x,s=i.score;return ae(t,e,{y:o,x:a},r)||(n+=s),n}),0)/n.length}function ye(t,e,n,i,r,o,a,s){return void 0===a&&(a=.5),void 0===s&&(s=20),l(this,void 0,void 0,(function(){var u,l,c,f,p,d,m,g,y,v,w,x;return h(this,(function(h){switch(h.label){case 0:return[4,ie([t,e,n,i])];case 1:for(u=h.sent(),l=u[0],c=u[1],f=u[2],p=u[3],d=[],m=function(t,e,n){for(var i=n.shape,r=i[0],o=i[1],a=i[2],s=new ee(r*o*a,(function(t){return t.score})),u=0;u<r;++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),g=s*s;d.length<o&&!m.empty();)y=m.dequeue(),v=oe(y.part,r,c),ae(d,g,v,y.part.id)||(w=me(y,l,c,r,f,p),x=ge(d,g,w),d.push({keypoints:w,score:x}));return[2,d]}}))}))}function ve(t,e,n){return(0,r.tidy)((function(){var i=function(t,e){for(var n=[],i=0;i<f.length;i++){var o=we(t.get(i,0).valueOf(),t.get(i,1).valueOf(),i,e),a=o.x,s=o.y;n.push(s),n.push(a)}return(0,r.tensor2d)(n,[f.length,2])}(t,n);return(0,r.add)((0,r.cast)((0,r.mul)(t.toTensor(),(0,r.scalar)(e,"int32")),"float32"),i)}))}function we(t,e,n,i){return{y:i.get(t,e,n),x:i.get(t,e,n+f.length)}}function xe(t,e,n){return l(this,void 0,void 0,(function(){var i,o,a,s,u,l,c,p,d,m;return h(this,(function(h){switch(h.label){case 0:return i=0,o=function(t){var e=t.shape,n=e[0],i=e[1],o=e[2];return(0,r.tidy)((function(){var e,a,s=(0,r.reshape)(t,[n*i,o]),u=(0,r.argMax)(s,0),l=(0,r.expandDims)((0,r.div)(u,(0,r.scalar)(i,"int32")),1),h=(0,r.expandDims)((e=u,a=i,(0,r.tidy)((function(){var t=(0,r.div)(e,(0,r.scalar)(a,"int32"));return(0,r.sub)(e,(0,r.mul)(t,(0,r.scalar)(a,"int32")))}))),1);return(0,r.concat)([l,h],1)}))}(t),[4,Promise.all([t.buffer(),e.buffer(),o.buffer()])];case 1:return a=h.sent(),s=a[0],u=a[1],l=a[2],[4,(c=ve(l,n,u)).buffer()];case 2:return p=h.sent(),d=Array.from(function(t,e){for(var n=e.shape[0],i=new Float32Array(n),r=0;r<n;r++){var o=e.get(r,0),a=e.get(r,1);i[r]=t.get(o,a,r)}return i}(s,l)),m=d.map((function(t,e){return i+=t,{y:p.get(e,0),x:p.get(e,1),score:t,name:f[e]}})),o.dispose(),c.dispose(),[2,{keypoints:m,score:i/m.length}]}}))}))}function be(t,e){return(t-1)%e==0}var ke="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",Se="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";function Me(t,e){return function(t,e){return(t-1)%e==0}(t,e)?t:Math.floor(t/e)*e+1}var Te=function(){function t(t,e){this.posenetModel=t;var n=this.posenetModel.inputs[0].shape;r.util.assert(-1===n[1]&&-1===n[2],(function(){return"Input shape ["+n[1]+", "+n[2]+"] must both be equal to or -1"}));var i,o,a=(i=e.inputResolution,o=e.outputStride,{height:Me(i.height,o),width:Me(i.width,o)});!function(t){r.util.assert(Xt.indexOf(t)>=0,(function(){return"outputStride of "+t+" is invalid. It must be either 8 or 16."}))}(e.outputStride),function(t,e){r.util.assert(be(t.height,e),(function(){return"height of "+t.height+" is invalid for output stride "+e+"."})),r.util.assert(be(t.width,e),(function(){return"width of "+t.width+" is invalid for output stride "+e+"."}))}(a,e.outputStride),this.inputResolution=a,this.outputStride=e.outputStride,this.architecture=e.architecture}return t.prototype.estimatePoses=function(t,e){return void 0===e&&(e=Zt),l(this,void 0,void 0,(function(){var n,i,o,a,s,l,c,f,p,d,m,g,y,v,w;return h(this,(function(h){switch(h.label){case 0:return n=function(t){var e=t;if(null==e.maxPoses&&(e.maxPoses=1),e.maxPoses<=0)throw new Error("Invalid maxPoses "+e.maxPoses+". Should be > 0.");if(e.maxPoses>1){if((e=u(u({},$t),e)).scoreThreshold<0||e.scoreThreshold>1)throw new Error("Invalid scoreThreshold "+e.scoreThreshold+". Should be in range [0.0, 1.0]");if(e.nmsRadius<=0)throw new Error("Invalid nmsRadius "+e.nmsRadius+".")}return e}(e),null==t?[2,[]]:(this.maxPoses=n.maxPoses,i=V(t,{outputTensorSize:this.inputResolution,keepAspectRatio:!0,borderMode:"replicate"}),o=i.imageTensor,a=i.padding,s="ResNet50"===this.architecture?(0,r.add)(o,Jt):L(o,[-1,1]),l=this.posenetModel.predict(s),"ResNet50"===this.architecture?(c=(0,r.squeeze)(l[2],[0]),f=(0,r.squeeze)(l[3],[0]),p=(0,r.squeeze)(l[0],[0]),d=(0,r.squeeze)(l[1],[0])):(c=(0,r.squeeze)(l[0],[0]),f=(0,r.squeeze)(l[1],[0]),p=(0,r.squeeze)(l[2],[0]),d=(0,r.squeeze)(l[3],[0])),m=(0,r.sigmoid)(f),1!==this.maxPoses?[3,2]:[4,xe(m,c,this.outputStride)]);case 1:return y=h.sent(),g=[y],[3,4];case 2:return[4,ye(m,c,p,d,this.outputStride,this.maxPoses,n.scoreThreshold,n.nmsRadius)];case 3:g=h.sent(),h.label=4;case 4:return v=F(t),w=function(t,e,n,i){var r=e.height,o=e.width,a=r/(n.height*(1-i.top-i.bottom)),s=o/(n.width*(1-i.left-i.right)),u=-i.top*n.height,l=-i.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,v,this.inputResolution,a),n.flipHorizontal&&(w=function(t,e){for(var n=0,i=t;n<i.length;n++)for(var r=0,o=i[n].keypoints;r<o.length;r++){var a=o[r];a.x=e.width-1-a.x}return t}(w,v)),o.dispose(),s.dispose(),(0,r.dispose)(l),c.dispose(),f.dispose(),p.dispose(),d.dispose(),m.dispose(),[2,w]}}))}))},t.prototype.dispose=function(){this.posenetModel.dispose()},t.prototype.reset=function(){},t}();function Pe(t){return void 0===t&&(t=Ut),l(this,void 0,void 0,(function(){var e,n,i,r,a;return h(this,(function(s){switch(s.label){case 0:return"ResNet50"!==(e=function(t){var e=t||Ut;if(null==e.architecture&&(e.architecture="MobileNetV1"),Wt.indexOf(e.architecture)<0)throw new Error("Invalid architecture "+e.architecture+". Should be one of "+Wt);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 "+e.outputStride+". Should be one of "+Yt[e.architecture]+" for architecture "+e.architecture+".");if(null==e.multiplier&&(e.multiplier=1),Qt[e.architecture].indexOf(e.multiplier)<0)throw new Error("Invalid multiplier "+e.multiplier+". Should be one of "+Qt[e.architecture]+" for architecture "+e.architecture+".");if(null==e.quantBytes&&(e.quantBytes=4),Gt.indexOf(e.quantBytes)<0)throw new Error("Invalid quantBytes "+e.quantBytes+". Should be one of "+Gt+" for architecture "+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"+u+".json",n=4===l?Se+"float/"+h:Se+"quant"+l+"/"+h,[4,(0,o.YL)(e.modelUrl||n)]);case 1:return i=s.sent(),[2,new Te(i,e)];case 2:return r=function(t,e,n){var i={1:"100",.75:"075",.5:"050"},r="model-stride"+t+".json";return 4===n?ke+"float/"+i[e]+"/"+r:ke+"quant"+n+"/"+i[e]+"/"+r}(e.outputStride,e.multiplier,e.quantBytes),[4,(0,o.YL)(e.modelUrl||r)];case 3:return a=s.sent(),[2,new Te(a,e)]}var u,l,h}))}))}function _e(t,e){return l(this,void 0,void 0,(function(){var n,i;return h(this,(function(r){switch(t){case Ft.PoseNet:return[2,Pe(e)];case Ft.BlazePose:if(i=void 0,null!=(n=e)){if("tfjs"===n.runtime)return[2,Pt(e)];if("mediapipe"===n.runtime)return[2,_(e)];i=n.runtime}throw new Error("Expect modelConfig.runtime to be either 'tfjs' or 'mediapipe', but got "+i);case Ft.MoveNet:return[2,jt(e)];default:throw new Error(t+" is not a supported model name.")}}))}))}}}]);