2020-11-08 07:17:25 +01:00
|
|
|
var a1=Object.defineProperty,q0=e=>a1(e,"__esModule",{value:!0}),g=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),ye=(e,t)=>{q0(e);for(var n in t)a1(e,n,{get:t[n],enumerable:!0})},m1=g(we=>{const b=require("@tensorflow/tfjs"),l1=6;function W0(e){const t={strides:[e/16,e/8],anchors:[2,6]},n=[];for(let r=0;r<t.strides.length;r++){const c=t.strides[r],_=Math.floor((e+c-1)/c),o=Math.floor((e+c-1)/c),h=t.anchors[r];for(let s=0;s<_;s++){const x=c*(s+.5);for(let w=0;w<o;w++){const l=c*(w+.5);for(let y=0;y<h;y++)n.push([l,x])}}}return n}const d1=e=>{e.startEndTensor.dispose(),e.startPoint.dispose(),e.endPoint.dispose()},u1=e=>({startEndTensor:e,startPoint:b.slice(e,[0,0],[-1,2]),endPoint:b.slice(e,[0,2],[-1,2])}),f1=(e,t)=>{const n=b.mul(e.startPoint,t),r=b.mul(e.endPoint,t),c=b.concat2d([n,r],1);return u1(c)};function G0(e,t,n){const r=b.slice(e,[0,1],[-1,2]),c=b.add(r,t),_=b.slice(e,[0,3],[-1,2]),o=b.div(_,n),h=b.div(c,n),s=b.div(o,2),x=b.sub(h,s),w=b.add(h,s),l=b.mul(x,n),y=b.mul(w,n),i=1;return b.concat2d([l,y],i)}function X0(e,t){return b.tidy(()=>{const n=e.box?e.box:e;return f1(n,t).startEndTensor.squeeze()})}class p1{constructor(e,t){this.blazeFaceModel=e,this.width=t.detector.inputSize,this.height=t.detector.inputSize,this.anchorsData=W0(t.detector.inputSize),this.anchors=b.tensor2d(this.anchorsData),this.inputSize=b.tensor1d([this.width,this.height]),this.config=t,this.scaleFaces=.8}async getBoundingBoxes(e){if(!e||e.isDisposedInternal||e.shape.length!==4||e.shape[1]<1||e.shape[2]<1)return null;const[t,n,r]=b.tidy(()=>{const x=e.resizeBilinear([this.width,this.height]),w=b.sub(x.div(127.5),1),l=this.blazeFaceModel.predict(w);let y;if(Array.isArray(l)){const E=l.sort((L,d)=>L.size-d.size),v=b.concat([E[0],E[2]],2),I=b.concat([E[1],E[3]],2),F=b.concat([I,v],1);y=F.squeeze(0)}else y=l.squeeze();const i=G0(y,this.anchors,this.inputSize),f=b.slice(y,[0,0],[-1,1]),m=f.squeeze();return[y,i,m]}),c=await b.image.nonMaxSuppressionAsync(n,r,this.config.detector.maxFaces,this.config.detector.iouThreshold,this.config.detector.scoreThreshold),_=c.arraySync();c.dispose();const o=_.map(x=>b.slice(n,[x,0],[1,-1])),h=o.map(x=>{const w=x.arraySync();return x.dispose(),w}),s=[];for(let x=0;x<h.length;x++){const w=h[x],l=u1(w),y=_[x],i=this.anchorsData[y],f=b.slice(t,[y,l1-1],[1,-1]),m=f.squeeze(),E=m.reshape([l1,-1]),v=b.slice(r,[y],[1]),I={box:l,landmarks:E,probability:v,anchor:i};s.push(I),f.dispose(),m.dispose()}return t.dispose(),n.dispose(),r.dispose(),t.dispose(),{boxes:s,scaleFactor:[e.shape[2]/this.width,e.shape[1]/this.height]}}async estimateFaces(e){const{boxes:t,scaleFactor:n}=await this.getBoundingBoxes(e),r=[];for(const c of t){const _=c.landmarks.arraySync(),o=X0(c,n),h=f1.arraySync(),s=c.probability.arraySync(),x=c.anchor,[w,l]=n,y=_.map(f=>[(f[0]+x[0])*w,(f[1]+x[1])*l]),i={topLeft:h.slice(0,2),bottomRight:h.slice(2),landmarks:y,probability:s};d1(c.box),c.landmarks.dispose(),c.probability.dispose(),o.dispose(),r.push(i)}return r}}async function Y0(e){const t=await b.loadGraphModel(e.detector.modelPath,{fromTFHub:e.detector.modelPath.includes("tfhub.dev")}),n=new p1(t,e);return console.log(`Human: load model: ${e.detector.modelPath.match(/\/(.*)\./)[1]}`),n}we.load=Y0;we.BlazeFaceModel=p1;we.disposeBox=d1}),Ee=g(be=>{be.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,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65
|
|
|
|
`),L.FRAGMENT_IDENTITY=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","void main(void) {","gl_FragColor = texture2D(texture, vUv);","}"].join(`
|
|
|
|
`);let d={};d.colorMatrix=function(u){const a=new Float32Array(u);a[4]/=255,a[9]/=255,a[14]/=255,a[19]/=255;const p=a[18]===1&&a[3]===0&&a[8]===0&&a[13]===0&&a[15]===0&&a[16]===0&&a[17]===0&&a[19]===0?d.colorMatrix.SHADER.WITHOUT_ALPHA:d.colorMatrix.SHADER.WITH_ALPHA,P=I(p);i.uniform1fv(P.uniform.m,a),v()},d.colorMatrix.SHADER={},d.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-11-07 17:34:56 +01:00
|
|
|
`),d.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-11-08 07:17:25 +01:00
|
|
|
`),d.brightness=function(u){const a=(u||0)+1;d.colorMatrix([a,0,0,0,0,0,a,0,0,0,0,0,a,0,0,0,0,0,1,0])},d.saturation=function(u){const a=(u||0)*2/3+1,p=(a-1)*-.5;d.colorMatrix([a,p,p,0,0,p,a,p,0,0,p,p,a,0,0,0,0,0,1,0])},d.desaturate=function(){d.saturation(-1)},d.contrast=function(u){const a=(u||0)+1,p=-128*(a-1);d.colorMatrix([a,0,0,0,p,0,a,0,0,p,0,0,a,0,p,0,0,0,1,0])},d.negative=function(){d.contrast(-2)},d.hue=function(u){u=(u||0)/180*Math.PI;const a=Math.cos(u),p=Math.sin(u),P=.213,R=.715,z=.072;d.colorMatrix([P+a*(1-P)+p*-P,R+a*-R+p*-R,z+a*-z+p*(1-z),0,0,P+a*-P+p*.143,R+a*(1-R)+p*.14,z+a*-z+p*-.283,0,0,P+a*-P+p*-(1-P),R+a*-R+p*R,z+a*(1-z)+p*z,0,0,0,0,0,1,0])},d.desaturateLuminance=function(){d.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},d.sepia=function(){d.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},d.brownie=function(){d.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},d.vintagePinhole=function(){d.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},d.kodachrome=function(){d.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])},d.technicolor=function(){d.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])},d.polaroid=function(){d.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},d.shiftToBGR=function(){d.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},d.convolution=function(u){const a=new Float32Array(u),p=1/h,P=1/s,R=I(d.convolution.SHADER);i.uniform1fv(R.uniform.m,a),i.uniform2f(R.uniform.px,p,P),v()},d.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(`
|
|
|
|
`),d.detectEdges=function(){d.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},d.sobelX=function(){d.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},d.sobelY=function(){d.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},d.sharpen=function(u){const a=u||1;d.convolution.call(this,[0,-1*a,0,-1*a,1+4*a,-1*a,0,-1*a,0])},d.emboss=function(u){const a=u||1;d.convolution.call(this,[-2*a,-1*a,0,-1*a,1,1*a,0,1*a,2*a])},d.blur=function(u){const a=u/7/h,p=u/7/s,P=I(d.blur.SHADER);i.uniform2f(P.uniform.px,0,p),v(F.INTERMEDIATE),i.uniform2f(P.uniform.px,a,0),v()},d.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(`
|
|
|
|
`),d.pixelate=function(u){const a=u/h,p=u/s,P=I(d.pixelate.SHADER);i.uniform2f(P.uniform.size,a,p),v()},d.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(`
|
2020-11-08 15:56:02 +01:00
|
|
|
`)};I0.Canvas=Wn}),k0=g(R0=>{const oe=require("@tensorflow/tfjs"),Gn=M0();let M=null,k=null;function Xn(e,t){let n;if(e instanceof oe.Tensor)n=oe.clone(e);else{const r=e.naturalWidth||e.videoWidth||e.width||e.shape&&e.shape[1]>0,c=e.naturalHeight||e.videoHeight||e.height||e.shape&&e.shape[2]>0;let _=r,o=c;t.filter.width>0?_=t.filter.width:t.filter.height>0&&(_=r*(t.filter.height/c)),t.filter.height>0?o=t.filter.height:t.filter.width>0&&(o=c*(t.filter.width/r)),(!M||M.width!==_||M.height!==o)&&(M=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(_,o):document.createElement("canvas"),M.width!==_&&(M.width=_),M.height!==o&&(M.height=o));const h=M.getContext("2d");e instanceof ImageData?h.putImageData(e,0,0):h.drawImage(e,0,0,r,c,0,0,M.width,M.height),t.filter.enabled&&((!this.fx||!k||M.width!==k.width||M.height!==k.height)&&(k=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(M.width,M.height):document.createElement("canvas"),k.width!==M.width&&(k.width=M.width),k.height!==M.height&&(k.height=M.height),this.fx=oe.ENV.flags.IS_BROWSER?new Gn.Canvas({canvas:k}):null),this.fx.reset(),this.fx.addFilter("brightness",t.filter.brightness),t.filter.contrast!==0&&this.fx.addFilter("contrast",t.filter.contrast),t.filter.sharpness!==0&&this.fx.addFilter("sharpen",t.filter.sharpness),t.filter.blur!==0&&this.fx.addFilter("blur",t.filter.blur),t.filter.saturation!==0&&this.fx.addFilter("saturation",t.filter.saturation),t.filter.hue!==0&&this.fx.addFilter("hue",t.filter.hue),t.filter.negative&&this.fx.addFilter("negative"),t.filter.sepia&&this.fx.addFilter("sepia"),t.filter.vintage&&this.fx.addFilter("brownie"),t.filter.sepia&&this.fx.addFilter("sepia"),t.filter.kodachrome&&this.fx.addFilter("kodachrome"),t.filter.technicolor&&this.fx.addFilter("technicolor"),t.filter.polaroid&&this.fx.addFilter("polaroid"),t.filter.pixelate!==0&&this.fx.addFilter("pixelate",t.filter.pixelate),this.fx.apply(M)),k||(k=M);let s;if(t.backend==="webgl"||k instanceof ImageData)s=oe.browser.fromPixels(k);else{const w=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(_,o):document.createElement("canvas");w.width=_,w.height=o;const l=w.getContext("2d");l.drawImage(k,0,0);const y=l.getImageData(0,0,_,o);s=oe.browser.fromPixels(y)}const x=s.toFloat();n=x.expandDims(0),s.dispose(),x.dispose()}return{tensor:n,canvas:t.filter.return?k:null}}R0.process=Xn}),A0=g(Yn=>{ye(Yn,{default:()=>Vn});var Vn={backend:"webgl",console:!0,async:!0,profile:!1,deallocate:!1,scoped:!1,videoOptimized:!0,filter:{enabled:!0,width:0,height: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},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"../models/blazeface-back.json",inputSize:256,maxFaces:10,skipFrames:15,minConfidence:.1,iouThreshold:.1,scoreThreshold:.2},mesh:{enabled:!0,modelPath:"../models/facemesh.json",inputSize:192},iris:{enabled:!0,modelPath:"../models/iris.json",enlargeFactor:2.3,inputSize:64},age:{enabled:!0,modelPath:"../models/age-ssrnet-imdb.json",inputSize:64,skipFrames:15},gender:{enabled:!0,minConfidence:.1,modelPath:"../models/gender-ssrnet-imdb.json",inputSize:64,skipFrames:15},emotion:{enabled:!0,inputSize:64,minConfidence:.2,skipFrames:15,modelPath:"../models/emotion-large.json"}},body:{enabled:!0,modelPath:"../models/posenet.json",inputResolution:257,outputStride:16,maxDetections:10,scoreThreshold:.8,nmsRadius:20},hand:{enabled:!0,inputSize:256,skipFrames:15,minConfidence:.5,iouThreshold:.1,scoreThreshold:.8,enlargeFactor:1.65,maxHands:1,detector:{modelPath:"../models/handdetect.json"},skeleton:{modelPath:"../models/handskeleton.json"}}}}),F0=g((N5,B0)=>{B0.exports={name:"@vladmandic/human",version:"0.8.2",description:"human: 3D Face Detection, Body Pose, Hand & Finger Tracking, Iris Tracking, Age & Gender Prediction, Emotion Prediction & Gesture Recognition",sideEffects:!1,main:"dist/human.node.js",module:"dist/human.esm.js",browser:"dist/human.esm.js",author:"Vladimir Mandic <mandic00@live.com>",bugs:{url:"https://github.com/vladm
|
2020-11-04 07:11:24 +01:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2020-10-15 14:16:34 +02:00
|
|
|
//# sourceMappingURL=human.esm-nobundle.js.map
|