2020-10-20 13:58:20 +02:00
|
|
|
var We=Object.defineProperty;var E=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),E0=e=>We(e,"__esModule",{value:!0}),Ge=(e,t)=>{E0(e);for(var o in t)We(e,o,{get:t[o],enumerable:!0})};var Ze=E(ne=>{const w=require("@tensorflow/tfjs"),Ye=6;function v0(e){const t={strides:[e/16,e/8],anchors:[2,6]},o=[];for(let n=0;n<t.strides.length;n++){const s=t.strides[n],i=Math.floor((e+s-1)/s),a=Math.floor((e+s-1)/s),c=t.anchors[n];for(let d=0;d<i;d++){const l=s*(d+.5);for(let u=0;u<a;u++){const f=s*(u+.5);for(let h=0;h<c;h++)o.push([f,l])}}}return o}const Ke=e=>{e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},Ve=e=>({startEndTensor:e,startPoint:w.slice(e,[0,0],[-1,2]),endPoint:w.slice(e,[0,2],[-1,2])}),P0=(e,t)=>{const o=w.mul(e.startPoint,t),n=w.mul(e.endPoint,t),s=w.concat2d([o,n],1);return Ve(s)};function T0(e,t,o){const n=w.slice(e,[0,1],[-1,2]),s=w.add(n,t),i=w.slice(e,[0,3],[-1,2]),a=w.div(i,o),c=w.div(s,o),d=w.div(a,2),l=w.sub(c,d),u=w.add(c,d),f=w.mul(l,o),h=w.mul(u,o),r=1;return w.concat2d([f,h],r)}function _0(e,t){return w.tidy(()=>{const o=e.box?e.box:e;return P0(o,t).startEndTensor.squeeze()})}class Qe{constructor(e,t){this.blazeFaceModel=e,this.width=t.detector.inputSize,this.height=t.detector.inputSize,this.maxFaces=t.detector.maxFaces,this.anchorsData=v0(t.detector.inputSize),this.anchors=w.tensor2d(this.anchorsData),this.inputSize=w.tensor1d([this.width,this.height]),this.iouThreshold=t.detector.iouThreshold,this.scaleFaces=.8,this.scoreThreshold=t.detector.scoreThreshold}async getBoundingBoxes(e){if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return null;const[t,o,n]=w.tidy(()=>{const l=e.resizeBilinear([this.width,this.height]),u=w.mul(w.sub(l.div(255),.5),2),f=this.blazeFaceModel.predict(u);let h;if(Array.isArray(f)){const P=f.sort((F,p)=>F.size-p.size),T=w.concat([P[0],P[2]],2),y=w.concat([P[1],P[3]],2),B=w.concat([y,T],1);h=B.squeeze(0)}else h=f.squeeze();const r=T0(h,this.anchors,this.inputSize),b=w.slice(h,[0,0],[-1,1]),_=w.sigmoid(b).squeeze();return[h,r,_]}),s=await w.image.nonMaxSuppressionAsync(o,n,this.maxFaces,this.iouThreshold,this.scoreThreshold),i=await s.array();s.dispose();const a=i.map(l=>w.slice(o,[l,0],[1,-1])),c=await Promise.all(a.map(async l=>{const u=await l.array();return l.dispose(),u})),d=[];for(let l=0;l<c.length;l++){const u=c[l],f=Ve(u),h=i[l],r=this.anchorsData[h],b=w.slice(t,[h,Ye-1],[1,-1]),_=b.squeeze(),P=_.reshape([Ye,-1]),T=w.slice(n,[h],[1]),y={box:f,landmarks:P,probability:T,anchor:r};d.push(y),b.dispose(),_.dispose()}return t.dispose(),o.dispose(),n.dispose(),t.dispose(),{boxes:d,scaleFactor:[e.shape[2]/this.width,e.shape[1]/this.height]}}async estimateFaces(e){const{boxes:t,scaleFactor:o}=await this.getBoundingBoxes(e);return Promise.all(t.map(async n=>{const s=_0(n,o),[i,a,c]=await Promise.all([n.landmarks,s,n.probability].map(async r=>r.array())),d=n.anchor,[l,u]=o,f=i.map(r=>[(r[0]+d[0])*l,(r[1]+d[1])*u]),h={topLeft:a.slice(0,2),bottomRight:a.slice(2),landmarks:f,probability:c};return Ke(n.box),n.landmarks.dispose(),n.probability.dispose(),s.dispose(),h}))}}async function M0(e){const t=await w.loadGraphModel(e.detector.modelPath,{fromTFHub:e.detector.modelPath.includes("tfhub.dev")}),o=new Qe(t,e);return o}ne.load=M0;ne.BlazeFaceModel=Qe;ne.disposeBox=Ke});var me=E(ue=>{ue.MESH_ANNOTATIONS={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:[61,185,40,39,37,0,267,269,270,409,291],lipsLowerOuter:[146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[78,191,80,81,82,13,312,311,310,415,308],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],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,
|
2020-10-19 17:03:48 +02:00
|
|
|
`),F.FRAGMENT_IDENTITY=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","void main(void) {","gl_FragColor = texture2D(texture, vUv);","}"].join(`
|
2020-10-20 13:58:20 +02:00
|
|
|
`);let p={};p.colorMatrix=function(g){const m=new Float32Array(g);m[4]/=255,m[9]/=255,m[14]/=255,m[19]/=255;const x=m[18]===1&&m[3]===0&&m[8]===0&&m[13]===0&&m[15]===0&&m[16]===0&&m[17]===0&&m[19]===0?p.colorMatrix.SHADER.WITHOUT_ALPHA:p.colorMatrix.SHADER.WITH_ALPHA,M=y(x);r.uniform1fv(M.uniform.m,m),T()},p.colorMatrix.SHADER={},p.colorMatrix.SHADER.WITH_ALPHA=["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];","}"].join(`
|
2020-10-19 17:03:48 +02:00
|
|
|
`),p.colorMatrix.SHADER.WITHOUT_ALPHA=["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;","}"].join(`
|
2020-10-20 13:58:20 +02:00
|
|
|
`),p.brightness=function(g){const m=(g||0)+1;p.colorMatrix([m,0,0,0,0,0,m,0,0,0,0,0,m,0,0,0,0,0,1,0])},p.saturation=function(g){const m=(g||0)*2/3+1,x=(m-1)*-.5;p.colorMatrix([m,x,x,0,0,x,m,x,0,0,x,x,m,0,0,0,0,0,1,0])},p.desaturate=function(){p.saturation(-1)},p.contrast=function(g){const m=(g||0)+1,x=-128*(m-1);p.colorMatrix([m,0,0,0,x,0,m,0,0,x,0,0,m,0,x,0,0,0,1,0])},p.negative=function(){p.contrast(-2)},p.hue=function(g){g=(g||0)/180*Math.PI;const m=Math.cos(g),x=Math.sin(g),M=.213,S=.715,N=.072;p.colorMatrix([M+m*(1-M)+x*-M,S+m*-S+x*-S,N+m*-N+x*(1-N),0,0,M+m*-M+x*.143,S+m*(1-S)+x*.14,N+m*-N+x*-.283,0,0,M+m*-M+x*-(1-M),S+m*-S+x*S,N+m*(1-N)+x*N,0,0,0,0,0,1,0])},p.desaturateLuminance=function(){p.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},p.sepia=function(){p.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},p.brownie=function(){p.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},p.vintagePinhole=function(){p.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},p.kodachrome=function(){p.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])},p.technicolor=function(){p.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])},p.polaroid=function(){p.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},p.shiftToBGR=function(){p.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},p.convolution=function(g){const m=new Float32Array(g),x=1/c,M=1/d,S=y(p.convolution.SHADER);r.uniform1fv(S.uniform.m,m),r.uniform2f(S.uniform.px,x,M),T()},p.convolution.SHADER=["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);","vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y));","vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y));","vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) );","vec4 c22 = texture2D(texture, vUv);","vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) );","vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) );","vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) );","vec4 c33 = texture2D(texture, vUv + px );","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;","}"].join(`
|
|
|
|
`),p.detectEdges=function(){p.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},p.sobelX=function(){p.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},p.sobelY=function(){p.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},p.sharpen=function(g){const m=g||1;p.convolution.call(this,[0,-1*m,0,-1*m,1+4*m,-1*m,0,-1*m,0])},p.emboss=function(g){const m=g||1;p.convolution.call(this,[-2*m,-1*m,0,-1*m,1,1*m,0,1*m,2*m])},p.blur=function(g){const m=g/7/c,x=g/7/d,M=y(p.blur.SHADER);r.uniform2f(M.uniform.px,0,x),T(B.INTERMEDIATE),r.uniform2f(M.uniform.px,m,0),T()},p.blur.SHADER=["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;","}"].join(`
|
|
|
|
`),p.pixelate=function(g){const m=g/c,x=g/d,M=y(p.pixelate.SHADER);r.uniform2f(M.uniform.size,m,x),T()},p.pixelate.SHADER=["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);","}"].join(`
|
|
|
|
`)};i0.Canvas=pn});var a0=E(gn=>{Ge(gn,{default:()=>xn});var xn={backend:"webgl",console:!0,scoped:!1,videoOptimized:!0,filter:{enabled:!0,return:!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},face:{enabled:!0,detector:{modelPath:"../models/blazeface/back/model.json",inputSize:256,maxFaces:10,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7},mesh:{enabled:!0,modelPath:"../models/facemesh/model.json",inputSize:192},iris:{enabled:!0,modelPath:"../models/iris/model.json",enlargeFactor:2.3,inputSize:64},age:{enabled:!0,modelPath:"../models/ssrnet-age/imdb/model.json",inputSize:64,skipFrames:10},gender:{enabled:!0,minConfidence:.8,modelPath:"../models/ssrnet-gender/imdb/model.json"},emotion:{enabled:!0,inputSize:64,minConfidence:.5,skipFrames:10,modelPath:"../models/emotion/model.json"}},body:{enabled:!0,modelPath:"../models/posenet/model.json",inputResolution:257,outputStride:16,maxDetections:10,scoreThreshold:.7,nmsRadius:20},hand:{enabled:!0,inputSize:256,skipFrames:10,minConfidence:.5,iouThreshold:.3,scoreThreshold:.7,enlargeFactor:1.65,maxHands:10,detector:{anchors:"../models/handdetect/anchors.json",modelPath:"../models/handdetect/model.json"},skeleton:{modelPath:"../models/handskeleton/model.json"}}}});var d0=E((Jn,c0)=>{c0.exports={name:"@vladmandic/human",version:"0.4.1",description:"human: 3D Face Detection, Iris Tracking and Age & Gender Prediction",sideEffects:!1,main:"dist/human.cjs",module:"dist/human.esm.js",browser:"dist/human.esm.js",author:"Vladimir Mandic <mandic00@live.com>",bugs:{url:"https://github.com/vladmandic/human/issues"},homepage:"https://github.com/vladmandic/human#readme",license:"MIT",engines:{node:">=14.0.0"},repository:{type:"git",url:"git+https://github.com/vladmandic/human.git"},dependencies:{},peerDependencies:{},devDependencies:{"@vladmandic/pilogger":"^0.2.6",dayjs:"^1.9.3","simple-git":"^2.21.0","@tensorflow/tfjs":"^2.6.0","@tensorflow/tfjs-node":"^2.6.0",esbuild:"^0.7.15",eslint:"^7.10.0","eslint-config-airbnb-base":"^14.2.0","eslint-plugin-import":"^2.22.1","eslint-plugin-json":"^2.1.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1",rimraf:"^3.0.2"},scripts:{start:"node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js",lint:"eslint src/*.js demo/*.js","build-iife":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=iife --minify --external:fs --global-name=Human --metafile=dist/human.json --outfile=dist/human.js src/human.js","build-esm-bundle":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:fs --metafile=dist/human.esm.json --outfile=dist/human.esm.js src/human.js","build-esm-nobundle":"esbuild --bundle --platform=browser --sourcemap --target=esnext --format=esm --minify --external:@tensorflow --external:fs --metafile=dist/human.esm-nobundle.json --outfile=dist/human.esm-nobundle.js src/human.js","build-node":"esbuild --bundle --platform=node --sourcemap --target=esnext --format=cjs --external:@tensorflow --metafile=dist/human.cjs.json --outfile=dist/human.cjs src/human.js",build:"rimraf dist/* && npm run build-iife && npm run build-esm-bundle && npm run build-esm-nobundle && npm run build-node && ls -l dist/",update:"npm update --depth 20 && npm dedupe && npm prune && npm audit",changelog:"node changelog.js"},keywords:["tensorflowjs","face-detection","face-geometry","body-tracking","hand-tracking","iris-tracking","age-estimation","emotion-detection","gender-prediction","gesture-recognition"]}});const R=require("@tensorflow/tfjs"),l0=ht(),de=mt(),Le=gt(),h0=jt(),u0=s0(),bn=r0(),le=a0().default,yn=d0();let m0=!0;const wn={face:{detector:{skipFrames:0},age:{skipFrames:0},emotion:{skipFrames:0}},hand:{skipFrames:0}},I=()=>typeof performance!="undefined"?performance.now():parseInt(Number(process.hrtime.bigint())/1e3/1e3);function he(...e){const t=o=>o&&typeof o=="object";return e.reduce((o,n)=>(Object.keys(n||{}).forEach(s=>{const i=o[s],a
|
2020-10-15 14:16:34 +02:00
|
|
|
//# sourceMappingURL=human.esm-nobundle.js.map
|