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) 320 kB
/* Human homepage: <https://github.com/vladmandic/human> author: <https://github.com/vladmandic>' */ var at=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var $n=Object.getOwnPropertyNames;var eo=Object.prototype.hasOwnProperty;var q5=e=>{throw TypeError(e)};var to=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var re=(e,t)=>{for(var n in t)at(e,n,{get:t[n],enumerable:!0})},X5=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $n(t))!eo.call(e,s)&&s!==n&&at(e,s,{get:()=>t[s],enumerable:!(o=_n(t,s))||o.enumerable});return e},E=(e,t,n)=>(X5(e,t,"default"),n&&X5(n,t,"default"));var z=(e,t,n)=>to(e,typeof t!="symbol"?t+"":t,n),U5=(e,t,n)=>t.has(e)||q5("Cannot "+n);var E0=(e,t,n)=>(U5(e,t,"read from private field"),n?n.call(e):t.get(e)),q0=(e,t,n)=>t.has(e)?q5("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),_0=(e,t,n,o)=>(U5(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var r={};re(r,{node:()=>it,version:()=>Je});E(r,MA);E(r,PA);E(r,kA);E(r,wA);E(r,EA);E(r,zA);import*as MA from"@tensorflow/tfjs-core/dist/index.js";import*as PA from"@tensorflow/tfjs-converter/dist/index.js";import*as kA from"@tensorflow/tfjs-backend-cpu/dist/index.js";import*as wA from"@tensorflow/tfjs-backend-webgl/dist/index.js";import*as EA from"@tensorflow/tfjs-backend-wasm/dist/index.js";import*as zA from"@tensorflow/tfjs-backend-webgpu/dist/index.js";var Y5="4.22.0",no="4.22.0",oo="4.22.0",ro="4.22.0",so="4.22.0",Ao="4.22.0",Je={tfjs:Y5,"tfjs-core":Y5,"tfjs-converter":no,"tfjs-backend-cpu":oo,"tfjs-backend-webgl":ro,"tfjs-backend-wasm":so,"tfjs-backend-webgpu":Ao},it=void 0;function g(...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 K5(e,t){let n=e.endsWith("/")?"":"/",s=t.startsWith(".")||t.startsWith("/")||t.startsWith("http:")||t.startsWith("https:")||t.startsWith("file:")?`${t}`:`${e}${n}${t}`;if(!s.toLocaleLowerCase().includes(".json"))throw new Error(`modelpath error: expecting json file: ${s}`);return s}var R=()=>typeof performance!="undefined"?performance.now():parseInt((Number(process.hrtime.bigint())/1e3/1e3).toString());function lt(e,t,n="config",o=[]){for(let s of Object.keys(t))if(typeof t[s]=="object")lt(e[s],t[s],s,o);else{let A=e&&typeof e[s]!="undefined";A||o.push({reason:"unknown property",where:`${n}.${s} = ${t[s]}`});let a=e&&typeof e[s]==typeof t[s];A&&!a&&o.push({reason:"property type mismatch",where:`${n}.${s} = ${t[s]}`,expected:typeof e[s]})}return t.debug&&n==="config"&&o.length>0&&g("invalid configuration",o),o}function Q(...e){let t=n=>n&&typeof n=="object";return e.reduce((n,o)=>(Object.keys(o||{}).forEach(s=>{let A=n[s],a=o[s];Array.isArray(A)&&Array.isArray(a)?n[s]=A.concat(...a):t(A)&&t(a)?n[s]=Q(A,a):n[s]=a}),n),{})}var Ce={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 J5=` 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 Q5=` 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]; } `,_5=` 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; } `,$5=` 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); } `,e1=` 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; } `,t1=` 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 ct=(e,t,n)=>{let o=new RegExp("\\b"+t+" \\w+ (\\w+)","ig");e.replace(o,(s,A)=>(n[A]=0,s))},dt=class{constructor(t,n,o){z(this,"uniform",{});z(this,"attribute",{});z(this,"gl");z(this,"id");z(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:(g(`filter: gl compile failed: ${this.gl.getShaderInfoLog(o)||"unknown"}`),null)):(g("filter: could not create shader"),null)});this.gl=t;let s=this.compile(n,this.gl.VERTEX_SHADER),A=this.compile(o,this.gl.FRAGMENT_SHADER);if(this.id=this.gl.createProgram(),!(!s||!A)){if(!this.id){g("filter: could not create webgl program");return}if(this.gl.attachShader(this.id,s),this.gl.attachShader(this.id,A),this.gl.linkProgram(this.id),!this.gl.getProgramParameter(this.id,this.gl.LINK_STATUS)){g(`filter: gl link failed: ${this.gl.getProgramInfoLog(this.id)||"unknown"}`);return}this.gl.useProgram(this.id),ct(n,"attribute",this.attribute);for(let a in this.attribute)this.attribute[a]=this.gl.getAttribLocation(this.id,a);ct(n,"uniform",this.uniform),ct(o,"uniform",this.uniform);for(let a in this.uniform)this.uniform[a]=this.gl.getUniformLocation(this.id,a)}}};function n1(){let e=0,t=null,n=!1,o=-1,s=[null,null],A=[],a=null,i=null,c=D0(100,100),d={},x={INTERMEDIATE:1},l=c.getContext("webgl");if(!l){g("filter: cannot get webgl context");return}this.gl=l;function f(T,u){if(!(T===c.width&&u===c.height)){if(c.width=T,c.height=u,!a){let h=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=l.createBuffer(),l.bindBuffer(l.ARRAY_BUFFER,a),l.bufferData(l.ARRAY_BUFFER,h,l.STATIC_DRAW),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0)}l.viewport(0,0,c.width,c.height),s=[null,null]}}function y(T,u){let h=l.createFramebuffer();l.bindFramebuffer(l.FRAMEBUFFER,h);let w=l.createRenderbuffer();l.bindRenderbuffer(l.RENDERBUFFER,w);let k=l.createTexture();return l.bindTexture(l.TEXTURE_2D,k),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,T,u,0,l.RGBA,l.UNSIGNED_BYTE,null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,k,0),l.bindTexture(l.TEXTURE_2D,null),l.bindFramebuffer(l.FRAMEBUFFER,null),{fbo:h,texture:k}}function p(T){return s[T]=s[T]||y(c.width,c.height),s[T]}function m(T=0){if(!i)return;let u=null,h=null,w=!1;e===0?u=t:u=p(o).texture||null,e++,n&&!(T&x.INTERMEDIATE)?(h=null,w=e%2===0):(o=(o+1)%2,h=p(o).fbo||null),l.bindTexture(l.TEXTURE_2D,u),l.bindFramebuffer(l.FRAMEBUFFER,h),l.uniform1f(i.uniform.flipY,w?-1:1),l.drawArrays(l.TRIANGLES,0,6)}function b(T){if(d[T])return i=d[T],l.useProgram((i?i.id:null)||null),i;if(i=new dt(l,J5,T),!i)return g("filter: could not get webgl program"),null;let u=Float32Array.BYTES_PER_ELEMENT,h=4*u;return l.enableVertexAttribArray(i.attribute.pos),l.vertexAttribPointer(i.attribute.pos,2,l.FLOAT,!1,h,0*u),l.enableVertexAttribArray(i.attribute.uv),l.vertexAttribPointer(i.attribute.uv,2,l.FLOAT,!1,h,2*u),d[T]=i,i}let v={colorMatrix:T=>{let u=new Float32Array(T);u[4]/=255,u[9]/=255,u[14]/=255,u[19]/=255;let h=u[18]===1&&u[3]===0&&u[8]===0&&u[13]===0&&u[15]===0&&u[16]===0&&u[17]===0&&u[19]===0?_5:Q5,w=b(h);w&&(l.uniform1fv(w.uniform.m,u),m())},brightness:T=>{let u=(T||0)+1;v.colorMatrix([u,0,0,0,0,0,u,0,0,0,0,0,u,0,0,0,0,0,1,0])},saturation:T=>{let u=(T||0)*2/3+1,h=(u-1)*-.5;v.colorMatrix([u,h,h,0,0,h,u,h,0,0,h,h,u,0,0,0,0,0,1,0])},desaturate:()=>{v.saturation(-1)},contrast:T=>{let u=(T||0)+1,h=-128*(u-1);v.colorMatrix([u,0,0,0,h,0,u,0,0,h,0,0,u,0,h,0,0,0,1,0])},negative:()=>{v.contrast(-2)},hue:T=>{T=(T||0)/180*Math.PI;let u=Math.cos(T),h=Math.sin(T),w=.213,k=.715,I=.072;v.colorMatrix([w+u*(1-w)+h*-w,k+u*-k+h*-k,I+u*-I+h*(1-I),0,0,w+u*-w+h*.143,k+u*(1-k)+h*.14,I+u*-I+h*-.283,0,0,w+u*-w+h*-(1-w),k+u*-k+h*k,I+u*(1-I)+h*I,0,0,0,0,0,1,0])},desaturateLuminance:()=>{v.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:()=>{v.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},brownie:()=>{v.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:()=>{v.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:()=>{v.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:()=>{v.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:()=>{v.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:()=>{v.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},convolution:T=>{let u=new Float32Array(T),h=1/c.width,w=1/c.height,k=b(t1);k&&(l.uniform1fv(k.uniform.m,u),l.uniform2f(k.uniform.px,h,w),m())},detectEdges:()=>{v.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},sobelX:()=>{v.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},sobelY:()=>{v.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},sharpen:T=>{let u=T||1;v.convolution.call(this,[0,-1*u,0,-1*u,1+4*u,-1*u,0,-1*u,0])},emboss:T=>{let u=T||1;v.convolution.call(this,[-2*u,-1*u,0,-1*u,1,1*u,0,1*u,2*u])},blur:T=>{let u=T/7/c.width,h=T/7/c.height,w=b(e1);w&&(l.uniform2f(w.uniform.px,0,h),m(x.INTERMEDIATE),l.uniform2f(w.uniform.px,u,0),m())},pixelate:T=>{let u=T/c.width,h=T/c.height,w=b($5);w&&(l.uniform2f(w.uniform.size,u,h),m())}};this.add=function(T){let u=Array.prototype.slice.call(arguments,1),h=v[T];A.push({func:h,args:u})},this.reset=function(){A=[]},this.get=function(){return A},this.apply=function(T){f(T.width,T.height),e=0,t||(t=l.createTexture()),l.bindTexture(l.TEXTURE_2D,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,T);for(let u=0;u<A.length;u++){n=u===A.length-1;let h=A[u];h.func.apply(this,h.args||[])}return c},this.draw=function(T){return this.add("brightness",0),this.apply(T)}}async function d2(e){let t=e.shape.length===4?r.squeeze(e):e,n=r.split(t,3,2),o=[r.min(n[0]),r.min(n[1]),r.min(n[2])],s=[r.max(n[0]),r.max(n[1]),r.max(n[2])],A=await Promise.all(s.map(x=>x.data())),a=Math.max(A[0][0],A[1][0],A[2][0]),c=(a>1?255:1)/a,d;if(c>1){let x=[r.sub(n[0],o[0]),r.sub(n[1],o[1]),r.sub(n[2],o[2])],l=[r.sub(s[0],o[0]),r.sub(s[1],o[1]),r.sub(s[2],o[2])],f=[r.mul(x[0],c),r.mul(x[1],c),r.mul(x[2],c)],y=r.stack([f[0],f[1],f[2]],2);d=r.reshape(y,[1,t.shape[0]||0,t.shape[1]||0,3]),r.dispose([...x,...l,...f,y])}else d=r.expandDims(t,0);return r.dispose([...n,...o,...s,n,t,e]),d}var x2=3840,c0=null,d0=null,We=null,q,L0={inputSum:0,cacheDiff:1,sumMethod:0,inputTensor:void 0};function xt(){L0.inputSum=0,L0.cacheDiff=1,L0.sumMethod=0,L0.inputTensor=void 0}function D0(e,t){let n;if(M.browser)if(M.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 M.Canvas!="undefined")n=new M.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 M.Canvas!="undefined"?n=new M.Canvas(e,t):typeof globalThis.Canvas!="undefined"&&(n=new globalThis.Canvas(e,t));return n}function y2(e,t){let n=t||D0(e.width,e.height);return n.getContext("2d").drawImage(e,0,0),n}async function f2(e,t,n=!0){var f,y,p;if(!e)return t.debug&&g("input error: input is missing"),{tensor:null,canvas:null};if(!(e instanceof r.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 r.Tensor){let m=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)m=r.expandDims(e,0);else if(e.shape[2]===4){let b=r.slice3d(e,[0,0,0],[-1,-1,3]);m=r.expandDims(b,0),r.dispose(b)}}else e.shape.length===4&&(e.shape[3]===3?m=r.clone(e):e.shape[3]===4&&(m=r.slice4d(e,[0,0,0,0],[-1,-1,-1,3])));if(m==null||m.shape.length!==4||m.shape[0]!==1||m.shape[3]!==3)throw new Error(`input error: attempted to use tensor with unrecognized shape: ${e.shape.toString()}`);if(m.dtype==="int32"){let b=r.cast(m,"float32");r.dispose(m),m=b}return{tensor:m,canvas:t.filter.return?d0:null}}if(typeof e.readyState!="undefined"&&e.readyState<=2)return t.debug&&g("input stream is not ready"),{tensor:null,canvas:c0};let o=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,s=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;if(!o||!s)return t.debug&&g("cannot determine input dimensions"),{tensor:null,canvas:c0};let A=o,a=s;if(A>x2&&(A=x2,a=Math.trunc(A*s/o)),a>x2&&(a=x2,A=Math.trunc(a*o/s)),(((f=t.filter)==null?void 0:f.width)||0)>0?A=t.filter.width:(((y=t.filter)==null?void 0:y.height)||0)>0&&(A=o*((t.filter.height||0)/s)),(t.filter.height||0)>0?a=t.filter.height:(t.filter.width||0)>0&&(a=s*((t.filter.width||0)/o)),!A||!a)throw new Error("input error: cannot determine dimension");(!c0||c0.width!==A||c0.height!==a)&&(c0=D0(A,a));let i=c0.getContext("2d");if(typeof ImageData!="undefined"&&e instanceof ImageData?i.putImageData(e,0,0):t.filter.flip&&typeof i.translate!="undefined"?(i.translate(o,0),i.scale(-1,1),i.drawImage(e,0,0,o,s,0,0,c0.width,c0.height),i.setTransform(1,0,0,1,0,0)):i.drawImage(e,0,0,o,s,0,0,c0.width,c0.height),(!d0||c0.width!==d0.width||c0.height!==d0.height)&&(d0=D0(c0.width,c0.height)),t.filter.enabled&&M.webgl.supported?(q||(q=M.browser?new n1:null),M.filter=!!q,q!=null&&q.add?(q.reset(),t.filter.brightness!==0&&q.add("brightness",t.filter.brightness),t.filter.contrast!==0&&q.add("contrast",t.filter.contrast),t.filter.sharpness!==0&&q.add("sharpen",t.filter.sharpness),t.filter.blur!==0&&q.add("blur",t.filter.blur),t.filter.saturation!==0&&q.add("saturation",t.filter.saturation),t.filter.hue!==0&&q.add("hue",t.filter.hue),t.filter.negative&&q.add("negative"),t.filter.sepia&&q.add("sepia"),t.filter.vintage&&q.add("brownie"),t.filter.sepia&&q.add("sepia"),t.filter.kodachrome&&q.add("kodachrome"),t.filter.technicolor&&q.add("technicolor"),t.filter.polaroid&&q.add("polaroid"),t.filter.pixelate!==0&&q.add("pixelate",t.filter.pixelate),((p=q.get())==null?void 0:p.length)>1?d0=q.apply(c0):d0=q.draw(c0)):(t.debug&&g("input process error: cannot initialize filters"),M.webgl.supported=!1,t.filter.enabled=!1,y2(c0,d0))):(y2(c0,d0),q&&(q=null),M.filter=!!q),!n)return{tensor:null,canvas:d0};if(!d0)throw new Error("canvas error: cannot create output");let c,d=3;if(typeof ImageData!="undefined"&&e instanceof ImageData||e.data&&e.width&&e.height)if(M.browser&&r.browser)c=r.browser?r.browser.fromPixels(e):null;else{d=e.data.length/e.height/e.width;let m=new Uint8Array(e.data.buffer);c=r.tensor(m,[e.height,e.width,d],"int32")}else if((!We||d0.width!==We.width||d0.height!==We.height)&&(We=D0(d0.width,d0.height)),r.browser&&M.browser)t.backend==="webgl"||t.backend==="humangl"||t.backend==="webgpu"?c=r.browser.fromPixels(d0):(We=y2(d0),c=r.browser.fromPixels(We));else{let v=y2(d0).getContext("2d").getImageData(0,0,A,a);d=v.data.length/A/a;let T=new Uint8Array(v.data.buffer);c=r.tensor(T,[A,a,d])}if(d===4){let m=r.slice3d(c,[0,0,0],[-1,-1,3]);r.dispose(c),c=m}if(!c)throw new Error("input error: cannot create tensor");let x=r.cast(c,"float32"),l=t.filter.equalization?await d2(x):r.expandDims(x,0);if(r.dispose([c,x]),t.filter.autoBrightness){let m=r.max(l),b=await m.data();t.filter.brightness=b[0]>1?1-b[0]/255:1-b[0],r.dispose(m)}return{tensor:l,canvas:t.filter.return?d0:null}}async function o1(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(!L0.inputTensor)L0.inputTensor=r.clone(t);else if(L0.inputTensor.shape[1]!==t.shape[1]||L0.inputTensor.shape[2]!==t.shape[2])r.dispose(L0.inputTensor),L0.inputTensor=r.clone(t);else{let o={};o.diff=r.sub(t,L0.inputTensor),o.squared=r.mul(o.diff,o.diff),o.sum=r.sum(o.squared);let A=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;r.dispose([L0.inputTensor,o.diff,o.squared,o.sum]),L0.inputTensor=r.clone(t),n=A<=(e.cacheSensitivity||0)}return n}async function r1(e,t,n){let o={};if(!t||!n||t.shape.length!==4||t.shape.length!==n.shape.length)return e.debug||g("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||g("input tensors must be of shape [1, height, width, 3]:",t.shape,n.shape),0;o.input1=r.clone(t),o.input2=t.shape[1]!==n.shape[1]||t.shape[2]!==n.shape[2]?r.image.resizeBilinear(n,[t.shape[1],t.shape[2]]):r.clone(n),o.diff=r.sub(o.input1,o.input2),o.squared=r.mul(o.diff,o.diff),o.sum=r.sum(o.squared);let A=(await o.sum.data())[0]/(t.shape[1]||1)/(t.shape[2]||1)/255/3;return r.dispose([o.input1,o.input2,o.diff,o.squared,o.sum]),A}var Qe,_e,$e,p2=class{constructor(){z(this,"browser");z(this,"node");z(this,"worker");z(this,"platform","");z(this,"agent","");z(this,"backends",[]);z(this,"initial");z(this,"filter");z(this,"tfjs");z(this,"offscreen");z(this,"perfadd",!1);z(this,"tensorflow",{version:void 0,gpu:void 0});z(this,"wasm",{supported:void 0,backend:void 0,simd:void 0,multithread:void 0});z(this,"webgl",{supported:void 0,backend:void 0,version:void 0,renderer:void 0,shader:void 0,vendor:void 0});z(this,"webgpu",{supported:void 0,backend:void 0,adapter:void 0});z(this,"cpu",{model:void 0,flags:[]});z(this,"kernels",[]);q0(this,Qe);q0(this,_e);q0(this,$e);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:Je["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 E0(this,Qe)}set Canvas(t){_0(this,Qe,t),globalThis.Canvas=t}get Image(){return E0(this,_e)}set Image(t){_0(this,_e,t),globalThis.Image=t}get ImageData(){return E0(this,$e)}set ImageData(t){_0(this,$e,t),globalThis.ImageData=t}async updateBackend(){this.backends=Object.keys(r.engine().registryFactory);try{this.tensorflow={version:r.backend().binding?r.backend().binding.TF_Version:void 0,gpu:r.backend().binding?r.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 r.env().getAsync("WASM_HAS_SIMD_SUPPORT"),this.wasm.multithread=await r.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"));let t=D0(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=r.getKernelsForBackend(r.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})}};Qe=new WeakMap,_e=new WeakMap,$e=new WeakMap;var M=new p2;var u2=class{constructor(){z(this,"config");z(this,"element");z(this,"stream");z(this,"devices",[]);z(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});z(this,"start",async t=>{var s,A;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&&g("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&&g("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(((s=this.config)==null?void 0:s.width)>0&&(n.video.width={ideal:this.config.width}),((A=this.config)==null?void 0:A.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&&g("webcam","play")}),this.element.addEventListener("pause",()=>{this.config.debug&&g("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&&g("webcam error","no devices"),"webcam error: no devices";try{this.stream=await navigator.mediaDevices.getUserMedia(n)}catch(a){return g("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&&g("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&&g("webcam error","no stream"),"webcam error no stream")});z(this,"pause",()=>{this.element&&this.element.pause()});z(this,"play",async()=>{this.element&&await this.element.play()});z(this,"stop",()=>{this.config.debug&&g("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 yt={};re(yt,{"affectnet-mobilenet":()=>Ro,age:()=>Mo,"anti-spoofing":()=>nr,antispoof:()=>co,blazeface:()=>xo,"blazeface-back":()=>Po,"blazeface-front":()=>ko,"blazepose-detector":()=>wo,"blazepose-full":()=>Eo,"blazepose-heavy":()=>zo,"blazepose-lite":()=>So,centernet:()=>yo,default:()=>mr,efficientpose:()=>jo,"efficientpose-i-lite":()=>or,"efficientpose-ii-lite":()=>rr,"efficientpose-iv":()=>sr,emotion:()=>fo,faceboxes:()=>No,facemesh:()=>mo,"facemesh-attention":()=>Lo,"facemesh-attention-pinto":()=>Io,"facemesh-detection-full":()=>Oo,"facemesh-detection-short":()=>Co,faceres:()=>po,"faceres-deep":()=>Wo,gear:()=>Bo,"gear-e1":()=>Do,"gear-e2":()=>Fo,gender:()=>Go,"gender-ssrnet-imdb":()=>Ho,handdetect:()=>Vo,"handlandmark-full":()=>Zo,"handlandmark-lite":()=>uo,"handlandmark-sparse":()=>Xo,handskeleton:()=>qo,handtrack:()=>ho,"insightface-efficientnet-b0":()=>Ar,"insightface-ghostnet-strides1":()=>ar,"insightface-ghostnet-strides2":()=>ir,"insightface-mobilenet-emore":()=>lr,"insightface-mobilenet-swish":()=>cr,iris:()=>bo,liveness:()=>go,meet:()=>Uo,mobileface:()=>Yo,mobilefacenet:()=>Ko,models:()=>To,"movenet-lightning":()=>vo,"movenet-multipose":()=>Jo,"movenet-thunder":()=>Qo,nanodet:()=>_o,"nanodet-e":()=>dr,"nanodet-g":()=>xr,"nanodet-m":()=>yr,"nanodet-t":()=>fr,posenet:()=>$o,rvm:()=>er,selfie:()=>tr});var co=853098,xo=538928,yo=4030290,fo=820516,mo=1477958,po=6978814,uo=2023432,ho=2964837,bo=2599092,go=592976,To=0,vo=4650216,Ro=6920630,Mo=161240,Po=538928,ko=402048,wo=5928856,Eo=6339202,zo=27502466,So=2726402,jo=5651240,No=2013002,Io=2387598,Lo=2382414,Oo=1026192,Co=201268,Wo=13957620,Do=112438,Fo=112438,Bo=1498916,Ho=161236,Go=201808,Vo=3515612,Zo=5431368,Xo=5286322,qo=5502280,Uo=372228,Yo=2183192,Ko=5171976,Jo=9448838,Qo=12477112,_o=7574558,$o=5032780,er=3739355,tr=212886,nr=853098,or=2269064,rr=5651240,sr=25643252,Ar=13013224,ar=8093408,ir=8049584,lr=6938536,cr=12168584,dr=12319156,xr=7574558,yr=1887474,fr=5294216,mr={antispoof:co,blazeface:xo,centernet:yo,emotion:fo,facemesh:mo,faceres:po,"handlandmark-lite":uo,handtrack:ho,iris:bo,liveness:go,models:To,"movenet-lightning":vo,"affectnet-mobilenet":Ro,age:Mo,"blazeface-back":Po,"blazeface-front":ko,"blazepose-detector":wo,"blazepose-full":Eo,"blazepose-heavy":zo,"blazepose-lite":So,efficientpose:jo,faceboxes:No,"facemesh-attention-pinto":Io,"facemesh-attention":Lo,"facemesh-detection-full":Oo,"facemesh-detection-short":Co,"faceres-deep":Wo,"gear-e1":Do,"gear-e2":Fo,gear:Bo,"gender-ssrnet-imdb":Ho,gender:Go,handdetect:Vo,"handlandmark-full":Zo,"handlandmark-sparse":Xo,handskeleton:qo,meet:Uo,mobileface:Yo,mobilefacenet:Ko,"movenet-multipose":Jo,"movenet-thunder":Qo,nanodet:_o,posenet:$o,rvm:er,selfie:tr,"anti-spoofing":nr,"efficientpose-i-lite":or,"efficientpose-ii-lite":rr,"efficientpose-iv":sr,"insightface-efficientnet-b0":Ar,"insightface-ghostnet-strides1":ar,"insightface-ghostnet-strides2":ir,"insightface-mobilenet-emore":lr,"insightface-mobilenet-swish":cr,"nanodet-e":dr,"nanodet-g":xr,"nanodet-m":yr,"nanodet-t":fr};var T0={cacheModels:!0,cacheSupported:!0,verbose:!0,debug:!1,modelBasePath:""},l0={};async function pr(e,t){return T0.debug&&g("load model fetch:",e,t),fetch(e,t)}function s1(e){T0.cacheModels=e.cacheModels,T0.verbose=e.debug,T0.modelBasePath=e.modelBasePath}async function L(e){var c,d,x,l,f,y;let t=K5(T0.modelBasePath,e||"");t.toLowerCase().endsWith(".json")||(t+=".json");let n=t.includes("/")?t.split("/"):t.split("\\"),o=n[n.length-1].replace(".json",""),s="indexeddb://"+o;l0[o]={name:o,loaded:!1,sizeFromManifest:0,sizeLoadedWeights:0,sizeDesired:yt[o],inCache:!1,url:""},T0.cacheSupported=typeof indexedDB!="undefined";let A={};try{A=T0.cacheSupported&&T0.cacheModels?await r.io.listModels():{}}catch(p){T0.cacheSupported=!1}l0[o].inCache=T0.cacheSupported&&T0.cacheModels&&Object.keys(A).includes(s),l0[o].url=l0[o].inCache?s:t;let a=typeof fetch=="undefined"?{}:{fetchFunc:(p,m)=>pr(p,m)},i=new r.GraphModel(l0[o].url,a);l0[o].loaded=!1;try{i.findIOHandler(),T0.debug&&g("model load handler:",i.handler)}catch(p){g("error finding model i/o handler:",t,p)}try{let p=await((c=i.handler)==null?void 0:c.load())||null;l0[o].sizeFromManifest=((d=p==null?void 0:p.weightData)==null?void 0:d.byteLength)||0,p?i.loadSync(p):i=await r.loadGraphModel(l0[o].inCache?s:t,a),l0[o].sizeLoadedWeights=((l=(x=i.artifacts)==null?void 0:x.weightData)==null?void 0:l.byteLength)||((y=(f=i.artifacts)==null?void 0:f.weightData)==null?void 0:y[0].byteLength)||0,T0.verbose&&g("load:",{model:o,url:i.modelUrl,bytes:l0[o].sizeLoadedWeights}),l0[o].loaded=!0}catch(p){g("error loading model:",t,p)}if(l0[o].loaded&&T0.cacheModels&&T0.cacheSupported&&!l0[o].inCache)try{let p=await i.save(s);T0.debug&&g("model saved:",s,p)}catch(p){g("error saving model:",t,p)}return i}var ft="3.3.5";var K={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 br(){let e=K.gl;e&&(K.extensions=e.getSupportedExtensions())}function A1(e){var t;if(e.config.backend==="humangl"&&(K.name in r.engine().registry&&!((t=K==null?void 0:K.gl)!=null&&t.getParameter(K.gl.VERSION))&&(g("humangl error: backend invalid context"),e.models.reset()),!r.findBackend(K.name))){try{K.canvas=D0(100,100)}catch(s){g("humangl error: cannot create canvas:",s);return}try{if(K.gl=K.canvas.getContext("webgl2",K.webGLattr),!K.gl){g("humangl error: cannot get webgl context");return}if(!K.gl.getParameter(K.gl.VERSION).includes("2.0")){g("backend override: using fallback webgl backend as webgl 2.0 is not detected"),e.config.backend="webgl";return}K.canvas&&(K.canvas.addEventListener("webglcontextlost",A=>{throw g("humangl error:",A.type),g("possible browser memory leak using webgl or conflict with multiple backend registrations"),e.emit("error"),new Error("backend error: webgl context lost")}),K.canvas.addEventListener("webglcontextrestored",A=>{g("humangl error: context restored:",A)}),K.canvas.addEventListener("webglcontextcreationerror",A=>{g("humangl error: context create:",A)}))}catch(s){g("humangl error: cannot get webgl context:",s);return}try{r.setWebGLContext(2,K.gl)}catch(s){g("humangl error: cannot set webgl context:",s);return}try{let s=new r.GPGPUContext(K.gl);r.registerBackend(K.name,()=>new r.MathBackendWebGL(s),K.priority)}catch(s){g("humangl error: cannot register webgl backend:",s);return}try{r.getKernelsForBackend("webgl").forEach(A=>{let a={...A,backendName:K.name};r.registerKernel(a)})}catch(s){g("humangl error: cannot update webgl backend registration:",s);return}try{r.env().flagRegistry.WEBGL_VERSION&&r.env().set("WEBGL_VERSION",2)}catch(s){g("humangl error: cannot set WebGL backend flags:",s);return}br();let n=r.backend(),o=typeof n.gpgpu!="undefined"?n.getGPGPUContext().gl:null;o?e.config.debug&&g("humangl backend registered:",{webgl:o.getParameter(o.VERSION),renderer:o.getParameter(o.RENDERER)}):g("humangl error: no current gl context:",o,K.gl)}}var O={tf255:255,tf1:1,tf2:2,tf05:.5,tf127:127.5,rgb:[.2989,.587,.114]};function a1(){O.tf255=r.scalar(255,"float32"),O.tf1=r.scalar(1,"float32"),O.tf2=r.scalar(2,"float32"),O.tf05=r.scalar(.5,"float32"),O.tf127=r.scalar(127.5,"float32"),O.rgb=r.tensor1d([.2989,.587,.114],"float32")}async function vr(){var e;return await M.updateBackend(),(e=M.tensorflow)!=null&&e.version?"tensorflow":M.webgpu.supported&&M.webgpu.backend?"webgpu":M.webgl.supported&&M.webgl.backend?"webgl":M.wasm.supported&&M.wasm.backend?"wasm":"cpu"}function Rr(e){let t=[];if(!M.kernels.includes("mod")){let n={kernelName:"Mod",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>r.sub(o.inputs.a,r.mul(r.div(o.inputs.a,o.inputs.b),o.inputs.b)))};r.registerKernel(n),M.kernels.push("mod"),t.push("mod")}if(!M.kernels.includes("floormod")){let n={kernelName:"FloorMod",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>r.add(r.mul(r.floorDiv(o.inputs.a,o.inputs.b),o.inputs.b),r.mod(o.inputs.a,o.inputs.b)))};r.registerKernel(n),M.kernels.push("floormod"),t.push("floormod")}if(!M.kernels.includes("rotatewithoffset")&&e.softwareKernels){let n={kernelName:"RotateWithOffset",backendName:r.getBackend(),kernelFunc:o=>r.tidy(()=>{let s=r.getBackend();r.setBackend("cpu");let A=r.image.rotateWithOffset(o.inputs.image,o.attrs.radians,o.attrs.fillValue,o.attrs.center);return r.setBackend(s),A})};r.registerKernel(n),M.kernels.push("rotatewithoffset"),t.push("rotatewithoffset")}t.length>0&&e.debug&&g("registered kernels:",t)}var i1={};async function e2(e,t=!1){var n,o;if(e.state="backend",((n=e.config.backend)==null?void 0:n.length)===0&&(e.config.backend=await vr()),t||M.initial||e.config.backend&&e.config.backend.length>0&&r.getBackend()!==e.config.backend){let s=R();if(e.config.backend&&e.config.backend.length>0){typeof window=="undefined"&&typeof WorkerGlobalScope!="undefined"&&e.config.debug&&e.config.debug&&g("running inside web worker"),typeof navigator!="undefined"&&((o=navigator==null?void 0:navigator.userAgent)!=null&&o.toLowerCase().includes("electron"))&&e.config.debug&&g("running inside electron");let A=Object.keys(r.engine().registryFactory);if(e.config.backend==="humangl"&&!A.includes("humangl")&&(A1(e),A=Object.keys(r.engine().registryFactory)),e.config.debug&&g("available backends:",A),M.browser&&!M.node&&e.config.backend==="tensorflow"&&A.includes("webgl")&&(e.config.debug&&g("override: backend set to tensorflow while running in browser"),e.config.backend="webgl"),M.node&&!M.browser&&(e.config.backend==="webgl"||e.config.backend==="humangl")&&A.includes("tensorflow")&&(e.config.debug&&g(`override: backend set to ${e.config.backend} while running in nodejs`),e.config.backend="tensorflow"),M.browser&&e.config.backend==="webgpu")if(typeof navigator=="undefined"||typeof navigator.gpu=="undefined")g("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&&g("enumerated webgpu adapter:",a),!a)g("override: backend set to webgpu but browser reports no available gpu"),e.config.backend="webgl";else{let i;"requestAdapterInfo"in a?i=await(a==null?void 0:a.requestAdapterInfo()):i=a.info,g("webgpu adapter info:",i)}}if(A.includes(e.config.backend)||(g(`error: backend ${e.config.backend} not found in registry`),e.config.backend=M.node?"tensorflow":"webgl",e.config.debug&&g(`override: setting backend ${e.config.backend}`)),e.config.debug&&g("setting backend:",[e.config.backend]),e.config.backend==="wasm"){if(r.env().flagRegistry.CANVAS2D_WILL_READ_FREQUENTLY&&r.env().set("CANVAS2D_WILL_READ_FREQUENTLY",!0),e.config.debug&&g("wasm path:",e.config.wasmPath),typeof r.setWasmPaths!="undefined")r.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,i=!1;try{a=await r.env().getAsync("WASM_HAS_MULTITHREAD_SUPPORT"),i=await r.env().getAsync("WASM_HAS_SIMD_SUPPORT"),e.config.debug&&g(`wasm execution: ${i?"simd":"no simd"} ${a?"multithreaded":"singlethreaded"}`),e.config.debug&&!i&&g("warning: wasm simd support is not enabled")}catch(c){g("wasm detection failed")}}try{await r.setBackend(e.config.backend),await r.ready()}catch(a){return g("error: cannot set backend:",e.config.backend,a),!1}e.config.debug&&(i1=JSON.parse(JSON.stringify(r.env().flags)))}if((r.getBackend()==="humangl"||r.getBackend()==="webgl")&&(r.env().flagRegistry.WEBGL_USE_SHAPES_UNIFORMS&&r.env().set("WEBGL_USE_SHAPES_UNIFORMS",!0),r.env().flagRegistry.WEBGL_EXP_CONV&&r.env().set("WEBGL_EXP_CONV",!0),e.config.debug&&typeof e.config.deallocate!="undefined"&&e.config.deallocate&&(g("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:",!0),r.env().set("WEBGL_DELETE_TEXTURE_THRESHOLD",0))),r.getBackend(),e.config.debug){let A=r.env().flags,a={};for(let i of Object.keys(A))i1[i]!==A[i]&&(a[i]=A[i]);e.config.debug&&Object.keys(a).length>0&&g("backend:",r.getBackend(),"flags:",a)}if(e.config.flags&&Object.keys(e.config.flags).length>0){e.config.debug&&g("flags:",e.config.flags);for(let[A,a]of Object.entries(e.config.flags))r.env().set(A,a)}r.enableProdMode(),a1(),e.performance.initBackend=Math.trunc(R()-s),e.config.backend=r.getBackend(),await M.updateBackend(),Rr(e.config)}return!0}function h2(e,t){for(let n of e){let o={kernelName:n,backendName:t.backend,kernelFunc:s=>{var A;return t.debug&&g("kernelFunc",n,t.backend,s),(A=s==null?void 0:s.inputs)==null?void 0:A.info}};r.registerKernel(o)}M.kernels=r.getKernelsForBackend(r.getBackend()).map(n=>n.kernelName.toLowerCase())}var vt={};re(vt,{all:()=>ts,body:()=>g2,canvas:()=>$r,face:()=>b2,gesture:()=>R2,hand:()=>T2,init:()=>Tt,object:()=>v2,options:()=>n0,person:()=>_r,tensor:()=>es});var O0=e=>{if(!e)g("draw error: invalid canvas");else if(!e.getContext)g("draw error: canvas context not defined");else{let t=e.getContext("2d",{willReadFrequently:!0});if(!t)g("draw error: cannot get canvas context");else return t}return null},ge=e=>Math.round(e*180/Math.PI),H=(e,t,n)=>e.replace(t,typeof n=="number"?n.toFixed(1):n),Te=(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 C0(e,t,n,o,s){let A=t.replace(/\[.*\]/g,"").split(` `).map(i=>i.trim()),a=Math.max(0,n);for(let i=A.length-1;i>=0;i--){let c=i*s.lineHeight+o;s.shadowColor&&s.shadowColor!==""&&(e.fillStyle=s.shadowColor,e.fillText(A[i],a+5,c+16)),e.fillStyle=s.labelColor,e.fillText(A[i],a+4,c+15)}}function U0(e,t,n,o,s){e.fillStyle=Te(o,s),e.beginPath(),e.arc(t,n,s.pointSize,0,2*Math.PI),e.fill()}function Y0(e,t,n,o,s,A){if(e.beginPath(),e.lineWidth=A.lineWidth,A.useCurves){let a=(t+t+o)/2,i=(n+n+s)/2;e.ellipse(a,i,o/2,s/2,0,0,2*Math.PI)}else e.moveTo(t+A.roundRect,n),e.lineTo(t+o-A.roundRect,n),e.quadraticCurveTo(t+o,n,t+o,n+A.roundRect),e.lineTo(t+o,n+s-A.roundRect),e.quadraticCurveTo(t+o,n+s,t+o-A.roundRect,n+s),e.lineTo(t+A.roundRect,n+s),e.quadraticCurveTo(t,n+s,t,n+s-A.roundRect),e.lineTo(t,n+A.roundRect),e.quadraticCurveTo(t,n,t+A.roundRect,n),e.closePath();e.stroke()}function mt(e,t,n){if(!(t.length<2)){e.beginPath(),e.moveTo(t[0][0],t[0][1]);for(let o of t)e.strokeStyle=Te(o[2]||0,n),e.lineTo(Math.trunc(o[0]),Math.trunc(o[1]));e.stroke(),n.fillPolygons&&(e.closePath(),e.fill())}}function c1(e,t,n){if(!(t.length<2)){if(e.lineWidth=n.lineWidth,!n.useCurves||t.length<=2){mt(e,t,n);return}e.moveTo(t[0][0],t[0][1]);for(let o=0;o<t.length-2;o++){let s=(t[o][0]+t[o+1][0])/2,A=(t[o][1]+t[o+1][1])/2;e.quadraticCurveTo(t[o][0],t[o][1],s,A)}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 pt(e,t,n,o=5){let s,A,a;e.beginPath(),e.moveTo(t[0],t[1]),e.lineTo(n[0],n[1]),s=Math.atan2(n[1]-t[1],n[0]-t[0]),A=o*Math.cos(s)+n[0],a=o*Math.sin(s)+n[1],e.moveTo(A,a),s+=1/3*(2*Math.PI),A=o*Math.cos(s)+n[0],a=o*Math.sin(s)+n[1],e.lineTo(A,a),s+=1/3*(2*Math.PI),A=o*Math.cos(s)+n[0],a=o*Math.sin(s)+n[1],e.lineTo(A,a),e.closePath(),e.stroke(),e.fill()}var n0={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 F0={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]},ut={count:468,mouth:13,symmetryLine:[13,F0.midwayBetweenEyes[0]]},ve={leftEye:0,rightEye:1,nose:2,mouth:3,leftEar:4,rightEar:5,symmetryLine:[3,2]},ht=[{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]}],t2=[[.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,.346076011657715],[.319321990013123,.347265005111694],[.297903001308441,.353591024875641],[.24779200553894,.410809993743896],[.396889001131058,.842755019664764],[.280097991228104,.375599980354309],[.106310002505779,.399955987930298],[.2099249958992,.391353011131287],[.355807989835739,.534406006336212],[.471751004457474,.65040397644043],[.474155008792877,.680191993713379],[.439785003662109,.657229006290436],[.414617002010345,.66654098033905],[.450374007225037,.680860996246338],[.428770989179611,.682690978050232],[.374971002340317,.727805018424988],[.486716985702515,.547628998756409],[.485300987958908,.527395009994507],[.257764995098114,.314490020275116],[.401223003864288,.455172002315521],[.429818987846375,.548614978