UNPKG

@vladmandic/human

Version:

Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gesture Recognition

100 lines (99 loc) 322 kB
/* Human homepage: <https://github.com/vladmandic/human> author: <https://github.com/vladmandic>' */ "use strict";var Bo=Object.create;var w2=Object.defineProperty;var Ho=Object.getOwnPropertyDescriptor;var Go=Object.getOwnPropertyNames;var Vo=Object.getPrototypeOf,Zo=Object.prototype.hasOwnProperty;var N1=e=>{throw TypeError(e)};var qo=(e,t,n)=>t in e?w2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Xo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Se=(e,t)=>{for(var n in t)w2(e,n,{get:t[n],enumerable:!0})},I1=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Go(t))!Zo.call(e,r)&&r!==n&&w2(e,r,{get:()=>t[r],enumerable:!(o=Ho(t,r))||o.enumerable});return e};var Z=(e,t,n)=>(n=e!=null?Bo(Vo(e)):{},I1(t||!e||!e.__esModule?w2(n,"default",{value:e,enumerable:!0}):n,e)),Uo=e=>I1(w2({},"__esModule",{value:!0}),e);var w=(e,t,n)=>qo(e,typeof t!="symbol"?t+"":t,n),L1=(e,t,n)=>t.has(e)||N1("Cannot "+n);var Y0=(e,t,n)=>(L1(e,t,"read from private field"),n?n.call(e):t.get(e)),ue=(e,t,n)=>t.has(e)?N1("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Me=(e,t,n,o)=>(L1(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var H=Xo((Ra,Kt)=>{"use strict";var Ut=Object.defineProperty,Yo=Object.getOwnPropertyDescriptor,Ko=Object.getOwnPropertyNames,Jo=Object.prototype.hasOwnProperty,Qo=(e,t)=>{for(var n in t)Ut(e,n,{get:t[n],enumerable:!0})},Xt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ko(t))!Jo.call(e,r)&&r!==n&&Ut(e,r,{get:()=>t[r],enumerable:!(o=Yo(t,r))||o.enumerable});return e},_o=(e,t,n)=>(Xt(e,t,"default"),n&&Xt(n,t,"default")),$o=e=>Xt(Ut({},"__esModule",{value:!0}),e),Yt={};Qo(Yt,{version:()=>sr});Kt.exports=$o(Yt);_o(Yt,require("@tensorflow/tfjs-node-gpu"),Kt.exports);var O1="4.22.0",er="4.22.0",tr="4.22.0",nr="4.22.0",or="4.22.0",rr="4.22.0",sr={tfjs:O1,"tfjs-core":O1,"tfjs-converter":er,"tfjs-backend-cpu":tr,"tfjs-backend-webgl":nr,"tfjs-backend-wasm":or,"tfjs-backend-webgpu":rr}});var Ta={};Se(Ta,{Env:()=>E2,Human:()=>w1,default:()=>w1,defaults:()=>Ke,draw:()=>nt,empty:()=>ve,env:()=>R,match:()=>Ot,models:()=>k1});module.exports=Uo(Ta);var de=Z(H());function b(...e){let t=new Date,n=`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`;e&&console.log(n,"Human:",...e)}function C1(e,t){let n=e.endsWith("/")?"":"/",r=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!r.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${r}`);return r}var v=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function Jt(e,t,n="config",o=[]){for(let r of Object.keys(t))if(typeof t[r]=="object")Jt(e[r],t[r],r,o);else{let s=e&&typeof e[r]!="undefined";s||o.push({reason:"unknown property",where:`${n}.${r} = ${t[r]}`});let A=e&&typeof e[r]==typeof t[r];s&&!A&&o.push({reason:"property type mismatch",where:`${n}.${r} = ${t[r]}`,expected:typeof e[r]})}return t.debug&&n==="config"&&o.length>0&&b("invalid configuration",o),o}function i0(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(r=>{let s=n[r],A=o[r];Array.isArray(s)&&Array.isArray(A)?n[r]=s.concat(...A):t(s)&&t(A)?n[r]=i0(s,A):n[r]=A}),n),{})}var Ke={backend:"",modelBasePath:"",cacheModels:!0,validateModels:!0,wasmPath:"",wasmPlatformFetch:!1,debug:!1,async:!0,warmup:"full",cacheSensitivity:.7,skipAllowed:!1,deallocate:!1,flags:{},softwareKernels:!1,filter:{enabled:!0,equalization:!1,width:0,height:0,flip:!1,return:!0,autoBrightness:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"blazeface.json",rotation:!1,maxDetected:1,skipFrames:99,skipTime:2500,minConfidence:.2,minSize:0,iouThreshold:.1,scale:1.4,mask:!1,return:!1},mesh:{enabled:!0,modelPath:"facemesh.json",keepInvalid:!1},attention:{enabled:!1,modelPath:"facemesh-attention.json"},iris:{enabled:!0,scale:2.3,modelPath:"iris.json"},emotion:{enabled:!0,minConfidence:.1,skipFrames:99,skipTime:1500,modelPath:"emotion.json"},description:{enabled:!0,modelPath:"faceres.json",skipFrames:99,skipTime:3e3,minConfidence:.1},antispoof:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"antispoof.json"},liveness:{enabled:!1,skipFrames:99,skipTime:4e3,modelPath:"liveness.json"}},body:{enabled:!0,modelPath:"movenet-lightning.json",maxDetected:-1,minConfidence:.3,skipFrames:1,skipTime:200},hand:{enabled:!0,rotation:!0,skipFrames:99,skipTime:1e3,minConfidence:.5,iouThreshold:.2,maxDetected:-1,landmarks:!0,detector:{modelPath:"handtrack.json"},skeleton:{modelPath:"handlandmark-lite.json"}},object:{enabled:!1,modelPath:"centernet.json",minConfidence:.2,iouThreshold:.4,maxDetected:10,skipFrames:99,skipTime:2e3},segmentation:{enabled:!1,modelPath:"rvm.json",ratio:.5,mode:"default"}};var W0=Z(H());var I=Z(H());var W1=` precision highp float; attribute vec2 pos; attribute vec2 uv; varying vec2 vUv; uniform float flipY; void main(void) { vUv = uv; gl_Position = vec4(pos.x, pos.y*flipY, 0.0, 1.); } `;var D1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; uniform float m[20]; void main(void) { vec4 c = texture2D(texture, vUv); gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4]; gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9]; gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14]; gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19]; } `,F1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; uniform float m[20]; void main(void) { vec4 c = texture2D(texture, vUv); gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4]; gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9]; gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14]; gl_FragColor.a = c.a; } `,B1=` precision highp float; varying vec2 vUv; uniform vec2 size; uniform sampler2D texture; vec2 pixelate(vec2 coord, vec2 size) { return floor( coord / size ) * size; } void main(void) { gl_FragColor = vec4(0.0); vec2 coord = pixelate(vUv, size); gl_FragColor += texture2D(texture, coord); } `,H1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; uniform vec2 px; void main(void) { gl_FragColor = vec4(0.0); gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265; gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794; gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053; gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718; gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933; gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105; gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121; gl_FragColor += texture2D(texture, vUv )*0.159576912161; gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121; gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105; gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933; gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718; gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053; gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794; gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265; } `,G1=` precision highp float; varying vec2 vUv; uniform sampler2D texture; uniform vec2 px; uniform float m[9]; void main(void) { vec4 c11 = texture2D(texture, vUv - px); // top left vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y)); // top center vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y)); // top right vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) ); // mid left vec4 c22 = texture2D(texture, vUv); // mid center vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) ); // mid right vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) ); // bottom left vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) ); // bottom center vec4 c33 = texture2D(texture, vUv + px ); // bottom right gl_FragColor = c11 * m[0] + c12 * m[1] + c22 * m[2] + c21 * m[3] + c22 * m[4] + c23 * m[5] + c31 * m[6] + c32 * m[7] + c33 * m[8]; gl_FragColor.a = c22.a; } `;var Qt=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(r,s)=>(n[s]=0,r))},_t=class{constructor(t,n,o){w(this,"uniform",{});w(this,"attribute",{});w(this,"gl");w(this,"id");w(this,"compile",(t,n)=>{let o=this.gl.createShader(n);return o?(this.gl.shaderSource(o,t),this.gl.compileShader(o),this.gl.getShaderParameter(o,this.gl.COMPILE_STATUS)?o:(b(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(b("filter: could not create shader"),null)});this.gl=t;let r=this.compile(n,this.gl.VERTEX_SHADER),s=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!r||!s)){if(!this.id){b("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,r),this.gl.attachShader(this.id,s),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){b(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),Qt(n,"attribute",this.attribute);for(let A in this.attribute)this.attribute[A]=this.gl.getAttribLocation(this.id,A);Qt(n,"uniform",this.uniform),Qt(o,"uniform",this.uniform);for(let A in this.uniform)this.uniform[A]=this.gl.getUniformLocation(this.id,A)}}};function V1(){let e=0,t=null,n=!1,o=-1,r=[null,null],s=[],A=null,a=null,l=Ae(100,100),c={},d={INTERMEDIATE:1},i=l.getContext("webgl");if(!i){b("filter: cannot get webgl context");return}this.gl=i;function y(g,p){if(!(g===l.width&&p===l.height)){if(l.width=g,l.height=p,!A){let u=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,-1,1,0,0,1,-1,1,1,1,1,1,0]);A=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,A),i.bufferData(i.ARRAY_BUFFER,u,i.STATIC_DRAW),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}i.viewport(0,0,l.width,l.height),r=[null,null]}}function x(g,p){let u=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,u);let k=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,k);let P=i.createTexture();return i.bindTexture(i.TEXTURE_2D,P),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,g,p,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,P,0),i.bindTexture(i.TEXTURE_2D,null),i.bindFramebuffer(i.FRAMEBUFFER,null),{fbo:u,texture:P}}function m(g){return r[g]=r[g]||x(l.width,l.height),r[g]}function f(g=0){if(!a)return;let p=null,u=null,k=!1;e===0?p=t:p=m(o).texture||null,e++,n&&!(g&d.INTERMEDIATE)?(u=null,k=e%2===0):(o=(o+1)%2,u=m(o).fbo||null),i.bindTexture(i.TEXTURE_2D,p),i.bindFramebuffer(i.FRAMEBUFFER,u),i.uniform1f(a.uniform.flipY,k?-1:1),i.drawArrays(i.TRIANGLES,0,6)}function h(g){if(c[g])return a=c[g],i.useProgram((a?a.id:null)||null),a;if(a=new _t(i,W1,g),!a)return b("filter: could not get webgl program"),null;let p=Float32Array.BYTES_PER_ELEMENT,u=4*p;return i.enableVertexAttribArray(a.attribute.pos),i.vertexAttribPointer(a.attribute.pos,2,i.FLOAT,!1,u,0*p),i.enableVertexAttribArray(a.attribute.uv),i.vertexAttribPointer(a.attribute.uv,2,i.FLOAT,!1,u,2*p),c[g]=a,a}let T={colorMatrix:g=>{let p=new Float32Array(g);p[4]/=255,p[9]/=255,p[14]/=255,p[19]/=255;let u=p[18]===1&&p[3]===0&&p[8]===0&&p[13]===0&&p[15]===0&&p[16]===0&&p[17]===0&&p[19]===0?F1:D1,k=h(u);k&&(i.uniform1fv(k.uniform.m,p),f())},brightness:g=>{let p=(g||0)+1;T.colorMatrix([p,0,0,0,0,0,p,0,0,0,0,0,p,0,0,0,0,0,1,0])},saturation:g=>{let p=(g||0)*2/3+1,u=(p-1)*-.5;T.colorMatrix([p,u,u,0,0,u,p,u,0,0,u,u,p,0,0,0,0,0,1,0])},desaturate:()=>{T.saturation(-1)},contrast:g=>{let p=(g||0)+1,u=-128*(p-1);T.colorMatrix([p,0,0,0,u,0,p,0,0,u,0,0,p,0,u,0,0,0,1,0])},negative:()=>{T.contrast(-2)},hue:g=>{g=(g||0)/180*Math.PI;let p=Math.cos(g),u=Math.sin(g),k=.213,P=.715,N=.072;T.colorMatrix([k+p*(1-k)+u*-k,P+p*-P+u*-P,N+p*-N+u*(1-N),0,0,k+p*-k+u*.143,P+p*(1-P)+u*.14,N+p*-N+u*-.283,0,0,k+p*-k+u*-(1-k),P+p*-P+u*P,N+p*(1-N)+u*N,0,0,0,0,0,1,0])},desaturateLuminance:()=>{T.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},sepia:()=>{T.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{T.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},vintagePinhole:()=>{T.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},kodachrome:()=>{T.colorMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0])},technicolor:()=>{T.colorMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0])},polaroid:()=>{T.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},shiftToBGR:()=>{T.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:g=>{let p=new Float32Array(g),u=1/l.width,k=1/l.height,P=h(G1);P&&(i.uniform1fv(P.uniform.m,p),i.uniform2f(P.uniform.px,u,k),f())},detectEdges:()=>{T.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{T.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{T.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:g=>{let p=g||1;T.convolution.call(this,[0,-1*p,0,-1*p,1+4*p,-1*p,0,-1*p,0])},emboss:g=>{let p=g||1;T.convolution.call(this,[-2*p,-1*p,0,-1*p,1,1*p,0,1*p,2*p])},blur:g=>{let p=g/7/l.width,u=g/7/l.height,k=h(H1);k&&(i.uniform2f(k.uniform.px,0,u),f(d.INTERMEDIATE),i.uniform2f(k.uniform.px,p,0),f())},pixelate:g=>{let p=g/l.width,u=g/l.height,k=h(B1);k&&(i.uniform2f(k.uniform.size,p,u),f())}};this.add=function(g){let p=Array.prototype.slice.call(arguments,1),u=T[g];s.push({func:u,args:p})},this.reset=function(){s=[]},this.get=function(){return s},this.apply=function(g){y(g.width,g.height),e=0,t||(t=i.createTexture()),i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,g);for(let p=0;p<s.length;p++){n=p===s.length-1;let u=s[p];u.func.apply(this,u.args||[])}return l},this.draw=function(g){return this.add("brightness",0),this.apply(g)}}var U=Z(H());async function Z2(e){let t=e.shape.length===4?U.squeeze(e):e,n=U.split(t,3,2),o=[U.min(n[0]),U.min(n[1]),U.min(n[2])],r=[U.max(n[0]),U.max(n[1]),U.max(n[2])],s=await Promise.all(r.map(d=>d.data())),A=Math.max(s[0][0],s[1][0],s[2][0]),l=(A>1?255:1)/A,c;if(l>1){let d=[U.sub(n[0],o[0]),U.sub(n[1],o[1]),U.sub(n[2],o[2])],i=[U.sub(r[0],o[0]),U.sub(r[1],o[1]),U.sub(r[2],o[2])],y=[U.mul(d[0],l),U.mul(d[1],l),U.mul(d[2],l)],x=U.stack([y[0],y[1],y[2]],2);c=U.reshape(x,[1,t.shape[0]||0,t.shape[1]||0,3]),U.dispose([...d,...i,...y,x])}else c=U.expandDims(t,0);return U.dispose([...n,...o,...r,n,t,e]),c}var q2=3840,M0=null,P0=null,y2=null,t0,ne={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function $t(){ne.inputSum=0,ne.cacheDiff=1,ne.sumMethod=0,ne.inputTensor=void 0}function Ae(e,t){let n;if(R.browser)if(R.worker){if(typeof OffscreenCanvas=="undefined")throw new Error("canvas error: attempted to run in web worker but OffscreenCanvas is not supported");n=new OffscreenCanvas(e,t)}else if(typeof document!="undefined")n=document.createElement("canvas"),n.width=e,n.height=t;else if(typeof navigator!="undefined"&&navigator.product==="ReactNative")if(typeof R.Canvas!="undefined")n=new R.Canvas(e,t);else if(typeof globalThis.Canvas!="undefined")n=new globalThis.Canvas(e,t);else throw new Error("canvas error: attempted to use canvas in react-native without canvas support installed");else throw new Error("canvas error: attempted to run in browser but DOM is not defined");else typeof R.Canvas!="undefined"?n=new R.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function X2(e,t){let n=t||Ae(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function U2(e,t,n=!0){var y,x,m;if(!e)return t.debug&&b("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof I.Tensor)&&!(typeof Image!="undefined"&&e instanceof Image)&&!(typeof globalThis.Canvas!="undefined"&&e instanceof globalThis.Canvas)&&!(typeof ImageData!="undefined"&&e instanceof ImageData)&&!(typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap)&&!(typeof HTMLImageElement!="undefined"&&e instanceof HTMLImageElement)&&!(typeof HTMLMediaElement!="undefined"&&e instanceof HTMLMediaElement)&&!(typeof HTMLVideoElement!="undefined"&&e instanceof HTMLVideoElement)&&!(typeof HTMLCanvasElement!="undefined"&&e instanceof HTMLCanvasElement)&&!(typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas))throw new Error("input error: type not recognized");if(e instanceof I.Tensor){let f=null;if(e.isDisposedInternal)throw new Error("input error: attempted to use tensor but it is disposed");if(!e.shape)throw new Error("input error: attempted to use tensor without a shape");if(e.shape.length===3){if(e.shape[2]===3)f=I.expandDims(e,0);else if(e.shape[2]===4){let h=I.slice3d(e,[0,0,0],[-1,-1,3]);f=I.expandDims(h,0),I.dispose(h)}}else e.shape.length===4&&(e.shape[3]===3?f=I.clone(e):e.shape[3]===4&&(f=I.slice4d(e,[0,0,0,0],[-1,-1,-1,3])));if(f==null||f.shape.length!==4||f.shape[0]!==1||f.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${e.shape.toString()}`);if(f.dtype==="int32"){let h=I.cast(f,"float32");I.dispose(f),f=h}return{tensor:f,canvas:t.filter.return?P0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&b("input stream is not ready"),{tensor:null,canvas:M0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,r=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!r)return t.debug&&b("cannot determine input dimensions"),{tensor:null,canvas:M0};let s=o,A=r;if(s>q2&&(s=q2,A=Math.trunc(s*r/o)),A>q2&&(A=q2,s=Math.trunc(A*o/r)),(((y=t.filter)==null?void 0:y.width)||0)>0?s=t.filter.width:(((x=t.filter)==null?void 0:x.height)||0)>0&&(s=o*((t.filter.height||0)/r)),(t.filter.height||0)>0?A=t.filter.height:(t.filter.width||0)>0&&(A=r*((t.filter.width||0)/o)),!s||!A)throw new Error("input error: cannot determine dimension");(!M0||M0.width!==s||M0.height!==A)&&(M0=Ae(s,A));let a=M0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?a.putImageData(e,0,0):t.filter.flip&&typeof a.translate!="undefined"?(a.translate(o,0),a.scale(-1,1),a.drawImage(e,0,0,o,r,0,0,M0.width,M0.height),a.setTransform(1,0,0,1,0,0)):a.drawImage(e,0,0,o,r,0,0,M0.width,M0.height),(!P0||M0.width!==P0.width||M0.height!==P0.height)&&(P0=Ae(M0.width,M0.height)),t.filter.enabled&&R.webgl.supported?(t0||(t0=R.browser?new V1:null),R.filter=!!t0,t0!=null&&t0.add?(t0.reset(),t.filter.brightness!==0&&t0.add("brightness",t.filter.brightness),t.filter.contrast!==0&&t0.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&t0.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&t0.add("blur",t.filter.blur),t.filter.saturation!==0&&t0.add("saturation",t.filter.saturation),t.filter.hue!==0&&t0.add("hue",t.filter.hue),t.filter.negative&&t0.add("negative"),t.filter.sepia&&t0.add("sepia"),t.filter.vintage&&t0.add("brownie"),t.filter.sepia&&t0.add("sepia"),t.filter.kodachrome&&t0.add("kodachrome"),t.filter.technicolor&&t0.add("technicolor"),t.filter.polaroid&&t0.add("polaroid"),t.filter.pixelate!==0&&t0.add("pixelate",t.filter.pixelate),((m=t0.get())==null?void 0:m.length)>1?P0=t0.apply(M0):P0=t0.draw(M0)):(t.debug&&b("input process error: cannot initialize filters"),R.webgl.supported=!1,t.filter.enabled=!1,X2(M0,P0))):(X2(M0,P0),t0&&(t0=null),R.filter=!!t0),!n)return{tensor:null,canvas:P0};if(!P0)throw new Error("canvas error: cannot create output");let l,c=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(R.browser&&I.browser)l=I.browser?I.browser.fromPixels(e):null;else{c=e.data.length/e.height/e.width;let f=new Uint8Array(e.data.buffer);l=I.tensor(f,[e.height,e.width,c],"int32")}else if((!y2||P0.width!==y2.width||P0.height!==y2.height)&&(y2=Ae(P0.width,P0.height)),I.browser&&R.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?l=I.browser.fromPixels(P0):(y2=X2(P0),l=I.browser.fromPixels(y2));else{let T=X2(P0).getContext("2d").getImageData(0,0,s,A);c=T.data.length/s/A;let g=new Uint8Array(T.data.buffer);l=I.tensor(g,[s,A,c])}if(c===4){let f=I.slice3d(l,[0,0,0],[-1,-1,3]);I.dispose(l),l=f}if(!l)throw new Error("input error: cannot create tensor");let d=I.cast(l,"float32"),i=t.filter.equalization?await Z2(d):I.expandDims(d,0);if(I.dispose([l,d]),t.filter.autoBrightness){let f=I.max(i),h=await f.data();t.filter.brightness=h[0]>1?1-h[0]/255:1-h[0],I.dispose(f)}return{tensor:i,canvas:t.filter.return?P0:null}}async function Z1(e,t){let n=!1;if(e.cacheSensitivity===0||!t.shape||t.shape.length!==4||t.shape[1]>3840||t.shape[2]>2160)return n;if(!ne.inputTensor)ne.inputTensor=I.clone(t);else if(ne.inputTensor.shape[1]!==t.shape[1]||ne.inputTensor.shape[2]!==t.shape[2])I.dispose(ne.inputTensor),ne.inputTensor=I.clone(t);else{let o={};o.diff=I.sub(t,ne.inputTensor),o.squared=I.mul(o.diff,o.diff),o.sum=I.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;I.dispose([ne.inputTensor,o.diff,o.squared,o.sum]),ne.inputTensor=I.clone(t),n=s<=(e.cacheSensitivity||0)}return n}async function q1(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||b("invalid input tensor or tensor shapes do not match:",t.shape,n.shape),0;if(t.shape[0]!==1||n.shape[0]!==1||t.shape[3]!==3||n.shape[3]!==3)return e.debug||b("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=I.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?I.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):I.clone(n),o.diff=I.sub(o.input1,o.input2),o.squared=I.mul(o.diff,o.diff),o.sum=I.sum(o.squared);let s=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return I.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),s}var z2,S2,j2,E2=class{constructor(){w(this,"browser");w(this,"node");w(this,"worker");w(this,"platform","");w(this,"agent","");w(this,"backends",[]);w(this,"initial");w(this,"filter");w(this,"tfjs");w(this,"offscreen");w(this,"perfadd",!1);w(this,"tensorflow",{version:void 0,gpu:void 0});w(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});w(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});w(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});w(this,"cpu",{model:void 0,flags:[]});w(this,"kernels",[]);ue(this,z2);ue(this,S2);ue(this,j2);if(this.browser=typeof navigator!="undefined"&&typeof navigator.appVersion!="undefined",this.node=typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof process.versions.node!="undefined",this.tfjs={version:W0.version["tfjs-core"]},this.offscreen=typeof OffscreenCanvas!="undefined",this.initial=!0,this.worker=this.browser&&this.offscreen?typeof WorkerGlobalScope!="undefined":void 0,typeof navigator!="undefined"&&typeof navigator.userAgent!="undefined"){let t=navigator.userAgent||"",n=t.match(/\(([^()]+)\)/g);if(n!=null&&n[0]){let o=n[0].match(/\(([^()]+)\)/g);this.platform=o!=null&&o[0]?o[0].replace(/\(|\)/g,""):"",this.agent=t.replace(n[0],""),this.platform[1]&&(this.agent=this.agent.replace(n[1],"")),this.agent=this.agent.replace(/ /g," ")}}else typeof process!="undefined"&&(this.platform=`${process.platform} ${process.arch}`,this.agent=`NodeJS ${process.version}`)}get Canvas(){return Y0(this,z2)}set Canvas(t){Me(this,z2,t),globalThis.Canvas=t}get Image(){return Y0(this,S2)}set Image(t){Me(this,S2,t),globalThis.Image=t}get ImageData(){return Y0(this,j2)}set ImageData(t){Me(this,j2,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(W0.engine().registryFactory);try{this.tensorflow={version:W0.backend().binding?W0.backend().binding.TF_Version:void 0,gpu:W0.backend().binding?W0.backend().binding.isUsingGpuDevice():void 0}}catch(o){}this.wasm.supported=typeof WebAssembly!="undefined",this.wasm.backend=this.backends.includes("wasm"),this.wasm.supported&&this.wasm.backend&&(this.wasm.simd=await W0.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await W0.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=Ae(100,100),n=t?t.getContext("webgl2"):void 0;this.webgl.supported=typeof n!="undefined",this.webgl.backend=this.backends.includes("webgl"),this.webgl.supported&&this.webgl.backend&&n&&(this.webgl.version=n.getParameter(n.VERSION),this.webgl.vendor=n.getParameter(n.VENDOR),this.webgl.renderer=n.getParameter(n.RENDERER),this.webgl.shader=n.getParameter(n.SHADING_LANGUAGE_VERSION)),this.webgpu.supported=this.browser&&typeof navigator!="undefined"&&typeof navigator.gpu!="undefined",this.webgpu.backend=this.backends.includes("webgpu");try{if(this.webgpu.supported){let o=await navigator.gpu.requestAdapter();o&&("requestAdapterInfo"in o?this.webgpu.adapter=await o.requestAdapterInfo():this.webgpu.adapter=await o.info)}}catch(o){this.webgpu.supported=!1}try{this.kernels=W0.getKernelsForBackend(W0.getBackend()).map(o=>o.kernelName.toLowerCase())}catch(o){}}updateCPU(){let t={model:"",flags:[]};this.node&&this.platform.startsWith("linux"),this.cpu?this.cpu=t:Object.defineProperty(this,"cpu",{value:t})}};z2=new WeakMap,S2=new WeakMap,j2=new WeakMap;var R=new E2;var K2=class{constructor(){w(this,"config");w(this,"element");w(this,"stream");w(this,"devices",[]);w(this,"enumerate",async()=>{try{let t=await navigator.mediaDevices.enumerateDevices();this.devices=t.filter(n=>n.kind==="videoinput")}catch(t){this.devices=[]}return this.devices});w(this,"start",async t=>{var r,s;if(t!=null&&t.debug&&(this.config.debug=t==null?void 0:t.debug),t!=null&&t.crop&&(this.config.crop=t==null?void 0:t.crop),t!=null&&t.mode&&(this.config.mode=t==null?void 0:t.mode),t!=null&&t.width&&(this.config.width=t==null?void 0:t.width),t!=null&&t.height&&(this.config.height=t==null?void 0:t.height),t!=null&&t.id&&(this.config.id=t==null?void 0:t.id),t!=null&&t.element)if(typeof t.element=="string"){let A=document.getElementById(t.element);if(A&&A instanceof HTMLVideoElement)this.element=A;else return this.config.debug&&b("webcam","cannot get dom element",t.element),`webcam error: cannot get dom element: ${t.element}`}else if(t.element instanceof HTMLVideoElement)this.element=t.element;else return this.config.debug&&b("webcam","unknown dom element",t.element),`webcam error: unknown dom element: ${t.element}`;else this.element=document.createElement("video");let n={audio:!1,video:{facingMode:this.config.mode==="front"?"user":"environment",resizeMode:this.config.crop?"crop-and-scale":"none"}};if(((r=this.config)==null?void 0:r.width)>0&&(n.video.width={ideal:this.config.width}),((s=this.config)==null?void 0:s.height)>0&&(n.video.height={ideal:this.config.height}),this.config.id&&(n.video.deviceId=this.config.id),this.element.addEventListener("play",()=>{this.config.debug&&b("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&b("webcam","pause")}),this.element.addEventListener("click",async()=>{!this.element||!this.stream||(this.element.paused?await this.element.play():this.element.pause())}),!(navigator!=null&&navigator.mediaDevices))return this.config.debug&&b("webcam error","no devices"),"webcam error: no devices";try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(A){return b("webcam",A),`webcam error: ${A}`}return this.stream?(this.element.srcObject=this.stream,await new Promise(A=>{this.element?this.element.onloadeddata=()=>A(!0):A(!1)}),await this.element.play(),this.config.debug&&b("webcam",{width:this.width,height:this.height,label:this.label,stream:this.stream,track:this.track,settings:this.settings,constraints:this.constraints,capabilities:this.capabilities}),`webcam: ${this.label}`):(this.config.debug&&b("webcam error","no stream"),"webcam error no stream")});w(this,"pause",()=>{this.element&&this.element.pause()});w(this,"play",async()=>{this.element&&await this.element.play()});w(this,"stop",()=>{this.config.debug&&b("webcam","stop"),this.track&&this.track.stop()});this.config={element:void 0,debug:!0,mode:"front",crop:!1,width:0,height:0}}get track(){if(this.stream)return this.stream.getVideoTracks()[0]}get capabilities(){if(this.track)return this.track.getCapabilities?this.track.getCapabilities():void 0}get constraints(){if(this.track)return this.track.getConstraints?this.track.getConstraints():void 0}get settings(){if(!this.stream)return;let t=this.stream.getVideoTracks()[0];return t.getSettings?t.getSettings():void 0}get label(){return this.track?this.track.label:""}get paused(){var t;return((t=this.element)==null?void 0:t.paused)||!1}get width(){var t;return((t=this.element)==null?void 0:t.videoWidth)||0}get height(){var t;return((t=this.element)==null?void 0:t.videoHeight)||0}};var f2=Z(H());var e5={};Se(e5,{"affectnet-mobilenet":()=>Tr,age:()=>vr,"anti-spoofing":()=>es,antispoof:()=>lr,blazeface:()=>cr,"blazeface-back":()=>Rr,"blazeface-front":()=>Mr,"blazepose-detector":()=>Pr,"blazepose-full":()=>kr,"blazepose-heavy":()=>wr,"blazepose-lite":()=>Er,centernet:()=>dr,default:()=>ys,efficientpose:()=>zr,"efficientpose-i-lite":()=>ts,"efficientpose-ii-lite":()=>ns,"efficientpose-iv":()=>os,emotion:()=>xr,faceboxes:()=>Sr,facemesh:()=>yr,"facemesh-attention":()=>Nr,"facemesh-attention-pinto":()=>jr,"facemesh-detection-full":()=>Ir,"facemesh-detection-short":()=>Lr,faceres:()=>fr,"faceres-deep":()=>Or,gear:()=>Dr,"gear-e1":()=>Cr,"gear-e2":()=>Wr,gender:()=>Br,"gender-ssrnet-imdb":()=>Fr,handdetect:()=>Hr,"handlandmark-full":()=>Gr,"handlandmark-lite":()=>mr,"handlandmark-sparse":()=>Vr,handskeleton:()=>Zr,handtrack:()=>pr,"insightface-efficientnet-b0":()=>rs,"insightface-ghostnet-strides1":()=>ss,"insightface-ghostnet-strides2":()=>As,"insightface-mobilenet-emore":()=>as,"insightface-mobilenet-swish":()=>is,iris:()=>ur,liveness:()=>hr,meet:()=>qr,mobileface:()=>Xr,mobilefacenet:()=>Ur,models:()=>br,"movenet-lightning":()=>gr,"movenet-multipose":()=>Yr,"movenet-thunder":()=>Kr,nanodet:()=>Jr,"nanodet-e":()=>ls,"nanodet-g":()=>cs,"nanodet-m":()=>ds,"nanodet-t":()=>xs,posenet:()=>Qr,rvm:()=>_r,selfie:()=>$r});var lr=853098,cr=538928,dr=4030290,xr=820516,yr=1477958,fr=6978814,mr=2023432,pr=2964837,ur=2599092,hr=592976,br=0,gr=4650216,Tr=6920630,vr=161240,Rr=538928,Mr=402048,Pr=5928856,kr=6339202,wr=27502466,Er=2726402,zr=5651240,Sr=2013002,jr=2387598,Nr=2382414,Ir=1026192,Lr=201268,Or=13957620,Cr=112438,Wr=112438,Dr=1498916,Fr=161236,Br=201808,Hr=3515612,Gr=5431368,Vr=5286322,Zr=5502280,qr=372228,Xr=2183192,Ur=5171976,Yr=9448838,Kr=12477112,Jr=7574558,Qr=5032780,_r=3739355,$r=212886,es=853098,ts=2269064,ns=5651240,os=25643252,rs=13013224,ss=8093408,As=8049584,as=6938536,is=12168584,ls=12319156,cs=7574558,ds=1887474,xs=5294216,ys={antispoof:lr,blazeface:cr,centernet:dr,emotion:xr,facemesh:yr,faceres:fr,"handlandmark-lite":mr,handtrack:pr,iris:ur,liveness:hr,models:br,"movenet-lightning":gr,"affectnet-mobilenet":Tr,age:vr,"blazeface-back":Rr,"blazeface-front":Mr,"blazepose-detector":Pr,"blazepose-full":kr,"blazepose-heavy":wr,"blazepose-lite":Er,efficientpose:zr,faceboxes:Sr,"facemesh-attention-pinto":jr,"facemesh-attention":Nr,"facemesh-detection-full":Ir,"facemesh-detection-short":Lr,"faceres-deep":Or,"gear-e1":Cr,"gear-e2":Wr,gear:Dr,"gender-ssrnet-imdb":Fr,gender:Br,handdetect:Hr,"handlandmark-full":Gr,"handlandmark-sparse":Vr,handskeleton:Zr,meet:qr,mobileface:Xr,mobilefacenet:Ur,"movenet-multipose":Yr,"movenet-thunder":Kr,nanodet:Jr,posenet:Qr,rvm:_r,selfie:$r,"anti-spoofing":es,"efficientpose-i-lite":ts,"efficientpose-ii-lite":ns,"efficientpose-iv":os,"insightface-efficientnet-b0":rs,"insightface-ghostnet-strides1":ss,"insightface-ghostnet-strides2":As,"insightface-mobilenet-emore":as,"insightface-mobilenet-swish":is,"nanodet-e":ls,"nanodet-g":cs,"nanodet-m":ds,"nanodet-t":xs};var D0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},v0={};async function fs(e,t){return D0.debug&&b("load model fetch:",e,t),fetch(e,t)}function X1(e){D0.cacheModels=e.cacheModels,D0.verbose=e.debug,D0.modelBasePath=e.modelBasePath}async function O(e){var l,c,d,i,y,x;let t=C1(D0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),r="indexeddb://"+o;v0[o]={name:o,loaded:!1,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:e5[o],inCache:!1,url:""},D0.cacheSupported=typeof indexedDB!="undefined";let s={};try{s=D0.cacheSupported&&D0.cacheModels?await f2.io.listModels():{}}catch(m){D0.cacheSupported=!1}v0[o].inCache=D0.cacheSupported&&D0.cacheModels&&Object.keys(s).includes(r),v0[o].url=v0[o].inCache?r:t;let A=typeof fetch=="undefined"?{}:{fetchFunc:(m,f)=>fs(m,f)},a=new f2.GraphModel(v0[o].url,A);v0[o].loaded=!1;try{a.findIOHandler(),D0.debug&&b("model load handler:",a.handler)}catch(m){b("error finding model i/o handler:",t,m)}try{let m=await((l=a.handler)==null?void 0:l.load())||null;v0[o].sizeFromManifest=((c=m==null?void 0:m.weightData)==null?void 0:c.byteLength)||0,m?a.loadSync(m):a=await f2.loadGraphModel(v0[o].inCache?r:t,A),v0[o].sizeLoadedWeights=((i=(d=a.artifacts)==null?void 0:d.weightData)==null?void 0:i.byteLength)||((x=(y=a.artifacts)==null?void 0:y.weightData)==null?void 0:x[0].byteLength)||0,D0.verbose&&b("load:",{model:o,url:a.modelUrl,bytes:v0[o].sizeLoadedWeights}),v0[o].loaded=!0}catch(m){b("error loading model:",t,m)}if(v0[o].loaded&&D0.cacheModels&&D0.cacheSupported&&!v0[o].inCache)try{let m=await a.save(r);D0.debug&&b("model saved:",r,m)}catch(m){b("error saving model:",t,m)}return a}var t5="3.3.5";var S=Z(H());var u0=Z(H());var r0={name:"humangl",priority:999,canvas:null,gl:null,extensions:[],webGLattr:{alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!1,desynchronized:!0}};function us(){let e=r0.gl;e&&(r0.extensions=e.getSupportedExtensions())}function U1(e){var t;if(e.config.backend==="humangl"&&(r0.name in u0.engine().registry&&!((t=r0==null?void 0:r0.gl)!=null&&t.getParameter(r0.gl.VERSION))&&(b("humangl error: backend invalid context"),e.models.reset()),!u0.findBackend(r0.name))){try{r0.canvas=Ae(100,100)}catch(r){b("humangl error: cannot create canvas:",r);return}try{if(r0.gl=r0.canvas.getContext("webgl2",r0.webGLattr),!r0.gl){b("humangl error: cannot get webgl context");return}if(!r0.gl.getParameter(r0.gl.VERSION).includes("2.0")){b("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}r0.canvas&&(r0.canvas.addEventListener("webglcontextlost",s=>{throw b("humangl error:",s.type),b("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),r0.canvas.addEventListener("webglcontextrestored",s=>{b("humangl error: context restored:",s)}),r0.canvas.addEventListener("webglcontextcreationerror",s=>{b("humangl error: context create:",s)}))}catch(r){b("humangl error: cannot get webgl context:",r);return}try{u0.setWebGLContext(2,r0.gl)}catch(r){b("humangl error: cannot set webgl context:",r);return}try{let r=new u0.GPGPUContext(r0.gl);u0.registerBackend(r0.name,()=>new u0.MathBackendWebGL(r),r0.priority)}catch(r){b("humangl error: cannot register webgl backend:",r);return}try{u0.getKernelsForBackend("webgl").forEach(s=>{let A={...s,backendName:r0.name};u0.registerKernel(A)})}catch(r){b("humangl error: cannot update webgl backend registration:",r);return}try{u0.env().flagRegistry.WEBGL_VERSION&&u0.env().set("WEBGL_VERSION",2)}catch(r){b("humangl error: cannot set WebGL backend flags:",r);return}us();let n=u0.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&b("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):b("humangl error: no current gl context:",o,r0.gl)}}var je=Z(H()),C={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function Y1(){C.tf255=je.scalar(255,"float32"),C.tf1=je.scalar(1,"float32"),C.tf2=je.scalar(2,"float32"),C.tf05=je.scalar(.5,"float32"),C.tf127=je.scalar(127.5,"float32"),C.rgb=je.tensor1d([.2989,.587,.114],"float32")}async function gs(){var e;return await R.updateBackend(),(e=R.tensorflow)!=null&&e.version?"tensorflow":R.webgpu.supported&&R.webgpu.backend?"webgpu":R.webgl.supported&&R.webgl.backend?"webgl":R.wasm.supported&&R.wasm.backend?"wasm":"cpu"}function Ts(e){let t=[];if(!R.kernels.includes("mod")){let n={kernelName:"Mod",backendName:S.getBackend(),kernelFunc:o=>S.tidy(()=>S.sub(o.inputs.a,S.mul(S.div(o.inputs.a,o.inputs.b),o.inputs.b)))};S.registerKernel(n),R.kernels.push("mod"),t.push("mod")}if(!R.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:S.getBackend(),kernelFunc:o=>S.tidy(()=>S.add(S.mul(S.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),S.mod(o.inputs.a,o.inputs.b)))};S.registerKernel(n),R.kernels.push("floormod"),t.push("floormod")}if(!R.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:S.getBackend(),kernelFunc:o=>S.tidy(()=>{let r=S.getBackend();S.setBackend("cpu");let s=S.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return S.setBackend(r),s})};S.registerKernel(n),R.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&b("registered kernels:",t)}var K1={};async function N2(e,t=!1){var n,o;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await gs()),t||R.initial||e.config.backend&&e.config.backend.length>0&&S.getBackend()!==e.config.backend){let r=v();if(e.config.backend&&e.config.backend.length>0){typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&b("running inside web worker"),typeof navigator!="undefined"&&((o=navigator==null?void 0:navigator.userAgent)!=null&&o.toLowerCase().includes("electron"))&&e.config.debug&&b("running inside electron");let s=Object.keys(S.engine().registryFactory);if(e.config.backend==="humangl"&&!s.includes("humangl")&&(U1(e),s=Object.keys(S.engine().registryFactory)),e.config.debug&&b("available backends:",s),R.browser&&!R.node&&e.config.backend==="tensorflow"&&s.includes("webgl")&&(e.config.debug&&b("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),R.node&&!R.browser&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&s.includes("tensorflow")&&(e.config.debug&&b(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),R.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")b("override: backend set to webgpu but browser does not support webgpu"),e.config.backend="webgl";else{let A=await navigator.gpu.requestAdapter();if(e.config.debug&&b("enumerated webgpu adapter:",A),!A)b("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let a;"requestAdapterInfo"in A?a=await(A==null?void 0:A.requestAdapterInfo()):a=A.info,b("webgpu adapter info:",a)}}if(s.includes(e.config.backend)||(b(`error: backend ${e.config.backend} not found in registry`),e.config.backend=R.node?"tensorflow":"webgl",e.config.debug&&b(`override: setting backend ${e.config.backend}`)),e.config.debug&&b("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(S.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&S.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&b("wasm path:",e.config.wasmPath),typeof S.setWasmPaths!="undefined")S.setWasmPaths(e.config.wasmPath,e.config.wasmPlatformFetch);else throw new Error("backend error: attempting to use wasm backend but wasm path is not set");let A=!1,a=!1;try{A=await S.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),a=await S.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&b(`wasm execution: ${a?"simd":"no simd"} ${A?"multithreaded":"singlethreaded"}`),e.config.debug&&!a&&b("warning: wasm simd support is not enabled")}catch(l){b("wasm detection failed")}}try{await S.setBackend(e.config.backend),await S.ready()}catch(A){return b("error: cannot set backend:",e.config.backend,A),!1}e.config.debug&&(K1=JSON.parse(JSON.stringify(S.env().flags)))}if((S.getBackend()==="humangl"||S.getBackend()==="webgl")&&(S.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&S.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),S.env().flagRegistry.WEBGL_EXP_CONV&&S.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(b("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),S.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),S.getBackend(),e.config.debug){let s=S.env().flags,A={};for(let a of Object.keys(s))K1[a]!==s[a]&&(A[a]=s[a]);e.config.debug&&Object.keys(A).length>0&&b("backend:",S.getBackend(),"flags:",A)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&b("flags:",e.config.flags);for(let[s,A]of Object.entries(e.config.flags))S.env().set(s,A)}S.enableProdMode(),Y1(),e.performance.initBackend=Math.trunc(v()-r),e.config.backend=S.getBackend(),await R.updateBackend(),Ts(e.config)}return!0}function J2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:r=>{var s;return t.debug&&b("kernelFunc",n,t.backend,r),(s=r==null?void 0:r.inputs)==null?void 0:s.info}};S.registerKernel(o)}R.kernels=S.getKernelsForBackend(S.getBackend()).map(n=>n.kernelName.toLowerCase())}var nt={};Se(nt,{all:()=>$s,body:()=>_2,canvas:()=>Qs,face:()=>Q2,gesture:()=>tt,hand:()=>$2,init:()=>i5,object:()=>et,options:()=>f0,person:()=>Js,tensor:()=>_s});var $1=Z(H());var oe=e=>{if(!e)b("draw error: invalid canvas");else if(!e.getContext)b("draw error: canvas context not defined");else{let t=e.getContext("2d",{willReadFrequently:!0});if(!t)b("draw error: cannot get canvas context");else return t}return null},Je=e=>Math.round(e*180/Math.PI),Y=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),Qe=(e,t)=>{if(!t.useDepth||typeof e=="undefined")return t.color;let n=Uint8ClampedArray.from([127+2*e,127-2*e,255]);return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t.alpha})`};function re(e,t,n,o,r){let s=t.replace(/\[.*\]/g,"").split(` `).map(a=>a.trim()),A=Math.max(0,n);for(let a=s.length-1;a>=0;a--){let l=a*r.lineHeight+o;r.shadowColor&&r.shadowColor!==""&&(e.fillStyle=r.shadowColor,e.fillText(s[a],A+5,l+16)),e.fillStyle=r.labelColor,e.fillText(s[a],A+4,l+15)}}function he(e,t,n,o,r){e.fillStyle=Qe(o,r),e.beginPath(),e.arc(t,n,r.pointSize,0,2*Math.PI),e.fill()}function be(e,t,n,o,r,s){if(e.beginPath(),e.lineWidth=s.lineWidth,s.useCurves){let A=(t+t+o)/2,a=(n+n+r)/2;e.ellipse(A,a,o/2,r/2,0,0,2*Math.PI)}else e.moveTo(t+s.roundRect,n),e.lineTo(t+o-s.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+s.roundRect),e.lineTo(t+o,n+r-s.roundRect),e.quadraticCurveTo(t+o,n+r,t+o-s.roundRect,n+r),e.lineTo(t+s.roundRect,n+r),e.quadraticCurveTo(t,n+r,t,n+r-s.roundRect),e.lineTo(t,n+s.roundRect),e.quadraticCurveTo(t,n,t+s.roundRect,n),e.closePath();e.stroke()}function n5(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=Qe(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function Q1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){n5(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;o<t.length-2;o++){let r=(t[o][0]+t[o+1][0])/2,s=(t[o][1]+t[o+1][1])/2;e.quadraticCurveTo(t[o][0],t[o][1],r,s)}e.quadraticCurveTo(t[t.length-2][0],t[t.length-2][1],t[t.length-1][0],t[t.length-1][1]),e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function o5(e,t,n,o=5){let r,s,A;e.beginPath(),e.moveTo(t[0],t[1]),e.lineTo(n[0],n[1]),r=Math.atan2(n[1]-t[1],n[0]-t[0]),s=o*Math.cos(r)+n[0],A=o*Math.sin(r)+n[1],e.moveTo(s,A),r+=1/3*(2*Math.PI),s=o*Math.cos(r)+n[0],A=o*Math.sin(r)+n[1],e.lineTo(s,A),r+=1/3*(2*Math.PI),s=o*Math.cos(r)+n[0],A=o*Math.sin(r)+n[1],e.lineTo(s,A),e.closePath(),e.stroke(),e.fill()}var f0={color:"rgba(173, 216, 230, 0.6)",labelColor:"rgba(173, 216, 230, 1)",shadowColor:"black",alpha:.5,font:'small-caps 16px "Segoe UI"',lineHeight:18,lineWidth:4,pointSize:2,roundRect:8,drawPoints:!1,drawLabels:!0,drawBoxes:!0,drawAttention:!0,drawGestures:!0,drawPolygons:!0,drawGaze:!0,fillPolygons:!1,useDepth:!0,useCurves:!1,faceLabels:"",bodyLabels:"",bodyPartLabels:"",objectLabels:"",handLabels:"",fingerLabels:"",gestureLabels:""};var ae={silhouette:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],lipsUpperOuter:[185,40,39,37,0,267,269,270,409],lipsLowerOuter:[61,146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[191,80,81,82,13,312,311,310,415],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],lipsLowerSemiOuter:[76,77,90,180,85,16,315,404,320,307,306],lipsUpperSemiOuter:[184,74,73,72,11,302,303,304,408],lipsLowerSemiInner:[62,96,89,179,86,15,316,403,319,325,292],lipsUpperSemiInner:[183,42,41,38,12,268,271,272,407],rightEyeUpper0:[246,161,160,159,158,157,173],rightEyeLower0:[33,7,163,144,145,153,154,155,133],rightEyeUpper1:[247,30,29,27,28,56,190],rightEyeLower1:[130,25,110,24,23,22,26,112,243],rightEyeUpper2:[113,225,224,223,222,221,189],rightEyeLower2:[226,31,228,229,230,231,232,233,244],rightEyeLower3:[143,111,117,118,119,120,121,128,245],rightEyebrowUpper:[156,70,63,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65],rightEyeIris:[473,474,475,476,477],leftEyeUpper0:[466,388,387,386,385,384,398],leftEyeLower0:[263,249,390,373,374,380,381,382,362],leftEyeUpper1:[467,260,259,257,258,286,414],leftEyeLower1:[359,255,339,254,253,252,256,341,463],leftEyeUpper2:[342,445,444,443,442,441,413],leftEyeLower2:[446,261,448,449,450,451,452,453,464],leftEyeLower3:[372,340,346,347,348,349,350,357,465],leftEyebrowUpper:[383,300,293,334,296,336,285,417],leftEyebrowLower:[265,353,276,283,282,295],leftEyeIris:[468,469,470,471,472],midwayBetweenEyes:[168],noseTip:[1],noseBottom:[2],noseRightCorner:[98],noseLeftCorner:[327],rightCheek:[205],leftCheek:[425]},r5={count:468,mouth:13,symmetryLine:[13,ae.midwayBetweenEyes[0]]},_e={leftEye:0,rightEye:1,nose:2,mouth:3,leftEar:4,rightEar:5,symmetryLine:[3,2]},s5=[{key:"EyeUpper0",indices:[9,10,11,12,13,14,15]},{key:"EyeUpper1",indices:[25,26,27,28,29,30,31]},{key:"EyeUpper2",indices:[41,42,43,44,45,46,47]},{key:"EyeLower0",indices:[0,1,2,3,4,5,6,7,8]},{key:"EyeLower1",indices:[16,17,18,19,20,21,22,23,24]},{key:"EyeLower2",indices:[32,33,34,35,36,37,38,39,40]},{key:"EyeLower3",indices:[54,55,56,57,58,59,60,61,62]},{key:"EyebrowUpper",indices:[63,64,65,66,67,68,69,70]},{key:"EyebrowLower",indices:[48,49,50,51,52,53]}],I2=[[.499976992607117,.652534008026123],[.500025987625122,.547487020492554],[.499974012374878,.602371990680695],[.482113003730774,.471979022026062],[.500150978565216,.527155995368958],[.499909996986389,.498252987861633],[.499523013830185,.40106201171875],[.289712011814117,.380764007568359],[.499954998493195,.312398016452789],[.499987006187439,.269918978214264],[.500023007392883,.107050001621246],[.500023007392883,.666234016418457],[.5000159740448,.679224014282227],[.500023007392883,.692348003387451],[.499976992607117,.695277988910675],[.499976992607117,.70593398809433],[.499976992607117,.719385027885437],[.499976992607117,.737019002437592],[.499967992305756,.781370997428894],[.499816000461578,.562981009483337],[.473773002624512,.573909997940063],[.104906998574734,.254140973091125],[.365929991006851,.409575998783112],[.338757991790771,.41302502155304],[.311120003461838,.409460008144379],[.274657994508743,.389131009578705],[.393361985683441,.403706014156342],[.345234006643295,.344011008739471],[.370094001293182,.3460760116577