@100mslive/hms-virtual-background 1.7.1-alpha.2 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var W=Object.create;var M=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var B=s=>M(s,"__esModule",{value:!0});var q=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),J=(s,t)=>{B(s);for(var e in t)M(s,e,{get:t[e],enumerable:!0})},Y=(s,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $(t))!z.call(s,i)&&i!=="default"&&M(s,i,{get:()=>t[i],enumerable:!(e=N(t,i))||e.enumerable});return s},L=s=>Y(B(M(s!=null?W(U(s)):{},"default",s&&s.__esModule&&"default"in s?{get:()=>s.default,enumerable:!0}:{value:s,enumerable:!0})),s);var u=(s,t,e)=>new Promise((i,a)=>{var n=h=>{try{r(e.next(h))}catch(l){a(l)}},o=h=>{try{r(e.throw(h))}catch(l){a(l)}},r=h=>h.done?i(h.value):Promise.resolve(h.value).then(n,o);r((e=e.apply(s,t)).next())});var E=q((ut,Q)=>{Q.exports={version:"1.7.1-alpha.2",license:"MIT",main:"dist/index.js",typings:"dist/index.d.ts",files:["dist","src/tflite","src/models"],scripts:{start:'concurrently "yarn dev" "yarn types"',dev:"node ../../scripts/dev","build:only":"node ../../scripts/build",build:"yarn build:only && yarn types:build",types:"tsc -w","types:build":"tsc -p tsconfig.json",test:"jest --maxWorkers=1 --passWithNoTests",lint:"eslint -c ../../.eslintrc .","lint:fix":"yarn lint --fix",prepare:"yarn build",size:"size-limit",analyze:"size-limit --why",format:"prettier --write src/**/*.ts"},peerDependencies:{"@100mslive/hms-video":"^0.5.0"},name:"@100mslive/hms-virtual-background",author:"ashish17",module:"dist/index.js",devDependencies:{"@100mslive/hms-video":"0.5.1-alpha.2"},dependencies:{"@tensorflow/tfjs-backend-webgl":"^3.3.0","@tensorflow/tfjs-core":"^3.3.0","@webassemblyjs/helper-wasm-bytecode":"1.11.1","@webassemblyjs/wasm-gen":"1.11.1","gifuct-js":"^2.1.2","wasm-check":"^2.0.2"},eslintIgnore:["tflite.js","tflite-simd.js","tflite.wasm","tflite-simd.wasm","defineTFLite.ts","importing.test.ts"],gitHead:"7450dfa08f3ccf63a603a62c70eafbbeea26ab1e"}});J(exports,{HMSVirtualBackgroundPlugin:()=>_});var K=E(),V=`https://unpkg.com/${K.name}/src`,y="VBProcessor",X="tflite/tflite.js",Z="tflite/tflite-simd.js",tt="models/selfie_segmentation_landscape.tflite",A=s=>new Promise(function(t,e){let i=document.createElement("script");i.src=s,i.onload=t,i.onerror=e,document.head.appendChild(i)}),et=()=>u(void 0,null,function*(){let s,t=`${V}/${Z}`;yield A(t);try{s=yield createTFLiteSIMDModule()}catch(e){console.warn("SIMD not supported. You may experience poor virtual background effect."),t=`${V}/${X}`,yield A(t),s=yield createTFLiteModule()}return s}),O=()=>u(void 0,null,function*(){let s=`${V}/${tt}`,[t,e]=yield Promise.all([et(),fetch(s)]),i=yield e.arrayBuffer(),a=t._getModelBufferMemoryOffset();return t.HEAPU8.set(new Uint8Array(i),a),t._loadModel(i.byteLength),console.debug(y,"Input memory offset:",t._getInputMemoryOffset()),console.debug(y,"Input height:",t._getInputHeight()),console.debug(y,"Input width:",t._getInputWidth()),console.debug(y,"Input channels:",t._getInputChannelCount()),t});var gt=L(require("@tensorflow/tfjs-backend-webgl")),x=L(require("gifuct-js")),w=L(require("@100mslive/hms-video")),v="VBProcessor",it=33,st=E(),at=214,nt=855,ot=120,rt=720,_=class{constructor(t,e=!1){this.backgroundType="none";this.background=t,this.enableSharpening=e,this.backgroundImage=null,this.backgroundVideo=null,this.personMaskWidth=256,this.personMaskHeight=144,this.isVirtualBackground=!1,this.blurValue="10px",this.loadModelCalled=!1,this.tfLite=null,this.modelName="landscape-segmentation",this.outputCtx=null,this.input=null,this.output=null,this.timerID=0,this.imageAspectRatio=1,this.personMaskPixelCount=this.personMaskWidth*this.personMaskHeight,this.personMask=new ImageData(this.personMaskWidth,this.personMaskHeight),this.personMaskCanvas=document.createElement("canvas"),this.personMaskCanvas.width=this.personMaskWidth,this.personMaskCanvas.height=this.personMaskHeight,this.personMaskCtx=this.personMaskCanvas.getContext("2d"),this.filters={},this.gifFrames=null,this.gifFramesIndex=0,this.gifFrameImageData=null,this.tempGifCanvas=document.createElement("canvas"),this.tempGifContext=this.tempGifCanvas.getContext("2d"),this.giflocalCount=0,this.enableSharpening=e,this.log(v,"Virtual Background plugin created"),this.setBackground(this.background)}init(){return u(this,null,function*(){this.loadModelCalled?yield this.tfLitePromise:(this.log(v,"PREVIOUS LOADED MODEL IS ",this.tfLite),this.loadModelCalled=!0,this.tfLitePromise=O(),this.tfLite=yield this.tfLitePromise),this.enableSharpening&&this.initSharpenFilter()})}isSupported(){return navigator.userAgent.indexOf("Chrome")!==-1||navigator.userAgent.indexOf("Firefox")!==-1||navigator.userAgent.indexOf("Edg")!==-1||navigator.userAgent.indexOf("Edge")!==-1}checkSupport(){let t={};return["Chrome","Firefox","Edg","Edge"].some(e=>navigator.userAgent.indexOf(e)!==-1)?t.isSupported=!0:(t.isSupported=!1,t.errType=w.HMSPluginUnsupportedTypes.PLATFORM_NOT_SUPPORTED,t.errMsg="browser not supported for plugin, see docs"),t}getName(){return st.name}getPluginType(){return w.HMSVideoPluginType.TRANSFORM}setBackground(t){return u(this,null,function*(){if(t!=="")if(t==="none")this.log(v,"setting background to :",t),this.background="none",this.backgroundType="none",this.isVirtualBackground=!1;else if(t==="blur")this.log(v,"setting background to :",t),this.background="blur",this.backgroundType="blur",this.isVirtualBackground=!1;else if(t instanceof HTMLImageElement){this.log("setting background to image",t);let e=yield this.setImage(t);if(!e||!e.complete||!e.naturalHeight)throw new Error("Invalid image. Provide a valid and successfully loaded HTMLImageElement");this.isVirtualBackground=!0,this.backgroundImage=e,this.backgroundType="image"}else if(t instanceof HTMLVideoElement)this.log("setting background to video",t),this.backgroundVideo=t,this.backgroundVideo.crossOrigin="anonymous",this.backgroundVideo.muted=!0,this.backgroundVideo.loop=!0,this.backgroundVideo.oncanplaythrough=()=>u(this,null,function*(){this.backgroundVideo!=null&&(yield this.backgroundVideo.play(),this.isVirtualBackground=!0,this.backgroundType="video")});else if(console.log("setting gif to background"),this.gifFrames=yield this.setGiF(t),this.gifFrames!=null&&this.gifFrames.length>0)this.backgroundType="gif",this.isVirtualBackground=!0;else throw new Error("Invalid background supplied, see the docs to check supported background type");else throw new Error("Invalid background supplied, see the docs to check supported background type")})}stop(){var t,e;this.isVirtualBackground&&((t=this.backgroundImage)==null||t.removeAttribute("src"),(e=this.backgroundVideo)==null||e.removeAttribute("src"),this.backgroundType==="video"&&(this.backgroundVideo.loop=!1,this.backgroundVideo=null)),this.outputCtx&&(this.outputCtx.fillStyle="rgb(0, 0, 0)",this.outputCtx.fillRect(0,0,this.output.width,this.output.height)),this.gifFrameImageData=null,this.gifFrames=null,this.giflocalCount=0,this.gifFramesIndex=0}processVideoFrame(t,e,i){if(!t||!e)throw new Error("Plugin invalid input/output");this.input=t,this.output=e;let a=e.getContext("2d");if(a.canvas.width!==t.width&&(a.canvas.width=t.width),a.canvas.height!==t.height&&(a.canvas.height=t.height),this.backgroundType==="video"&&(this.backgroundVideo.width=t.width,this.backgroundVideo.height=t.height),this.outputCtx=a,this.imageAspectRatio=t.width/t.height,this.imageAspectRatio<=0)throw new Error("Invalid input width/height");let n=()=>u(this,null,function*(){yield this.runSegmentation(i)});this.background==="none"&&!this.isVirtualBackground?(this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.outputCtx.drawImage(t,0,0,t.width,t.height)):n()}setImage(t){return u(this,null,function*(){return t.crossOrigin="anonymous",new Promise((e,i)=>{t.onload=()=>e(t),t.onerror=i})})}setGiF(t){return fetch(t).then(e=>e.arrayBuffer()).then(e=>(0,x.parseGIF)(e)).then(e=>(0,x.decompressFrames)(e,!0))}log(t,...e){console.info(t,...e)}resizeInputData(){this.personMaskCtx.drawImage(this.input,0,0,this.input.width,this.input.height,0,0,this.personMaskWidth,this.personMaskHeight);let t=this.personMaskCtx.getImageData(0,0,this.personMaskWidth,this.personMaskHeight),e=this.tfLite._getInputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)this.tfLite.HEAPF32[e+i*3]=t.data[i*4]/255,this.tfLite.HEAPF32[e+i*3+1]=t.data[i*4+1]/255,this.tfLite.HEAPF32[e+i*3+2]=t.data[i*4+2]/255}infer(t){t||this.tfLite._runInference();let e=this.tfLite._getOutputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)if(this.modelName==="meet"){let a=this.tfLite.HEAPF32[e+i*2],n=this.tfLite.HEAPF32[e+i*2+1],o=Math.max(a,n),r=Math.exp(a-o),h=Math.exp(n-o);this.personMask.data[i*4+3]=255*h/(r+h)}else if(this.modelName==="landscape-segmentation"){let a=this.tfLite.HEAPF32[e+i];this.personMask.data[i*4+3]=255*a}this.personMaskCtx.putImageData(this.personMask,0,0)}postProcessing(){this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.isVirtualBackground?this.outputCtx.filter="blur(4px)":this.outputCtx.filter="blur(8px)",this.drawPersonMask(),this.outputCtx.globalCompositeOperation="source-in",this.outputCtx.filter="none",this.outputCtx.drawImage(this.input,0,0),this.enableSharpening&&this.output.width>at&&this.output.height>ot&&this.output.width<nt&&this.output.height<rt&&this.sharpenFilter(),this.drawSegmentedBackground()}sharpenFilter(){let t=this.outputCtx.getImageData(0,0,this.output.width,this.output.height),e=this.filters.convolute(t);this.outputCtx.putImageData(e,0,0)}drawPersonMask(){this.outputCtx.drawImage(this.personMaskCanvas,0,0,this.personMaskWidth,this.personMaskHeight,0,0,this.output.width,this.output.height)}drawSegmentedBackground(){this.outputCtx.globalCompositeOperation="destination-over",this.outputCtx.imageSmoothingEnabled=!0,this.outputCtx.imageSmoothingQuality="high",this.isVirtualBackground?this.backgroundType==="video"&&this.backgroundVideo!=null&&this.backgroundVideo.readyState>=4?this.fitVideoToBackground():this.backgroundType==="image"?this.fitImageToBackground():this.backgroundType==="gif"&&(this.giflocalCount>this.gifFrames[this.gifFramesIndex].delay/it?(this.gifFramesIndex++,this.gifFramesIndex>=this.gifFrames.length&&(this.gifFramesIndex=0),this.giflocalCount=0):this.giflocalCount++,this.fitGifToBackground()):this.addBlurToBackground()}runSegmentation(t){return u(this,null,function*(){this.tfLite&&(this.resizeInputData(),yield this.infer(t),this.postProcessing())})}fitVideoToBackground(){this.fitData(this.backgroundVideo,this.backgroundVideo.videoWidth,this.backgroundVideo.videoHeight)}fitImageToBackground(){this.fitData(this.backgroundImage,this.backgroundImage.width,this.backgroundImage.height)}fitGifToBackground(){if(this.gifFrameImageData==null){let t=this.gifFrames[this.gifFramesIndex].dims;this.tempGifCanvas.width=t.width,this.tempGifCanvas.height=t.height,this.gifFrameImageData=this.tempGifContext.createImageData(t.width,t.height)}this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch),this.tempGifContext.putImageData(this.gifFrameImageData,0,0),this.fitData(this.tempGifCanvas,this.gifFrameImageData.width,this.gifFrameImageData.height)}fitData(t,e,i){let a,n,o,r;e/i<this.imageAspectRatio?(a=e,n=e/this.imageAspectRatio,o=0,r=(i-n)/2):(n=i,a=i*this.imageAspectRatio,r=0,o=(e-a)/2),this.outputCtx.drawImage(t,o,r,a,n,0,0,this.output.width,this.output.height)}addBlurToBackground(){return u(this,null,function*(){let t="15px";this.input.width<=160?t="5px":this.input.width<=320?t="10px":this.input.width<=640?t="15px":this.input.width<=960?t="20px":this.input.width<=1280?t="25px":this.input.width<=1920&&(t="30px"),this.outputCtx.filter=`blur(${t})`,this.outputCtx.drawImage(this.input,0,0,this.output.width,this.output.height)})}initSharpenFilter(){this.filters.tmpCanvas=document.createElement("canvas"),this.filters.tmpCtx=this.filters.tmpCanvas.getContext("2d"),this.filters.createImageData=(t,e)=>this.filters.tmpCtx.createImageData(t,e),this.filters.convolute=(t,e=[0,-1,0,-1,5,-1,0,-1,0],i)=>{let a=Math.round(Math.sqrt(e.length)),n=Math.floor(a/2),o=t.data,r=t.width,h=t.height,l=r,I=h,S=this.filters.createImageData(l,I),p=S.data,R=i?1:0;for(let d=0;d<I;d=d+1)for(let g=0;g<l;g=g+1){let c=(d*l+g)*4;if(o[c+3]!==0&&g<l&&d<I){let j=d,G=g,H=0,P=0,D=0,C=0;for(let m=0;m<a;m++)for(let f=0;f<a;f++){let F=j+m-n,T=G+f-n;if(F>=0&&F<h&&T>=0&&T<r){let k=(F*r+T)*4,b=e[m*a+f];H+=o[k]*b,P+=o[k+1]*b,D+=o[k+2]*b,C+=o[k+3]*b}}p[c]=H,p[c+1]=P,p[c+2]=D,p[c+3]=C+R*(255-C)}}return S}}};
|
|
1
|
+
var W=Object.create;var M=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var B=s=>M(s,"__esModule",{value:!0});var q=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),J=(s,t)=>{B(s);for(var e in t)M(s,e,{get:t[e],enumerable:!0})},Y=(s,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $(t))!z.call(s,i)&&i!=="default"&&M(s,i,{get:()=>t[i],enumerable:!(e=N(t,i))||e.enumerable});return s},L=s=>Y(B(M(s!=null?W(U(s)):{},"default",s&&s.__esModule&&"default"in s?{get:()=>s.default,enumerable:!0}:{value:s,enumerable:!0})),s);var u=(s,t,e)=>new Promise((i,a)=>{var n=h=>{try{r(e.next(h))}catch(l){a(l)}},o=h=>{try{r(e.throw(h))}catch(l){a(l)}},r=h=>h.done?i(h.value):Promise.resolve(h.value).then(n,o);r((e=e.apply(s,t)).next())});var E=q((ut,Q)=>{Q.exports={version:"1.7.1",license:"MIT",main:"dist/index.js",typings:"dist/index.d.ts",files:["dist","src/tflite","src/models"],scripts:{start:'concurrently "yarn dev" "yarn types"',dev:"node ../../scripts/dev","build:only":"node ../../scripts/build",build:"yarn build:only && yarn types:build",types:"tsc -w","types:build":"tsc -p tsconfig.json",test:"jest --maxWorkers=1 --passWithNoTests",lint:"eslint -c ../../.eslintrc .","lint:fix":"yarn lint --fix",prepare:"yarn build",size:"size-limit",analyze:"size-limit --why",format:"prettier --write src/**/*.ts"},peerDependencies:{"@100mslive/hms-video":"^0.2.0"},name:"@100mslive/hms-virtual-background",author:"ashish17",module:"dist/index.js",devDependencies:{"@100mslive/hms-video":"0.5.1"},dependencies:{"@tensorflow/tfjs-backend-webgl":"^3.3.0","@tensorflow/tfjs-core":"^3.3.0","@webassemblyjs/helper-wasm-bytecode":"1.11.1","@webassemblyjs/wasm-gen":"1.11.1","gifuct-js":"^2.1.2","wasm-check":"^2.0.2"},eslintIgnore:["tflite.js","tflite-simd.js","tflite.wasm","tflite-simd.wasm","defineTFLite.ts","importing.test.ts"],gitHead:"2b27a0da2da14570ec448b6ff8486dff12b7eb4d"}});J(exports,{HMSVirtualBackgroundPlugin:()=>_});var K=E(),V=`https://unpkg.com/${K.name}/src`,y="VBProcessor",X="tflite/tflite.js",Z="tflite/tflite-simd.js",tt="models/selfie_segmentation_landscape.tflite",A=s=>new Promise(function(t,e){let i=document.createElement("script");i.src=s,i.onload=t,i.onerror=e,document.head.appendChild(i)}),et=()=>u(void 0,null,function*(){let s,t=`${V}/${Z}`;yield A(t);try{s=yield createTFLiteSIMDModule()}catch(e){console.warn("SIMD not supported. You may experience poor virtual background effect."),t=`${V}/${X}`,yield A(t),s=yield createTFLiteModule()}return s}),O=()=>u(void 0,null,function*(){let s=`${V}/${tt}`,[t,e]=yield Promise.all([et(),fetch(s)]),i=yield e.arrayBuffer(),a=t._getModelBufferMemoryOffset();return t.HEAPU8.set(new Uint8Array(i),a),t._loadModel(i.byteLength),console.debug(y,"Input memory offset:",t._getInputMemoryOffset()),console.debug(y,"Input height:",t._getInputHeight()),console.debug(y,"Input width:",t._getInputWidth()),console.debug(y,"Input channels:",t._getInputChannelCount()),t});var gt=L(require("@tensorflow/tfjs-backend-webgl")),x=L(require("gifuct-js")),w=L(require("@100mslive/hms-video")),v="VBProcessor",it=33,st=E(),at=214,nt=855,ot=120,rt=720,_=class{constructor(t,e=!1){this.backgroundType="none";this.background=t,this.enableSharpening=e,this.backgroundImage=null,this.backgroundVideo=null,this.personMaskWidth=256,this.personMaskHeight=144,this.isVirtualBackground=!1,this.blurValue="10px",this.loadModelCalled=!1,this.tfLite=null,this.modelName="landscape-segmentation",this.outputCtx=null,this.input=null,this.output=null,this.timerID=0,this.imageAspectRatio=1,this.personMaskPixelCount=this.personMaskWidth*this.personMaskHeight,this.personMask=new ImageData(this.personMaskWidth,this.personMaskHeight),this.personMaskCanvas=document.createElement("canvas"),this.personMaskCanvas.width=this.personMaskWidth,this.personMaskCanvas.height=this.personMaskHeight,this.personMaskCtx=this.personMaskCanvas.getContext("2d"),this.filters={},this.gifFrames=null,this.gifFramesIndex=0,this.gifFrameImageData=null,this.tempGifCanvas=document.createElement("canvas"),this.tempGifContext=this.tempGifCanvas.getContext("2d"),this.giflocalCount=0,this.enableSharpening=e,this.log(v,"Virtual Background plugin created"),this.setBackground(this.background)}init(){return u(this,null,function*(){this.loadModelCalled?yield this.tfLitePromise:(this.log(v,"PREVIOUS LOADED MODEL IS ",this.tfLite),this.loadModelCalled=!0,this.tfLitePromise=O(),this.tfLite=yield this.tfLitePromise),this.enableSharpening&&this.initSharpenFilter()})}isSupported(){return navigator.userAgent.indexOf("Chrome")!==-1||navigator.userAgent.indexOf("Firefox")!==-1||navigator.userAgent.indexOf("Edg")!==-1||navigator.userAgent.indexOf("Edge")!==-1}checkSupport(){let t={};return["Chrome","Firefox","Edg","Edge"].some(e=>navigator.userAgent.indexOf(e)!==-1)?t.isSupported=!0:(t.isSupported=!1,t.errType=w.HMSPluginUnsupportedTypes.PLATFORM_NOT_SUPPORTED,t.errMsg="browser not supported for plugin, see docs"),t}getName(){return st.name}getPluginType(){return w.HMSVideoPluginType.TRANSFORM}setBackground(t){return u(this,null,function*(){if(t!=="")if(t==="none")this.log(v,"setting background to :",t),this.background="none",this.backgroundType="none",this.isVirtualBackground=!1;else if(t==="blur")this.log(v,"setting background to :",t),this.background="blur",this.backgroundType="blur",this.isVirtualBackground=!1;else if(t instanceof HTMLImageElement){this.log("setting background to image",t);let e=yield this.setImage(t);if(!e||!e.complete||!e.naturalHeight)throw new Error("Invalid image. Provide a valid and successfully loaded HTMLImageElement");this.isVirtualBackground=!0,this.backgroundImage=e,this.backgroundType="image"}else if(t instanceof HTMLVideoElement)this.log("setting background to video",t),this.backgroundVideo=t,this.backgroundVideo.crossOrigin="anonymous",this.backgroundVideo.muted=!0,this.backgroundVideo.loop=!0,this.backgroundVideo.oncanplaythrough=()=>u(this,null,function*(){this.backgroundVideo!=null&&(yield this.backgroundVideo.play(),this.isVirtualBackground=!0,this.backgroundType="video")});else if(console.log("setting gif to background"),this.gifFrames=yield this.setGiF(t),this.gifFrames!=null&&this.gifFrames.length>0)this.backgroundType="gif",this.isVirtualBackground=!0;else throw new Error("Invalid background supplied, see the docs to check supported background type");else throw new Error("Invalid background supplied, see the docs to check supported background type")})}stop(){var t,e;this.isVirtualBackground&&((t=this.backgroundImage)==null||t.removeAttribute("src"),(e=this.backgroundVideo)==null||e.removeAttribute("src"),this.backgroundType==="video"&&(this.backgroundVideo.loop=!1,this.backgroundVideo=null)),this.outputCtx&&(this.outputCtx.fillStyle="rgb(0, 0, 0)",this.outputCtx.fillRect(0,0,this.output.width,this.output.height)),this.gifFrameImageData=null,this.gifFrames=null,this.giflocalCount=0,this.gifFramesIndex=0}processVideoFrame(t,e,i){if(!t||!e)throw new Error("Plugin invalid input/output");this.input=t,this.output=e;let a=e.getContext("2d");if(a.canvas.width!==t.width&&(a.canvas.width=t.width),a.canvas.height!==t.height&&(a.canvas.height=t.height),this.backgroundType==="video"&&(this.backgroundVideo.width=t.width,this.backgroundVideo.height=t.height),this.outputCtx=a,this.imageAspectRatio=t.width/t.height,this.imageAspectRatio<=0)throw new Error("Invalid input width/height");let n=()=>u(this,null,function*(){yield this.runSegmentation(i)});this.background==="none"&&!this.isVirtualBackground?(this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.outputCtx.drawImage(t,0,0,t.width,t.height)):n()}setImage(t){return u(this,null,function*(){return t.crossOrigin="anonymous",new Promise((e,i)=>{t.onload=()=>e(t),t.onerror=i})})}setGiF(t){return fetch(t).then(e=>e.arrayBuffer()).then(e=>(0,x.parseGIF)(e)).then(e=>(0,x.decompressFrames)(e,!0))}log(t,...e){console.info(t,...e)}resizeInputData(){this.personMaskCtx.drawImage(this.input,0,0,this.input.width,this.input.height,0,0,this.personMaskWidth,this.personMaskHeight);let t=this.personMaskCtx.getImageData(0,0,this.personMaskWidth,this.personMaskHeight),e=this.tfLite._getInputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)this.tfLite.HEAPF32[e+i*3]=t.data[i*4]/255,this.tfLite.HEAPF32[e+i*3+1]=t.data[i*4+1]/255,this.tfLite.HEAPF32[e+i*3+2]=t.data[i*4+2]/255}infer(t){t||this.tfLite._runInference();let e=this.tfLite._getOutputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)if(this.modelName==="meet"){let a=this.tfLite.HEAPF32[e+i*2],n=this.tfLite.HEAPF32[e+i*2+1],o=Math.max(a,n),r=Math.exp(a-o),h=Math.exp(n-o);this.personMask.data[i*4+3]=255*h/(r+h)}else if(this.modelName==="landscape-segmentation"){let a=this.tfLite.HEAPF32[e+i];this.personMask.data[i*4+3]=255*a}this.personMaskCtx.putImageData(this.personMask,0,0)}postProcessing(){this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.isVirtualBackground?this.outputCtx.filter="blur(4px)":this.outputCtx.filter="blur(8px)",this.drawPersonMask(),this.outputCtx.globalCompositeOperation="source-in",this.outputCtx.filter="none",this.outputCtx.drawImage(this.input,0,0),this.enableSharpening&&this.output.width>at&&this.output.height>ot&&this.output.width<nt&&this.output.height<rt&&this.sharpenFilter(),this.drawSegmentedBackground()}sharpenFilter(){let t=this.outputCtx.getImageData(0,0,this.output.width,this.output.height),e=this.filters.convolute(t);this.outputCtx.putImageData(e,0,0)}drawPersonMask(){this.outputCtx.drawImage(this.personMaskCanvas,0,0,this.personMaskWidth,this.personMaskHeight,0,0,this.output.width,this.output.height)}drawSegmentedBackground(){this.outputCtx.globalCompositeOperation="destination-over",this.outputCtx.imageSmoothingEnabled=!0,this.outputCtx.imageSmoothingQuality="high",this.isVirtualBackground?this.backgroundType==="video"&&this.backgroundVideo!=null&&this.backgroundVideo.readyState>=4?this.fitVideoToBackground():this.backgroundType==="image"?this.fitImageToBackground():this.backgroundType==="gif"&&(this.giflocalCount>this.gifFrames[this.gifFramesIndex].delay/it?(this.gifFramesIndex++,this.gifFramesIndex>=this.gifFrames.length&&(this.gifFramesIndex=0),this.giflocalCount=0):this.giflocalCount++,this.fitGifToBackground()):this.addBlurToBackground()}runSegmentation(t){return u(this,null,function*(){this.tfLite&&(this.resizeInputData(),yield this.infer(t),this.postProcessing())})}fitVideoToBackground(){this.fitData(this.backgroundVideo,this.backgroundVideo.videoWidth,this.backgroundVideo.videoHeight)}fitImageToBackground(){this.fitData(this.backgroundImage,this.backgroundImage.width,this.backgroundImage.height)}fitGifToBackground(){if(this.gifFrameImageData==null){let t=this.gifFrames[this.gifFramesIndex].dims;this.tempGifCanvas.width=t.width,this.tempGifCanvas.height=t.height,this.gifFrameImageData=this.tempGifContext.createImageData(t.width,t.height)}this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch),this.tempGifContext.putImageData(this.gifFrameImageData,0,0),this.fitData(this.tempGifCanvas,this.gifFrameImageData.width,this.gifFrameImageData.height)}fitData(t,e,i){let a,n,o,r;e/i<this.imageAspectRatio?(a=e,n=e/this.imageAspectRatio,o=0,r=(i-n)/2):(n=i,a=i*this.imageAspectRatio,r=0,o=(e-a)/2),this.outputCtx.drawImage(t,o,r,a,n,0,0,this.output.width,this.output.height)}addBlurToBackground(){return u(this,null,function*(){let t="15px";this.input.width<=160?t="5px":this.input.width<=320?t="10px":this.input.width<=640?t="15px":this.input.width<=960?t="20px":this.input.width<=1280?t="25px":this.input.width<=1920&&(t="30px"),this.outputCtx.filter=`blur(${t})`,this.outputCtx.drawImage(this.input,0,0,this.output.width,this.output.height)})}initSharpenFilter(){this.filters.tmpCanvas=document.createElement("canvas"),this.filters.tmpCtx=this.filters.tmpCanvas.getContext("2d"),this.filters.createImageData=(t,e)=>this.filters.tmpCtx.createImageData(t,e),this.filters.convolute=(t,e=[0,-1,0,-1,5,-1,0,-1,0],i)=>{let a=Math.round(Math.sqrt(e.length)),n=Math.floor(a/2),o=t.data,r=t.width,h=t.height,l=r,I=h,S=this.filters.createImageData(l,I),p=S.data,R=i?1:0;for(let d=0;d<I;d=d+1)for(let g=0;g<l;g=g+1){let c=(d*l+g)*4;if(o[c+3]!==0&&g<l&&d<I){let j=d,G=g,H=0,P=0,D=0,C=0;for(let m=0;m<a;m++)for(let f=0;f<a;f++){let F=j+m-n,T=G+f-n;if(F>=0&&F<h&&T>=0&&T<r){let k=(F*r+T)*4,b=e[m*a+f];H+=o[k]*b,P+=o[k+1]*b,D+=o[k+2]*b,C+=o[k+3]*b}}p[c]=H,p[c+1]=P,p[c+2]=D,p[c+3]=C+R*(255-C)}}return S}}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/defineTFLite.ts", "../src/HMSVirtualBackgroundPlugin.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './HMSVirtualBackgroundPlugin';\n", "const pkg = require('../package.json');\nconst BASE_URL = `https://unpkg.com/${pkg.name}/src`;\nconst TAG = 'VBProcessor';\nconst TFLITE_JS_FILE = 'tflite/tflite.js';\nconst TFLITE_SIMD_JS_FILE = 'tflite/tflite-simd.js';\nconst MODEL_FILE_NAME = 'models/selfie_segmentation_landscape.tflite';\n\nconst loadScript = (src: string) => {\n return new Promise(function (resolve, reject) {\n const s = document.createElement('script');\n s.src = src;\n s.onload = resolve;\n s.onerror = reject;\n document.head.appendChild(s);\n });\n};\n\nconst loadTFLiteModel = async () => {\n let tfLite: any;\n let path = `${BASE_URL}/${TFLITE_SIMD_JS_FILE}`;\n await loadScript(path);\n try {\n //@ts-ignore\n tfLite = await createTFLiteSIMDModule();\n } catch {\n console.warn('SIMD not supported. You may experience poor virtual background effect.');\n path = `${BASE_URL}/${TFLITE_JS_FILE}`;\n await loadScript(path);\n // @ts-ignore\n tfLite = await createTFLiteModule();\n }\n return tfLite;\n};\n\nconst loadTFLite = async () => {\n const modelPath = `${BASE_URL}/${MODEL_FILE_NAME}`;\n const [tfLite, modelResponse] = await Promise.all([loadTFLiteModel(), fetch(modelPath)]);\n\n const model = await modelResponse.arrayBuffer();\n const modelBufferOffset = tfLite._getModelBufferMemoryOffset();\n tfLite.HEAPU8.set(new Uint8Array(model), modelBufferOffset);\n tfLite._loadModel(model.byteLength);\n\n console.debug(TAG, 'Input memory offset:', tfLite._getInputMemoryOffset());\n console.debug(TAG, 'Input height:', tfLite._getInputHeight());\n console.debug(TAG, 'Input width:', tfLite._getInputWidth());\n console.debug(TAG, 'Input channels:', tfLite._getInputChannelCount());\n\n return tfLite;\n};\n\nexport { loadTFLite };\n", "/* eslint-disable complexity */\nimport { loadTFLite } from './defineTFLite';\nimport '@tensorflow/tfjs-backend-webgl';\nimport { parseGIF, decompressFrames } from 'gifuct-js';\nimport {\n HMSPluginSupportResult,\n HMSPluginUnsupportedTypes,\n HMSVideoPlugin,\n HMSVideoPluginType,\n} from '@100mslive/hms-video';\n\nconst TAG = 'VBProcessor';\nconst DEFAULT_DELAY = 33;\nconst pkg = require('../package.json');\n\nconst minVideoWidthForSharpening = 214;\nconst maxVideoWidthForSharpening = 855;\nconst minVideoHeightForSharpening = 120;\nconst maxVideoHeightForSharpening = 720;\n\nexport class HMSVirtualBackgroundPlugin implements HMSVideoPlugin {\n background: string | HTMLImageElement;\n personMaskWidth: number;\n personMaskHeight: number;\n isVirtualBackground: boolean;\n backgroundImage: HTMLImageElement | null;\n backgroundVideo: HTMLVideoElement | null;\n backgroundType = 'none';\n loadModelCalled: boolean;\n blurValue: any;\n tfLite: any;\n tfLitePromise: any;\n modelName: string;\n\n input: HTMLCanvasElement | null;\n output: HTMLCanvasElement | null;\n outputCtx: CanvasRenderingContext2D | null;\n timerID: number;\n imageAspectRatio: number;\n\n personMaskPixelCount: number;\n personMask: ImageData;\n personMaskCanvas: HTMLCanvasElement;\n personMaskCtx: any;\n filters: any;\n enableSharpening?: boolean | false;\n\n gifFrames: any;\n gifFramesIndex: number;\n gifFrameImageData: any;\n tempGifCanvas: HTMLCanvasElement;\n tempGifContext: any;\n giflocalCount: number;\n\n constructor(background: string, enableSharpening = false) {\n this.background = background;\n this.enableSharpening = enableSharpening;\n\n this.backgroundImage = null;\n this.backgroundVideo = null;\n\n this.personMaskWidth = 256;\n this.personMaskHeight = 144;\n this.isVirtualBackground = false;\n this.blurValue = '10px';\n this.loadModelCalled = false;\n this.tfLite = null;\n this.modelName = 'landscape-segmentation';\n\n this.outputCtx = null;\n this.input = null;\n this.output = null;\n this.timerID = 0;\n this.imageAspectRatio = 1;\n\n this.personMaskPixelCount = this.personMaskWidth * this.personMaskHeight;\n this.personMask = new ImageData(this.personMaskWidth, this.personMaskHeight);\n this.personMaskCanvas = document.createElement('canvas');\n this.personMaskCanvas.width = this.personMaskWidth;\n this.personMaskCanvas.height = this.personMaskHeight;\n this.personMaskCtx = this.personMaskCanvas.getContext('2d');\n\n this.filters = {};\n this.gifFrames = null;\n this.gifFramesIndex = 0;\n this.gifFrameImageData = null;\n this.tempGifCanvas = document.createElement('canvas');\n this.tempGifContext = this.tempGifCanvas.getContext('2d');\n this.giflocalCount = 0;\n this.enableSharpening = enableSharpening;\n\n this.log(TAG, 'Virtual Background plugin created');\n this.setBackground(this.background);\n }\n\n async init(): Promise<void> {\n if (!this.loadModelCalled) {\n this.log(TAG, 'PREVIOUS LOADED MODEL IS ', this.tfLite);\n this.loadModelCalled = true;\n this.tfLitePromise = loadTFLite();\n this.tfLite = await this.tfLitePromise;\n } else {\n //either it is loading or loaded\n await this.tfLitePromise;\n }\n if (this.enableSharpening) {\n this.initSharpenFilter();\n }\n }\n\n /*\n @depreceated\n */\n isSupported(): boolean {\n //support chrome, firefox, edge TODO: check this\n return (\n navigator.userAgent.indexOf('Chrome') !== -1 ||\n navigator.userAgent.indexOf('Firefox') !== -1 ||\n navigator.userAgent.indexOf('Edg') !== -1 ||\n navigator.userAgent.indexOf('Edge') !== -1\n );\n }\n\n checkSupport(): HMSPluginSupportResult {\n const browserResult = {} as HMSPluginSupportResult;\n if (['Chrome', 'Firefox', 'Edg', 'Edge'].some(value => navigator.userAgent.indexOf(value) !== -1)) {\n browserResult.isSupported = true;\n } else {\n browserResult.isSupported = false;\n browserResult.errType = HMSPluginUnsupportedTypes.PLATFORM_NOT_SUPPORTED;\n browserResult.errMsg = 'browser not supported for plugin, see docs';\n }\n\n return browserResult;\n }\n\n getName(): string {\n return pkg.name;\n }\n\n getPluginType(): HMSVideoPluginType {\n return HMSVideoPluginType.TRANSFORM;\n }\n\n async setBackground(path?: string | HTMLImageElement | HTMLVideoElement) {\n if (path !== '') {\n if (path === 'none') {\n this.log(TAG, 'setting background to :', path);\n this.background = 'none';\n this.backgroundType = 'none';\n this.isVirtualBackground = false;\n } else if (path === 'blur') {\n this.log(TAG, 'setting background to :', path);\n this.background = 'blur';\n this.backgroundType = 'blur';\n this.isVirtualBackground = false;\n } else if (path instanceof HTMLImageElement) {\n this.log('setting background to image', path);\n const img = await this.setImage(path as HTMLImageElement);\n if (!img || !img.complete || !img.naturalHeight) {\n throw new Error('Invalid image. Provide a valid and successfully loaded HTMLImageElement');\n } else {\n this.isVirtualBackground = true;\n this.backgroundImage = img;\n this.backgroundType = 'image';\n }\n } else if (path instanceof HTMLVideoElement) {\n this.log('setting background to video', path);\n this.backgroundVideo = path as HTMLVideoElement;\n this.backgroundVideo.crossOrigin = 'anonymous';\n this.backgroundVideo.muted = true;\n this.backgroundVideo.loop = true;\n this.backgroundVideo.oncanplaythrough = async () => {\n if (this.backgroundVideo != null) {\n await this.backgroundVideo!.play();\n this.isVirtualBackground = true;\n this.backgroundType = 'video';\n }\n };\n } else {\n console.log('setting gif to background');\n this.gifFrames = await this.setGiF(path as string);\n if (this.gifFrames != null && this.gifFrames.length > 0) {\n this.backgroundType = 'gif';\n this.isVirtualBackground = true;\n } else {\n throw new Error('Invalid background supplied, see the docs to check supported background type');\n }\n }\n } else {\n throw new Error('Invalid background supplied, see the docs to check supported background type');\n }\n }\n\n stop(): void {\n if (this.isVirtualBackground) {\n this.backgroundImage?.removeAttribute('src');\n this.backgroundVideo?.removeAttribute('src');\n if (this.backgroundType === 'video') {\n this.backgroundVideo!.loop = false;\n this.backgroundVideo = null;\n }\n }\n if (this.outputCtx) {\n this.outputCtx!.fillStyle = `rgb(0, 0, 0)`;\n this.outputCtx!.fillRect(0, 0, this.output!.width, this.output!.height);\n }\n\n //gif related\n this.gifFrameImageData = null;\n this.gifFrames = null;\n this.giflocalCount = 0;\n this.gifFramesIndex = 0;\n }\n\n processVideoFrame(\n input: HTMLCanvasElement,\n output: HTMLCanvasElement,\n skipProcessing?: boolean,\n ): Promise<void> | void {\n if (!input || !output) {\n throw new Error('Plugin invalid input/output');\n }\n\n this.input = input;\n this.output = output;\n\n const ctx = output.getContext('2d');\n if (ctx!.canvas.width !== input.width) {\n ctx!.canvas.width = input.width;\n }\n if (ctx!.canvas.height !== input.height) {\n ctx!.canvas.height = input.height;\n }\n\n if (this.backgroundType === 'video') {\n this.backgroundVideo!.width = input.width;\n this.backgroundVideo!.height = input.height;\n }\n\n this.outputCtx = ctx!;\n this.imageAspectRatio = input.width / input.height;\n if (this.imageAspectRatio <= 0) {\n throw new Error('Invalid input width/height');\n }\n\n const process = async () => {\n await this.runSegmentation(skipProcessing);\n };\n\n if (this.background === 'none' && !this.isVirtualBackground) {\n this.outputCtx!.globalCompositeOperation = 'copy';\n this.outputCtx!.filter = 'none';\n this.outputCtx!.drawImage(input, 0, 0, input.width, input.height);\n } else {\n process();\n }\n }\n\n private async setImage(image: HTMLImageElement): Promise<any> {\n image.crossOrigin = 'anonymous';\n return new Promise((resolve, reject) => {\n image.onload = () => resolve(image);\n image.onerror = reject;\n });\n }\n\n private setGiF(url: string): Promise<any> {\n return fetch(url)\n .then(resp => resp.arrayBuffer())\n .then(buff => parseGIF(buff))\n .then(gif => {\n return decompressFrames(gif, true);\n });\n }\n\n private log(tag: string, ...data: any[]) {\n console.info(tag, ...data);\n }\n\n private resizeInputData() {\n this.personMaskCtx!.drawImage(\n this.input,\n 0,\n 0,\n this.input!.width,\n this.input!.height,\n 0,\n 0,\n this.personMaskWidth,\n this.personMaskHeight,\n );\n\n const imageData = this.personMaskCtx!.getImageData(0, 0, this.personMaskWidth, this.personMaskHeight);\n //\n const inputMemoryOffset = this.tfLite._getInputMemoryOffset() / 4;\n for (let i = 0; i < this.personMaskPixelCount; i++) {\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3] = imageData.data[i * 4] / 255;\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3 + 1] = imageData.data[i * 4 + 1] / 255;\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3 + 2] = imageData.data[i * 4 + 2] / 255;\n }\n }\n private infer(skipProcessing?: boolean) {\n if (!skipProcessing) {\n this.tfLite._runInference();\n }\n const outputMemoryOffset = this.tfLite._getOutputMemoryOffset() / 4;\n\n for (let i = 0; i < this.personMaskPixelCount; i++) {\n if (this.modelName === 'meet') {\n const background = this.tfLite.HEAPF32[outputMemoryOffset + i * 2];\n const person = this.tfLite.HEAPF32[outputMemoryOffset + i * 2 + 1];\n const shift = Math.max(background, person);\n const backgroundExp = Math.exp(background - shift);\n const personExp = Math.exp(person - shift);\n // Sets only the alpha component of each pixel.\n this.personMask.data[i * 4 + 3] = (255 * personExp) / (backgroundExp + personExp);\n } else if (this.modelName === 'landscape-segmentation') {\n const person = this.tfLite.HEAPF32[outputMemoryOffset + i];\n this.personMask.data[i * 4 + 3] = 255 * person;\n }\n }\n\n this.personMaskCtx!.putImageData(this.personMask, 0, 0);\n }\n\n private postProcessing() {\n this.outputCtx!.globalCompositeOperation = 'copy';\n this.outputCtx!.filter = 'none';\n\n if (this.isVirtualBackground) {\n this.outputCtx!.filter = 'blur(4px)';\n } else {\n this.outputCtx!.filter = 'blur(8px)';\n }\n this.drawPersonMask();\n this.outputCtx!.globalCompositeOperation = 'source-in';\n this.outputCtx!.filter = 'none';\n // //Draw the foreground\n this.outputCtx!.drawImage(this.input!, 0, 0);\n\n if (\n this.enableSharpening &&\n this.output!.width > minVideoWidthForSharpening && // minimum and maximum resolution to enable sharpening filter\n this.output!.height > minVideoHeightForSharpening &&\n this.output!.width < maxVideoWidthForSharpening &&\n this.output!.height < maxVideoHeightForSharpening\n ) {\n this.sharpenFilter();\n }\n\n // //Draw the background\n this.drawSegmentedBackground();\n }\n\n private sharpenFilter() {\n // adding sharpening filter to each frame to improve edges and brightness\n // The basic idea is that you take the weighed sum of a rectangle of pixels from the source image and use that as the output value using convolution filter\n // It is applied intermediate output with black background and only mask data in frame\n // Filter currently used is 3 x 3 sharpening filter with values as shown:\n // [ 0, -1, 0,\n // -1, 5, -1,\n // 0, -1, 0 ]\n const outputImageData = this.outputCtx!.getImageData(0, 0, this.output!.width, this.output!.height);\n\n // filters you may try\n // [-1, -1, -1, -1, 9, -1, -1, -1, -1]\n //[0, -1, 0, -1, 5, -1, 0, -1, 0]\n const output = this.filters.convolute(outputImageData);\n\n this.outputCtx!.putImageData(output, 0, 0);\n }\n\n private drawPersonMask() {\n this.outputCtx!.drawImage(\n this.personMaskCanvas,\n 0,\n 0,\n this.personMaskWidth,\n this.personMaskHeight,\n 0,\n 0,\n this.output!.width,\n this.output!.height,\n );\n }\n\n private drawSegmentedBackground() {\n this.outputCtx!.globalCompositeOperation = 'destination-over';\n this.outputCtx!.imageSmoothingEnabled = true;\n this.outputCtx!.imageSmoothingQuality = 'high';\n if (this.isVirtualBackground) {\n if (this.backgroundType === 'video' && this.backgroundVideo != null && this.backgroundVideo!.readyState >= 4) {\n this.fitVideoToBackground();\n } else if (this.backgroundType === 'image') {\n this.fitImageToBackground();\n } else if (this.backgroundType === 'gif') {\n if (this.giflocalCount > this.gifFrames[this.gifFramesIndex].delay / DEFAULT_DELAY) {\n this.gifFramesIndex++;\n if (this.gifFramesIndex >= this.gifFrames.length) {\n this.gifFramesIndex = 0;\n }\n this.giflocalCount = 0;\n } else {\n this.giflocalCount++;\n }\n this.fitGifToBackground();\n }\n } else {\n this.addBlurToBackground();\n }\n }\n\n private async runSegmentation(skipProcessing?: boolean) {\n if (this.tfLite) {\n // const start = performance.now();\n\n this.resizeInputData();\n await this.infer(skipProcessing);\n this.postProcessing();\n // const end = performance.now();\n // this.log(TAG,\"time taken\",end -start);\n }\n }\n\n private fitVideoToBackground() {\n this.fitData(this.backgroundVideo, this.backgroundVideo!.videoWidth, this.backgroundVideo!.videoHeight);\n }\n\n private fitImageToBackground() {\n this.fitData(this.backgroundImage, this.backgroundImage!.width, this.backgroundImage!.height);\n }\n\n private fitGifToBackground() {\n if (this.gifFrameImageData == null) {\n const dims = this.gifFrames[this.gifFramesIndex].dims;\n this.tempGifCanvas!.width = dims.width;\n this.tempGifCanvas!.height = dims.height;\n this.gifFrameImageData = this.tempGifContext.createImageData(dims.width, dims.height);\n }\n // set the patch data as an override\n this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch);\n this.tempGifContext.putImageData(this.gifFrameImageData, 0, 0);\n\n this.fitData(this.tempGifCanvas, this.gifFrameImageData!.width, this.gifFrameImageData!.height);\n }\n\n private fitData(data: any, dataWidth: number, dataHeight: number) {\n let inputWidth: any, inputHeight: any, xoffset: any, yoffset: any;\n if (dataWidth / dataHeight < this.imageAspectRatio) {\n inputWidth = dataWidth;\n inputHeight = dataWidth / this.imageAspectRatio;\n xoffset = 0;\n yoffset = (dataHeight - inputHeight) / 2;\n } else {\n inputHeight = dataHeight;\n inputWidth = dataHeight * this.imageAspectRatio;\n yoffset = 0;\n xoffset = (dataWidth - inputWidth) / 2;\n }\n this.outputCtx!.drawImage(\n data,\n xoffset,\n yoffset,\n inputWidth,\n inputHeight,\n 0,\n 0,\n this.output!.width,\n this.output!.height,\n );\n }\n\n private async addBlurToBackground() {\n let blurValue = '15px';\n if (this.input!.width <= 160) {\n blurValue = '5px';\n } else if (this.input!.width <= 320) {\n blurValue = '10px';\n } else if (this.input!.width <= 640) {\n blurValue = '15px';\n } else if (this.input!.width <= 960) {\n blurValue = '20px';\n } else if (this.input!.width <= 1280) {\n blurValue = '25px';\n } else if (this.input!.width <= 1920) {\n blurValue = '30px';\n }\n\n this.outputCtx!.filter = `blur(${blurValue})`;\n this.outputCtx!.drawImage(this.input!, 0, 0, this.output!.width, this.output!.height);\n }\n\n private initSharpenFilter(): any {\n this.filters.tmpCanvas = document.createElement('canvas');\n this.filters.tmpCtx = this.filters.tmpCanvas.getContext('2d');\n\n this.filters.createImageData = (w: number, h: number) => {\n return this.filters.tmpCtx.createImageData(w, h);\n };\n\n this.filters.convolute = (pixels: ImageData, weights = [0, -1, 0, -1, 5, -1, 0, -1, 0], opaque: boolean) => {\n const side = Math.round(Math.sqrt(weights.length));\n\n const halfSide = Math.floor(side / 2);\n const src = pixels.data;\n const sw = pixels.width;\n const sh = pixels.height;\n // pad output by the convolution matrix\n const w = sw;\n const h = sh;\n const output = this.filters.createImageData(w, h);\n const dst = output.data;\n // go through the destination image pixels\n const alphaFac = opaque ? 1 : 0;\n for (let y = 0; y < h; y = y + 1) {\n for (let x = 0; x < w; x = x + 1) {\n const dstOff = (y * w + x) * 4;\n\n if (src[dstOff + 3] === 0) {\n continue;\n } else if (x < w && y < h) {\n const sy = y;\n const sx = x;\n\n // calculate the weighed sum of the source image pixels that\n // fall under the convolution matrix\n let r = 0,\n g = 0,\n b = 0,\n a = 0;\n for (let cy = 0; cy < side; cy++) {\n for (let cx = 0; cx < side; cx++) {\n const scy = sy + cy - halfSide;\n const scx = sx + cx - halfSide;\n if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {\n const srcOff = (scy * sw + scx) * 4;\n const wt = weights[cy * side + cx];\n r += src[srcOff] * wt;\n g += src[srcOff + 1] * wt;\n b += src[srcOff + 2] * wt;\n a += src[srcOff + 3] * wt;\n }\n }\n }\n dst[dstOff] = r;\n dst[dstOff + 1] = g;\n dst[dstOff + 2] = b;\n dst[dstOff + 3] = a + alphaFac * (255 - a);\n }\n }\n }\n return output;\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "m9DAAA,8CCAA,GAAM,GAAM,IACN,EAAW,qBAAqB,EAAI,WACpC,EAAM,cACN,EAAiB,mBACjB,EAAsB,wBACtB,GAAkB,8CAElB,EAAa,AAAC,GACX,GAAI,SAAQ,SAAU,EAAS,EAAQ,CAC5C,GAAM,GAAI,SAAS,cAAc,UACjC,EAAE,IAAM,EACR,EAAE,OAAS,EACX,EAAE,QAAU,EACZ,SAAS,KAAK,YAAY,KAIxB,GAAkB,IAAY,0BAClC,GAAI,GACA,EAAO,GAAG,KAAY,IAC1B,KAAM,GAAW,GACjB,GAAI,CAEF,EAAS,KAAM,gCACT,EAAN,CACA,QAAQ,KAAK,0EACb,EAAO,GAAG,KAAY,IACtB,KAAM,GAAW,GAEjB,EAAS,KAAM,sBAEjB,MAAO,KAGH,EAAa,IAAY,0BAC7B,GAAM,GAAY,GAAG,KAAY,KAC3B,CAAC,EAAQ,GAAiB,KAAM,SA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,EACN,OAAS,GAAK,EAAG,EAAK,EAAM,IAC1B,OAAS,GAAK,EAAG,EAAK,EAAM,IAAM,CAChC,GAAM,GAAM,EAAK,EAAK,EAChB,EAAM,EAAK,EAAK,EACtB,GAAI,GAAO,GAAK,EAAM,GAAM,GAAO,GAAK,EAAM,EAAI,CAChD,GAAM,GAAU,GAAM,EAAK,GAAO,EAC5B,EAAK,EAAQ,EAAK,EAAO,GAC/B,GAAK,EAAI,GAAU,EACnB,GAAK,EAAI,EAAS,GAAK,EACvB,GAAK,EAAI,EAAS,GAAK,EACvB,GAAK,EAAI,EAAS,GAAK,GAI7B,EAAI,GAAU,EACd,EAAI,EAAS,GAAK,EAClB,EAAI,EAAS,GAAK,EAClB,EAAI,EAAS,GAAK,EAAI,EAAY,KAAM,IAI9C,MAAO",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var A=(h,t)=>()=>(t||h((t={exports:{}}).exports,t),t.exports);var u=(h,t,e)=>new Promise((i,s)=>{var a=r=>{try{o(e.next(r))}catch(l){s(l)}},n=r=>{try{o(e.throw(r))}catch(l){s(l)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,n);o((e=e.apply(h,t)).next())});var C=A((et,O)=>{O.exports={version:"1.7.1-alpha.2",license:"MIT",main:"dist/index.js",typings:"dist/index.d.ts",files:["dist","src/tflite","src/models"],scripts:{start:'concurrently "yarn dev" "yarn types"',dev:"node ../../scripts/dev","build:only":"node ../../scripts/build",build:"yarn build:only && yarn types:build",types:"tsc -w","types:build":"tsc -p tsconfig.json",test:"jest --maxWorkers=1 --passWithNoTests",lint:"eslint -c ../../.eslintrc .","lint:fix":"yarn lint --fix",prepare:"yarn build",size:"size-limit",analyze:"size-limit --why",format:"prettier --write src/**/*.ts"},peerDependencies:{"@100mslive/hms-video":"^0.5.0"},name:"@100mslive/hms-virtual-background",author:"ashish17",module:"dist/index.js",devDependencies:{"@100mslive/hms-video":"0.5.1-alpha.2"},dependencies:{"@tensorflow/tfjs-backend-webgl":"^3.3.0","@tensorflow/tfjs-core":"^3.3.0","@webassemblyjs/helper-wasm-bytecode":"1.11.1","@webassemblyjs/wasm-gen":"1.11.1","gifuct-js":"^2.1.2","wasm-check":"^2.0.2"},eslintIgnore:["tflite.js","tflite-simd.js","tflite.wasm","tflite-simd.wasm","defineTFLite.ts","importing.test.ts"],gitHead:"7450dfa08f3ccf63a603a62c70eafbbeea26ab1e"}});var _=C(),F=`https://unpkg.com/${_.name}/src`,M="VBProcessor",R="tflite/tflite.js",j="tflite/tflite-simd.js",G="models/selfie_segmentation_landscape.tflite",S=h=>new Promise(function(t,e){let i=document.createElement("script");i.src=h,i.onload=t,i.onerror=e,document.head.appendChild(i)}),W=()=>u(void 0,null,function*(){let h,t=`${F}/${j}`;yield S(t);try{h=yield createTFLiteSIMDModule()}catch(e){console.warn("SIMD not supported. You may experience poor virtual background effect."),t=`${F}/${R}`,yield S(t),h=yield createTFLiteModule()}return h}),H=()=>u(void 0,null,function*(){let h=`${F}/${G}`,[t,e]=yield Promise.all([W(),fetch(h)]),i=yield e.arrayBuffer(),s=t._getModelBufferMemoryOffset();return t.HEAPU8.set(new Uint8Array(i),s),t._loadModel(i.byteLength),console.debug(M,"Input memory offset:",t._getInputMemoryOffset()),console.debug(M,"Input height:",t._getInputHeight()),console.debug(M,"Input width:",t._getInputWidth()),console.debug(M,"Input channels:",t._getInputChannelCount()),t});import"@tensorflow/tfjs-backend-webgl";import{parseGIF as N,decompressFrames as $}from"gifuct-js";import{HMSPluginUnsupportedTypes as U,HMSVideoPluginType as z}from"@100mslive/hms-video";var y="VBProcessor",q=33,J=C(),Y=214,Q=855,K=120,X=720,Z=class{constructor(t,e=!1){this.backgroundType="none";this.background=t,this.enableSharpening=e,this.backgroundImage=null,this.backgroundVideo=null,this.personMaskWidth=256,this.personMaskHeight=144,this.isVirtualBackground=!1,this.blurValue="10px",this.loadModelCalled=!1,this.tfLite=null,this.modelName="landscape-segmentation",this.outputCtx=null,this.input=null,this.output=null,this.timerID=0,this.imageAspectRatio=1,this.personMaskPixelCount=this.personMaskWidth*this.personMaskHeight,this.personMask=new ImageData(this.personMaskWidth,this.personMaskHeight),this.personMaskCanvas=document.createElement("canvas"),this.personMaskCanvas.width=this.personMaskWidth,this.personMaskCanvas.height=this.personMaskHeight,this.personMaskCtx=this.personMaskCanvas.getContext("2d"),this.filters={},this.gifFrames=null,this.gifFramesIndex=0,this.gifFrameImageData=null,this.tempGifCanvas=document.createElement("canvas"),this.tempGifContext=this.tempGifCanvas.getContext("2d"),this.giflocalCount=0,this.enableSharpening=e,this.log(y,"Virtual Background plugin created"),this.setBackground(this.background)}init(){return u(this,null,function*(){this.loadModelCalled?yield this.tfLitePromise:(this.log(y,"PREVIOUS LOADED MODEL IS ",this.tfLite),this.loadModelCalled=!0,this.tfLitePromise=H(),this.tfLite=yield this.tfLitePromise),this.enableSharpening&&this.initSharpenFilter()})}isSupported(){return navigator.userAgent.indexOf("Chrome")!==-1||navigator.userAgent.indexOf("Firefox")!==-1||navigator.userAgent.indexOf("Edg")!==-1||navigator.userAgent.indexOf("Edge")!==-1}checkSupport(){let t={};return["Chrome","Firefox","Edg","Edge"].some(e=>navigator.userAgent.indexOf(e)!==-1)?t.isSupported=!0:(t.isSupported=!1,t.errType=U.PLATFORM_NOT_SUPPORTED,t.errMsg="browser not supported for plugin, see docs"),t}getName(){return J.name}getPluginType(){return z.TRANSFORM}setBackground(t){return u(this,null,function*(){if(t!=="")if(t==="none")this.log(y,"setting background to :",t),this.background="none",this.backgroundType="none",this.isVirtualBackground=!1;else if(t==="blur")this.log(y,"setting background to :",t),this.background="blur",this.backgroundType="blur",this.isVirtualBackground=!1;else if(t instanceof HTMLImageElement){this.log("setting background to image",t);let e=yield this.setImage(t);if(!e||!e.complete||!e.naturalHeight)throw new Error("Invalid image. Provide a valid and successfully loaded HTMLImageElement");this.isVirtualBackground=!0,this.backgroundImage=e,this.backgroundType="image"}else if(t instanceof HTMLVideoElement)this.log("setting background to video",t),this.backgroundVideo=t,this.backgroundVideo.crossOrigin="anonymous",this.backgroundVideo.muted=!0,this.backgroundVideo.loop=!0,this.backgroundVideo.oncanplaythrough=()=>u(this,null,function*(){this.backgroundVideo!=null&&(yield this.backgroundVideo.play(),this.isVirtualBackground=!0,this.backgroundType="video")});else if(console.log("setting gif to background"),this.gifFrames=yield this.setGiF(t),this.gifFrames!=null&&this.gifFrames.length>0)this.backgroundType="gif",this.isVirtualBackground=!0;else throw new Error("Invalid background supplied, see the docs to check supported background type");else throw new Error("Invalid background supplied, see the docs to check supported background type")})}stop(){var t,e;this.isVirtualBackground&&((t=this.backgroundImage)==null||t.removeAttribute("src"),(e=this.backgroundVideo)==null||e.removeAttribute("src"),this.backgroundType==="video"&&(this.backgroundVideo.loop=!1,this.backgroundVideo=null)),this.outputCtx&&(this.outputCtx.fillStyle="rgb(0, 0, 0)",this.outputCtx.fillRect(0,0,this.output.width,this.output.height)),this.gifFrameImageData=null,this.gifFrames=null,this.giflocalCount=0,this.gifFramesIndex=0}processVideoFrame(t,e,i){if(!t||!e)throw new Error("Plugin invalid input/output");this.input=t,this.output=e;let s=e.getContext("2d");if(s.canvas.width!==t.width&&(s.canvas.width=t.width),s.canvas.height!==t.height&&(s.canvas.height=t.height),this.backgroundType==="video"&&(this.backgroundVideo.width=t.width,this.backgroundVideo.height=t.height),this.outputCtx=s,this.imageAspectRatio=t.width/t.height,this.imageAspectRatio<=0)throw new Error("Invalid input width/height");let a=()=>u(this,null,function*(){yield this.runSegmentation(i)});this.background==="none"&&!this.isVirtualBackground?(this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.outputCtx.drawImage(t,0,0,t.width,t.height)):a()}setImage(t){return u(this,null,function*(){return t.crossOrigin="anonymous",new Promise((e,i)=>{t.onload=()=>e(t),t.onerror=i})})}setGiF(t){return fetch(t).then(e=>e.arrayBuffer()).then(e=>N(e)).then(e=>$(e,!0))}log(t,...e){console.info(t,...e)}resizeInputData(){this.personMaskCtx.drawImage(this.input,0,0,this.input.width,this.input.height,0,0,this.personMaskWidth,this.personMaskHeight);let t=this.personMaskCtx.getImageData(0,0,this.personMaskWidth,this.personMaskHeight),e=this.tfLite._getInputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)this.tfLite.HEAPF32[e+i*3]=t.data[i*4]/255,this.tfLite.HEAPF32[e+i*3+1]=t.data[i*4+1]/255,this.tfLite.HEAPF32[e+i*3+2]=t.data[i*4+2]/255}infer(t){t||this.tfLite._runInference();let e=this.tfLite._getOutputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)if(this.modelName==="meet"){let s=this.tfLite.HEAPF32[e+i*2],a=this.tfLite.HEAPF32[e+i*2+1],n=Math.max(s,a),o=Math.exp(s-n),r=Math.exp(a-n);this.personMask.data[i*4+3]=255*r/(o+r)}else if(this.modelName==="landscape-segmentation"){let s=this.tfLite.HEAPF32[e+i];this.personMask.data[i*4+3]=255*s}this.personMaskCtx.putImageData(this.personMask,0,0)}postProcessing(){this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.isVirtualBackground?this.outputCtx.filter="blur(4px)":this.outputCtx.filter="blur(8px)",this.drawPersonMask(),this.outputCtx.globalCompositeOperation="source-in",this.outputCtx.filter="none",this.outputCtx.drawImage(this.input,0,0),this.enableSharpening&&this.output.width>Y&&this.output.height>K&&this.output.width<Q&&this.output.height<X&&this.sharpenFilter(),this.drawSegmentedBackground()}sharpenFilter(){let t=this.outputCtx.getImageData(0,0,this.output.width,this.output.height),e=this.filters.convolute(t);this.outputCtx.putImageData(e,0,0)}drawPersonMask(){this.outputCtx.drawImage(this.personMaskCanvas,0,0,this.personMaskWidth,this.personMaskHeight,0,0,this.output.width,this.output.height)}drawSegmentedBackground(){this.outputCtx.globalCompositeOperation="destination-over",this.outputCtx.imageSmoothingEnabled=!0,this.outputCtx.imageSmoothingQuality="high",this.isVirtualBackground?this.backgroundType==="video"&&this.backgroundVideo!=null&&this.backgroundVideo.readyState>=4?this.fitVideoToBackground():this.backgroundType==="image"?this.fitImageToBackground():this.backgroundType==="gif"&&(this.giflocalCount>this.gifFrames[this.gifFramesIndex].delay/q?(this.gifFramesIndex++,this.gifFramesIndex>=this.gifFrames.length&&(this.gifFramesIndex=0),this.giflocalCount=0):this.giflocalCount++,this.fitGifToBackground()):this.addBlurToBackground()}runSegmentation(t){return u(this,null,function*(){this.tfLite&&(this.resizeInputData(),yield this.infer(t),this.postProcessing())})}fitVideoToBackground(){this.fitData(this.backgroundVideo,this.backgroundVideo.videoWidth,this.backgroundVideo.videoHeight)}fitImageToBackground(){this.fitData(this.backgroundImage,this.backgroundImage.width,this.backgroundImage.height)}fitGifToBackground(){if(this.gifFrameImageData==null){let t=this.gifFrames[this.gifFramesIndex].dims;this.tempGifCanvas.width=t.width,this.tempGifCanvas.height=t.height,this.gifFrameImageData=this.tempGifContext.createImageData(t.width,t.height)}this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch),this.tempGifContext.putImageData(this.gifFrameImageData,0,0),this.fitData(this.tempGifCanvas,this.gifFrameImageData.width,this.gifFrameImageData.height)}fitData(t,e,i){let s,a,n,o;e/i<this.imageAspectRatio?(s=e,a=e/this.imageAspectRatio,n=0,o=(i-a)/2):(a=i,s=i*this.imageAspectRatio,o=0,n=(e-s)/2),this.outputCtx.drawImage(t,n,o,s,a,0,0,this.output.width,this.output.height)}addBlurToBackground(){return u(this,null,function*(){let t="15px";this.input.width<=160?t="5px":this.input.width<=320?t="10px":this.input.width<=640?t="15px":this.input.width<=960?t="20px":this.input.width<=1280?t="25px":this.input.width<=1920&&(t="30px"),this.outputCtx.filter=`blur(${t})`,this.outputCtx.drawImage(this.input,0,0,this.output.width,this.output.height)})}initSharpenFilter(){this.filters.tmpCanvas=document.createElement("canvas"),this.filters.tmpCtx=this.filters.tmpCanvas.getContext("2d"),this.filters.createImageData=(t,e)=>this.filters.tmpCtx.createImageData(t,e),this.filters.convolute=(t,e=[0,-1,0,-1,5,-1,0,-1,0],i)=>{let s=Math.round(Math.sqrt(e.length)),a=Math.floor(s/2),n=t.data,o=t.width,r=t.height,l=o,x=r,T=this.filters.createImageData(l,x),p=T.data,P=i?1:0;for(let d=0;d<x;d=d+1)for(let g=0;g<l;g=g+1){let c=(d*l+g)*4;if(n[c+3]!==0&&g<l&&d<x){let D=d,B=g,L=0,E=0,V=0,w=0;for(let m=0;m<s;m++)for(let f=0;f<s;f++){let v=D+m-a,I=B+f-a;if(v>=0&&v<r&&I>=0&&I<o){let k=(v*o+I)*4,b=e[m*s+f];L+=n[k]*b,E+=n[k+1]*b,V+=n[k+2]*b,w+=n[k+3]*b}}p[c]=L,p[c+1]=E,p[c+2]=V,p[c+3]=w+P*(255-w)}}return T}}};export{Z as HMSVirtualBackgroundPlugin};
|
|
1
|
+
var A=(h,t)=>()=>(t||h((t={exports:{}}).exports,t),t.exports);var u=(h,t,e)=>new Promise((i,s)=>{var a=r=>{try{o(e.next(r))}catch(l){s(l)}},n=r=>{try{o(e.throw(r))}catch(l){s(l)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(a,n);o((e=e.apply(h,t)).next())});var C=A((et,O)=>{O.exports={version:"1.7.1",license:"MIT",main:"dist/index.js",typings:"dist/index.d.ts",files:["dist","src/tflite","src/models"],scripts:{start:'concurrently "yarn dev" "yarn types"',dev:"node ../../scripts/dev","build:only":"node ../../scripts/build",build:"yarn build:only && yarn types:build",types:"tsc -w","types:build":"tsc -p tsconfig.json",test:"jest --maxWorkers=1 --passWithNoTests",lint:"eslint -c ../../.eslintrc .","lint:fix":"yarn lint --fix",prepare:"yarn build",size:"size-limit",analyze:"size-limit --why",format:"prettier --write src/**/*.ts"},peerDependencies:{"@100mslive/hms-video":"^0.2.0"},name:"@100mslive/hms-virtual-background",author:"ashish17",module:"dist/index.js",devDependencies:{"@100mslive/hms-video":"0.5.1"},dependencies:{"@tensorflow/tfjs-backend-webgl":"^3.3.0","@tensorflow/tfjs-core":"^3.3.0","@webassemblyjs/helper-wasm-bytecode":"1.11.1","@webassemblyjs/wasm-gen":"1.11.1","gifuct-js":"^2.1.2","wasm-check":"^2.0.2"},eslintIgnore:["tflite.js","tflite-simd.js","tflite.wasm","tflite-simd.wasm","defineTFLite.ts","importing.test.ts"],gitHead:"2b27a0da2da14570ec448b6ff8486dff12b7eb4d"}});var _=C(),F=`https://unpkg.com/${_.name}/src`,M="VBProcessor",R="tflite/tflite.js",j="tflite/tflite-simd.js",G="models/selfie_segmentation_landscape.tflite",S=h=>new Promise(function(t,e){let i=document.createElement("script");i.src=h,i.onload=t,i.onerror=e,document.head.appendChild(i)}),W=()=>u(void 0,null,function*(){let h,t=`${F}/${j}`;yield S(t);try{h=yield createTFLiteSIMDModule()}catch(e){console.warn("SIMD not supported. You may experience poor virtual background effect."),t=`${F}/${R}`,yield S(t),h=yield createTFLiteModule()}return h}),H=()=>u(void 0,null,function*(){let h=`${F}/${G}`,[t,e]=yield Promise.all([W(),fetch(h)]),i=yield e.arrayBuffer(),s=t._getModelBufferMemoryOffset();return t.HEAPU8.set(new Uint8Array(i),s),t._loadModel(i.byteLength),console.debug(M,"Input memory offset:",t._getInputMemoryOffset()),console.debug(M,"Input height:",t._getInputHeight()),console.debug(M,"Input width:",t._getInputWidth()),console.debug(M,"Input channels:",t._getInputChannelCount()),t});import"@tensorflow/tfjs-backend-webgl";import{parseGIF as N,decompressFrames as $}from"gifuct-js";import{HMSPluginUnsupportedTypes as U,HMSVideoPluginType as z}from"@100mslive/hms-video";var y="VBProcessor",q=33,J=C(),Y=214,Q=855,K=120,X=720,Z=class{constructor(t,e=!1){this.backgroundType="none";this.background=t,this.enableSharpening=e,this.backgroundImage=null,this.backgroundVideo=null,this.personMaskWidth=256,this.personMaskHeight=144,this.isVirtualBackground=!1,this.blurValue="10px",this.loadModelCalled=!1,this.tfLite=null,this.modelName="landscape-segmentation",this.outputCtx=null,this.input=null,this.output=null,this.timerID=0,this.imageAspectRatio=1,this.personMaskPixelCount=this.personMaskWidth*this.personMaskHeight,this.personMask=new ImageData(this.personMaskWidth,this.personMaskHeight),this.personMaskCanvas=document.createElement("canvas"),this.personMaskCanvas.width=this.personMaskWidth,this.personMaskCanvas.height=this.personMaskHeight,this.personMaskCtx=this.personMaskCanvas.getContext("2d"),this.filters={},this.gifFrames=null,this.gifFramesIndex=0,this.gifFrameImageData=null,this.tempGifCanvas=document.createElement("canvas"),this.tempGifContext=this.tempGifCanvas.getContext("2d"),this.giflocalCount=0,this.enableSharpening=e,this.log(y,"Virtual Background plugin created"),this.setBackground(this.background)}init(){return u(this,null,function*(){this.loadModelCalled?yield this.tfLitePromise:(this.log(y,"PREVIOUS LOADED MODEL IS ",this.tfLite),this.loadModelCalled=!0,this.tfLitePromise=H(),this.tfLite=yield this.tfLitePromise),this.enableSharpening&&this.initSharpenFilter()})}isSupported(){return navigator.userAgent.indexOf("Chrome")!==-1||navigator.userAgent.indexOf("Firefox")!==-1||navigator.userAgent.indexOf("Edg")!==-1||navigator.userAgent.indexOf("Edge")!==-1}checkSupport(){let t={};return["Chrome","Firefox","Edg","Edge"].some(e=>navigator.userAgent.indexOf(e)!==-1)?t.isSupported=!0:(t.isSupported=!1,t.errType=U.PLATFORM_NOT_SUPPORTED,t.errMsg="browser not supported for plugin, see docs"),t}getName(){return J.name}getPluginType(){return z.TRANSFORM}setBackground(t){return u(this,null,function*(){if(t!=="")if(t==="none")this.log(y,"setting background to :",t),this.background="none",this.backgroundType="none",this.isVirtualBackground=!1;else if(t==="blur")this.log(y,"setting background to :",t),this.background="blur",this.backgroundType="blur",this.isVirtualBackground=!1;else if(t instanceof HTMLImageElement){this.log("setting background to image",t);let e=yield this.setImage(t);if(!e||!e.complete||!e.naturalHeight)throw new Error("Invalid image. Provide a valid and successfully loaded HTMLImageElement");this.isVirtualBackground=!0,this.backgroundImage=e,this.backgroundType="image"}else if(t instanceof HTMLVideoElement)this.log("setting background to video",t),this.backgroundVideo=t,this.backgroundVideo.crossOrigin="anonymous",this.backgroundVideo.muted=!0,this.backgroundVideo.loop=!0,this.backgroundVideo.oncanplaythrough=()=>u(this,null,function*(){this.backgroundVideo!=null&&(yield this.backgroundVideo.play(),this.isVirtualBackground=!0,this.backgroundType="video")});else if(console.log("setting gif to background"),this.gifFrames=yield this.setGiF(t),this.gifFrames!=null&&this.gifFrames.length>0)this.backgroundType="gif",this.isVirtualBackground=!0;else throw new Error("Invalid background supplied, see the docs to check supported background type");else throw new Error("Invalid background supplied, see the docs to check supported background type")})}stop(){var t,e;this.isVirtualBackground&&((t=this.backgroundImage)==null||t.removeAttribute("src"),(e=this.backgroundVideo)==null||e.removeAttribute("src"),this.backgroundType==="video"&&(this.backgroundVideo.loop=!1,this.backgroundVideo=null)),this.outputCtx&&(this.outputCtx.fillStyle="rgb(0, 0, 0)",this.outputCtx.fillRect(0,0,this.output.width,this.output.height)),this.gifFrameImageData=null,this.gifFrames=null,this.giflocalCount=0,this.gifFramesIndex=0}processVideoFrame(t,e,i){if(!t||!e)throw new Error("Plugin invalid input/output");this.input=t,this.output=e;let s=e.getContext("2d");if(s.canvas.width!==t.width&&(s.canvas.width=t.width),s.canvas.height!==t.height&&(s.canvas.height=t.height),this.backgroundType==="video"&&(this.backgroundVideo.width=t.width,this.backgroundVideo.height=t.height),this.outputCtx=s,this.imageAspectRatio=t.width/t.height,this.imageAspectRatio<=0)throw new Error("Invalid input width/height");let a=()=>u(this,null,function*(){yield this.runSegmentation(i)});this.background==="none"&&!this.isVirtualBackground?(this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.outputCtx.drawImage(t,0,0,t.width,t.height)):a()}setImage(t){return u(this,null,function*(){return t.crossOrigin="anonymous",new Promise((e,i)=>{t.onload=()=>e(t),t.onerror=i})})}setGiF(t){return fetch(t).then(e=>e.arrayBuffer()).then(e=>N(e)).then(e=>$(e,!0))}log(t,...e){console.info(t,...e)}resizeInputData(){this.personMaskCtx.drawImage(this.input,0,0,this.input.width,this.input.height,0,0,this.personMaskWidth,this.personMaskHeight);let t=this.personMaskCtx.getImageData(0,0,this.personMaskWidth,this.personMaskHeight),e=this.tfLite._getInputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)this.tfLite.HEAPF32[e+i*3]=t.data[i*4]/255,this.tfLite.HEAPF32[e+i*3+1]=t.data[i*4+1]/255,this.tfLite.HEAPF32[e+i*3+2]=t.data[i*4+2]/255}infer(t){t||this.tfLite._runInference();let e=this.tfLite._getOutputMemoryOffset()/4;for(let i=0;i<this.personMaskPixelCount;i++)if(this.modelName==="meet"){let s=this.tfLite.HEAPF32[e+i*2],a=this.tfLite.HEAPF32[e+i*2+1],n=Math.max(s,a),o=Math.exp(s-n),r=Math.exp(a-n);this.personMask.data[i*4+3]=255*r/(o+r)}else if(this.modelName==="landscape-segmentation"){let s=this.tfLite.HEAPF32[e+i];this.personMask.data[i*4+3]=255*s}this.personMaskCtx.putImageData(this.personMask,0,0)}postProcessing(){this.outputCtx.globalCompositeOperation="copy",this.outputCtx.filter="none",this.isVirtualBackground?this.outputCtx.filter="blur(4px)":this.outputCtx.filter="blur(8px)",this.drawPersonMask(),this.outputCtx.globalCompositeOperation="source-in",this.outputCtx.filter="none",this.outputCtx.drawImage(this.input,0,0),this.enableSharpening&&this.output.width>Y&&this.output.height>K&&this.output.width<Q&&this.output.height<X&&this.sharpenFilter(),this.drawSegmentedBackground()}sharpenFilter(){let t=this.outputCtx.getImageData(0,0,this.output.width,this.output.height),e=this.filters.convolute(t);this.outputCtx.putImageData(e,0,0)}drawPersonMask(){this.outputCtx.drawImage(this.personMaskCanvas,0,0,this.personMaskWidth,this.personMaskHeight,0,0,this.output.width,this.output.height)}drawSegmentedBackground(){this.outputCtx.globalCompositeOperation="destination-over",this.outputCtx.imageSmoothingEnabled=!0,this.outputCtx.imageSmoothingQuality="high",this.isVirtualBackground?this.backgroundType==="video"&&this.backgroundVideo!=null&&this.backgroundVideo.readyState>=4?this.fitVideoToBackground():this.backgroundType==="image"?this.fitImageToBackground():this.backgroundType==="gif"&&(this.giflocalCount>this.gifFrames[this.gifFramesIndex].delay/q?(this.gifFramesIndex++,this.gifFramesIndex>=this.gifFrames.length&&(this.gifFramesIndex=0),this.giflocalCount=0):this.giflocalCount++,this.fitGifToBackground()):this.addBlurToBackground()}runSegmentation(t){return u(this,null,function*(){this.tfLite&&(this.resizeInputData(),yield this.infer(t),this.postProcessing())})}fitVideoToBackground(){this.fitData(this.backgroundVideo,this.backgroundVideo.videoWidth,this.backgroundVideo.videoHeight)}fitImageToBackground(){this.fitData(this.backgroundImage,this.backgroundImage.width,this.backgroundImage.height)}fitGifToBackground(){if(this.gifFrameImageData==null){let t=this.gifFrames[this.gifFramesIndex].dims;this.tempGifCanvas.width=t.width,this.tempGifCanvas.height=t.height,this.gifFrameImageData=this.tempGifContext.createImageData(t.width,t.height)}this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch),this.tempGifContext.putImageData(this.gifFrameImageData,0,0),this.fitData(this.tempGifCanvas,this.gifFrameImageData.width,this.gifFrameImageData.height)}fitData(t,e,i){let s,a,n,o;e/i<this.imageAspectRatio?(s=e,a=e/this.imageAspectRatio,n=0,o=(i-a)/2):(a=i,s=i*this.imageAspectRatio,o=0,n=(e-s)/2),this.outputCtx.drawImage(t,n,o,s,a,0,0,this.output.width,this.output.height)}addBlurToBackground(){return u(this,null,function*(){let t="15px";this.input.width<=160?t="5px":this.input.width<=320?t="10px":this.input.width<=640?t="15px":this.input.width<=960?t="20px":this.input.width<=1280?t="25px":this.input.width<=1920&&(t="30px"),this.outputCtx.filter=`blur(${t})`,this.outputCtx.drawImage(this.input,0,0,this.output.width,this.output.height)})}initSharpenFilter(){this.filters.tmpCanvas=document.createElement("canvas"),this.filters.tmpCtx=this.filters.tmpCanvas.getContext("2d"),this.filters.createImageData=(t,e)=>this.filters.tmpCtx.createImageData(t,e),this.filters.convolute=(t,e=[0,-1,0,-1,5,-1,0,-1,0],i)=>{let s=Math.round(Math.sqrt(e.length)),a=Math.floor(s/2),n=t.data,o=t.width,r=t.height,l=o,x=r,T=this.filters.createImageData(l,x),p=T.data,P=i?1:0;for(let d=0;d<x;d=d+1)for(let g=0;g<l;g=g+1){let c=(d*l+g)*4;if(n[c+3]!==0&&g<l&&d<x){let D=d,B=g,L=0,E=0,V=0,w=0;for(let m=0;m<s;m++)for(let f=0;f<s;f++){let v=D+m-a,I=B+f-a;if(v>=0&&v<r&&I>=0&&I<o){let k=(v*o+I)*4,b=e[m*s+f];L+=n[k]*b,E+=n[k+1]*b,V+=n[k+2]*b,w+=n[k+3]*b}}p[c]=L,p[c+1]=E,p[c+2]=V,p[c+3]=w+P*(255-w)}}return T}}};export{Z as HMSVirtualBackgroundPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/defineTFLite.ts", "../src/HMSVirtualBackgroundPlugin.ts"],
|
|
4
4
|
"sourcesContent": ["const pkg = require('../package.json');\nconst BASE_URL = `https://unpkg.com/${pkg.name}/src`;\nconst TAG = 'VBProcessor';\nconst TFLITE_JS_FILE = 'tflite/tflite.js';\nconst TFLITE_SIMD_JS_FILE = 'tflite/tflite-simd.js';\nconst MODEL_FILE_NAME = 'models/selfie_segmentation_landscape.tflite';\n\nconst loadScript = (src: string) => {\n return new Promise(function (resolve, reject) {\n const s = document.createElement('script');\n s.src = src;\n s.onload = resolve;\n s.onerror = reject;\n document.head.appendChild(s);\n });\n};\n\nconst loadTFLiteModel = async () => {\n let tfLite: any;\n let path = `${BASE_URL}/${TFLITE_SIMD_JS_FILE}`;\n await loadScript(path);\n try {\n //@ts-ignore\n tfLite = await createTFLiteSIMDModule();\n } catch {\n console.warn('SIMD not supported. You may experience poor virtual background effect.');\n path = `${BASE_URL}/${TFLITE_JS_FILE}`;\n await loadScript(path);\n // @ts-ignore\n tfLite = await createTFLiteModule();\n }\n return tfLite;\n};\n\nconst loadTFLite = async () => {\n const modelPath = `${BASE_URL}/${MODEL_FILE_NAME}`;\n const [tfLite, modelResponse] = await Promise.all([loadTFLiteModel(), fetch(modelPath)]);\n\n const model = await modelResponse.arrayBuffer();\n const modelBufferOffset = tfLite._getModelBufferMemoryOffset();\n tfLite.HEAPU8.set(new Uint8Array(model), modelBufferOffset);\n tfLite._loadModel(model.byteLength);\n\n console.debug(TAG, 'Input memory offset:', tfLite._getInputMemoryOffset());\n console.debug(TAG, 'Input height:', tfLite._getInputHeight());\n console.debug(TAG, 'Input width:', tfLite._getInputWidth());\n console.debug(TAG, 'Input channels:', tfLite._getInputChannelCount());\n\n return tfLite;\n};\n\nexport { loadTFLite };\n", "/* eslint-disable complexity */\nimport { loadTFLite } from './defineTFLite';\nimport '@tensorflow/tfjs-backend-webgl';\nimport { parseGIF, decompressFrames } from 'gifuct-js';\nimport {\n HMSPluginSupportResult,\n HMSPluginUnsupportedTypes,\n HMSVideoPlugin,\n HMSVideoPluginType,\n} from '@100mslive/hms-video';\n\nconst TAG = 'VBProcessor';\nconst DEFAULT_DELAY = 33;\nconst pkg = require('../package.json');\n\nconst minVideoWidthForSharpening = 214;\nconst maxVideoWidthForSharpening = 855;\nconst minVideoHeightForSharpening = 120;\nconst maxVideoHeightForSharpening = 720;\n\nexport class HMSVirtualBackgroundPlugin implements HMSVideoPlugin {\n background: string | HTMLImageElement;\n personMaskWidth: number;\n personMaskHeight: number;\n isVirtualBackground: boolean;\n backgroundImage: HTMLImageElement | null;\n backgroundVideo: HTMLVideoElement | null;\n backgroundType = 'none';\n loadModelCalled: boolean;\n blurValue: any;\n tfLite: any;\n tfLitePromise: any;\n modelName: string;\n\n input: HTMLCanvasElement | null;\n output: HTMLCanvasElement | null;\n outputCtx: CanvasRenderingContext2D | null;\n timerID: number;\n imageAspectRatio: number;\n\n personMaskPixelCount: number;\n personMask: ImageData;\n personMaskCanvas: HTMLCanvasElement;\n personMaskCtx: any;\n filters: any;\n enableSharpening?: boolean | false;\n\n gifFrames: any;\n gifFramesIndex: number;\n gifFrameImageData: any;\n tempGifCanvas: HTMLCanvasElement;\n tempGifContext: any;\n giflocalCount: number;\n\n constructor(background: string, enableSharpening = false) {\n this.background = background;\n this.enableSharpening = enableSharpening;\n\n this.backgroundImage = null;\n this.backgroundVideo = null;\n\n this.personMaskWidth = 256;\n this.personMaskHeight = 144;\n this.isVirtualBackground = false;\n this.blurValue = '10px';\n this.loadModelCalled = false;\n this.tfLite = null;\n this.modelName = 'landscape-segmentation';\n\n this.outputCtx = null;\n this.input = null;\n this.output = null;\n this.timerID = 0;\n this.imageAspectRatio = 1;\n\n this.personMaskPixelCount = this.personMaskWidth * this.personMaskHeight;\n this.personMask = new ImageData(this.personMaskWidth, this.personMaskHeight);\n this.personMaskCanvas = document.createElement('canvas');\n this.personMaskCanvas.width = this.personMaskWidth;\n this.personMaskCanvas.height = this.personMaskHeight;\n this.personMaskCtx = this.personMaskCanvas.getContext('2d');\n\n this.filters = {};\n this.gifFrames = null;\n this.gifFramesIndex = 0;\n this.gifFrameImageData = null;\n this.tempGifCanvas = document.createElement('canvas');\n this.tempGifContext = this.tempGifCanvas.getContext('2d');\n this.giflocalCount = 0;\n this.enableSharpening = enableSharpening;\n\n this.log(TAG, 'Virtual Background plugin created');\n this.setBackground(this.background);\n }\n\n async init(): Promise<void> {\n if (!this.loadModelCalled) {\n this.log(TAG, 'PREVIOUS LOADED MODEL IS ', this.tfLite);\n this.loadModelCalled = true;\n this.tfLitePromise = loadTFLite();\n this.tfLite = await this.tfLitePromise;\n } else {\n //either it is loading or loaded\n await this.tfLitePromise;\n }\n if (this.enableSharpening) {\n this.initSharpenFilter();\n }\n }\n\n /*\n @depreceated\n */\n isSupported(): boolean {\n //support chrome, firefox, edge TODO: check this\n return (\n navigator.userAgent.indexOf('Chrome') !== -1 ||\n navigator.userAgent.indexOf('Firefox') !== -1 ||\n navigator.userAgent.indexOf('Edg') !== -1 ||\n navigator.userAgent.indexOf('Edge') !== -1\n );\n }\n\n checkSupport(): HMSPluginSupportResult {\n const browserResult = {} as HMSPluginSupportResult;\n if (['Chrome', 'Firefox', 'Edg', 'Edge'].some(value => navigator.userAgent.indexOf(value) !== -1)) {\n browserResult.isSupported = true;\n } else {\n browserResult.isSupported = false;\n browserResult.errType = HMSPluginUnsupportedTypes.PLATFORM_NOT_SUPPORTED;\n browserResult.errMsg = 'browser not supported for plugin, see docs';\n }\n\n return browserResult;\n }\n\n getName(): string {\n return pkg.name;\n }\n\n getPluginType(): HMSVideoPluginType {\n return HMSVideoPluginType.TRANSFORM;\n }\n\n async setBackground(path?: string | HTMLImageElement | HTMLVideoElement) {\n if (path !== '') {\n if (path === 'none') {\n this.log(TAG, 'setting background to :', path);\n this.background = 'none';\n this.backgroundType = 'none';\n this.isVirtualBackground = false;\n } else if (path === 'blur') {\n this.log(TAG, 'setting background to :', path);\n this.background = 'blur';\n this.backgroundType = 'blur';\n this.isVirtualBackground = false;\n } else if (path instanceof HTMLImageElement) {\n this.log('setting background to image', path);\n const img = await this.setImage(path as HTMLImageElement);\n if (!img || !img.complete || !img.naturalHeight) {\n throw new Error('Invalid image. Provide a valid and successfully loaded HTMLImageElement');\n } else {\n this.isVirtualBackground = true;\n this.backgroundImage = img;\n this.backgroundType = 'image';\n }\n } else if (path instanceof HTMLVideoElement) {\n this.log('setting background to video', path);\n this.backgroundVideo = path as HTMLVideoElement;\n this.backgroundVideo.crossOrigin = 'anonymous';\n this.backgroundVideo.muted = true;\n this.backgroundVideo.loop = true;\n this.backgroundVideo.oncanplaythrough = async () => {\n if (this.backgroundVideo != null) {\n await this.backgroundVideo!.play();\n this.isVirtualBackground = true;\n this.backgroundType = 'video';\n }\n };\n } else {\n console.log('setting gif to background');\n this.gifFrames = await this.setGiF(path as string);\n if (this.gifFrames != null && this.gifFrames.length > 0) {\n this.backgroundType = 'gif';\n this.isVirtualBackground = true;\n } else {\n throw new Error('Invalid background supplied, see the docs to check supported background type');\n }\n }\n } else {\n throw new Error('Invalid background supplied, see the docs to check supported background type');\n }\n }\n\n stop(): void {\n if (this.isVirtualBackground) {\n this.backgroundImage?.removeAttribute('src');\n this.backgroundVideo?.removeAttribute('src');\n if (this.backgroundType === 'video') {\n this.backgroundVideo!.loop = false;\n this.backgroundVideo = null;\n }\n }\n if (this.outputCtx) {\n this.outputCtx!.fillStyle = `rgb(0, 0, 0)`;\n this.outputCtx!.fillRect(0, 0, this.output!.width, this.output!.height);\n }\n\n //gif related\n this.gifFrameImageData = null;\n this.gifFrames = null;\n this.giflocalCount = 0;\n this.gifFramesIndex = 0;\n }\n\n processVideoFrame(\n input: HTMLCanvasElement,\n output: HTMLCanvasElement,\n skipProcessing?: boolean,\n ): Promise<void> | void {\n if (!input || !output) {\n throw new Error('Plugin invalid input/output');\n }\n\n this.input = input;\n this.output = output;\n\n const ctx = output.getContext('2d');\n if (ctx!.canvas.width !== input.width) {\n ctx!.canvas.width = input.width;\n }\n if (ctx!.canvas.height !== input.height) {\n ctx!.canvas.height = input.height;\n }\n\n if (this.backgroundType === 'video') {\n this.backgroundVideo!.width = input.width;\n this.backgroundVideo!.height = input.height;\n }\n\n this.outputCtx = ctx!;\n this.imageAspectRatio = input.width / input.height;\n if (this.imageAspectRatio <= 0) {\n throw new Error('Invalid input width/height');\n }\n\n const process = async () => {\n await this.runSegmentation(skipProcessing);\n };\n\n if (this.background === 'none' && !this.isVirtualBackground) {\n this.outputCtx!.globalCompositeOperation = 'copy';\n this.outputCtx!.filter = 'none';\n this.outputCtx!.drawImage(input, 0, 0, input.width, input.height);\n } else {\n process();\n }\n }\n\n private async setImage(image: HTMLImageElement): Promise<any> {\n image.crossOrigin = 'anonymous';\n return new Promise((resolve, reject) => {\n image.onload = () => resolve(image);\n image.onerror = reject;\n });\n }\n\n private setGiF(url: string): Promise<any> {\n return fetch(url)\n .then(resp => resp.arrayBuffer())\n .then(buff => parseGIF(buff))\n .then(gif => {\n return decompressFrames(gif, true);\n });\n }\n\n private log(tag: string, ...data: any[]) {\n console.info(tag, ...data);\n }\n\n private resizeInputData() {\n this.personMaskCtx!.drawImage(\n this.input,\n 0,\n 0,\n this.input!.width,\n this.input!.height,\n 0,\n 0,\n this.personMaskWidth,\n this.personMaskHeight,\n );\n\n const imageData = this.personMaskCtx!.getImageData(0, 0, this.personMaskWidth, this.personMaskHeight);\n //\n const inputMemoryOffset = this.tfLite._getInputMemoryOffset() / 4;\n for (let i = 0; i < this.personMaskPixelCount; i++) {\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3] = imageData.data[i * 4] / 255;\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3 + 1] = imageData.data[i * 4 + 1] / 255;\n this.tfLite.HEAPF32[inputMemoryOffset + i * 3 + 2] = imageData.data[i * 4 + 2] / 255;\n }\n }\n private infer(skipProcessing?: boolean) {\n if (!skipProcessing) {\n this.tfLite._runInference();\n }\n const outputMemoryOffset = this.tfLite._getOutputMemoryOffset() / 4;\n\n for (let i = 0; i < this.personMaskPixelCount; i++) {\n if (this.modelName === 'meet') {\n const background = this.tfLite.HEAPF32[outputMemoryOffset + i * 2];\n const person = this.tfLite.HEAPF32[outputMemoryOffset + i * 2 + 1];\n const shift = Math.max(background, person);\n const backgroundExp = Math.exp(background - shift);\n const personExp = Math.exp(person - shift);\n // Sets only the alpha component of each pixel.\n this.personMask.data[i * 4 + 3] = (255 * personExp) / (backgroundExp + personExp);\n } else if (this.modelName === 'landscape-segmentation') {\n const person = this.tfLite.HEAPF32[outputMemoryOffset + i];\n this.personMask.data[i * 4 + 3] = 255 * person;\n }\n }\n\n this.personMaskCtx!.putImageData(this.personMask, 0, 0);\n }\n\n private postProcessing() {\n this.outputCtx!.globalCompositeOperation = 'copy';\n this.outputCtx!.filter = 'none';\n\n if (this.isVirtualBackground) {\n this.outputCtx!.filter = 'blur(4px)';\n } else {\n this.outputCtx!.filter = 'blur(8px)';\n }\n this.drawPersonMask();\n this.outputCtx!.globalCompositeOperation = 'source-in';\n this.outputCtx!.filter = 'none';\n // //Draw the foreground\n this.outputCtx!.drawImage(this.input!, 0, 0);\n\n if (\n this.enableSharpening &&\n this.output!.width > minVideoWidthForSharpening && // minimum and maximum resolution to enable sharpening filter\n this.output!.height > minVideoHeightForSharpening &&\n this.output!.width < maxVideoWidthForSharpening &&\n this.output!.height < maxVideoHeightForSharpening\n ) {\n this.sharpenFilter();\n }\n\n // //Draw the background\n this.drawSegmentedBackground();\n }\n\n private sharpenFilter() {\n // adding sharpening filter to each frame to improve edges and brightness\n // The basic idea is that you take the weighed sum of a rectangle of pixels from the source image and use that as the output value using convolution filter\n // It is applied intermediate output with black background and only mask data in frame\n // Filter currently used is 3 x 3 sharpening filter with values as shown:\n // [ 0, -1, 0,\n // -1, 5, -1,\n // 0, -1, 0 ]\n const outputImageData = this.outputCtx!.getImageData(0, 0, this.output!.width, this.output!.height);\n\n // filters you may try\n // [-1, -1, -1, -1, 9, -1, -1, -1, -1]\n //[0, -1, 0, -1, 5, -1, 0, -1, 0]\n const output = this.filters.convolute(outputImageData);\n\n this.outputCtx!.putImageData(output, 0, 0);\n }\n\n private drawPersonMask() {\n this.outputCtx!.drawImage(\n this.personMaskCanvas,\n 0,\n 0,\n this.personMaskWidth,\n this.personMaskHeight,\n 0,\n 0,\n this.output!.width,\n this.output!.height,\n );\n }\n\n private drawSegmentedBackground() {\n this.outputCtx!.globalCompositeOperation = 'destination-over';\n this.outputCtx!.imageSmoothingEnabled = true;\n this.outputCtx!.imageSmoothingQuality = 'high';\n if (this.isVirtualBackground) {\n if (this.backgroundType === 'video' && this.backgroundVideo != null && this.backgroundVideo!.readyState >= 4) {\n this.fitVideoToBackground();\n } else if (this.backgroundType === 'image') {\n this.fitImageToBackground();\n } else if (this.backgroundType === 'gif') {\n if (this.giflocalCount > this.gifFrames[this.gifFramesIndex].delay / DEFAULT_DELAY) {\n this.gifFramesIndex++;\n if (this.gifFramesIndex >= this.gifFrames.length) {\n this.gifFramesIndex = 0;\n }\n this.giflocalCount = 0;\n } else {\n this.giflocalCount++;\n }\n this.fitGifToBackground();\n }\n } else {\n this.addBlurToBackground();\n }\n }\n\n private async runSegmentation(skipProcessing?: boolean) {\n if (this.tfLite) {\n // const start = performance.now();\n\n this.resizeInputData();\n await this.infer(skipProcessing);\n this.postProcessing();\n // const end = performance.now();\n // this.log(TAG,\"time taken\",end -start);\n }\n }\n\n private fitVideoToBackground() {\n this.fitData(this.backgroundVideo, this.backgroundVideo!.videoWidth, this.backgroundVideo!.videoHeight);\n }\n\n private fitImageToBackground() {\n this.fitData(this.backgroundImage, this.backgroundImage!.width, this.backgroundImage!.height);\n }\n\n private fitGifToBackground() {\n if (this.gifFrameImageData == null) {\n const dims = this.gifFrames[this.gifFramesIndex].dims;\n this.tempGifCanvas!.width = dims.width;\n this.tempGifCanvas!.height = dims.height;\n this.gifFrameImageData = this.tempGifContext.createImageData(dims.width, dims.height);\n }\n // set the patch data as an override\n this.gifFrameImageData.data.set(this.gifFrames[this.gifFramesIndex].patch);\n this.tempGifContext.putImageData(this.gifFrameImageData, 0, 0);\n\n this.fitData(this.tempGifCanvas, this.gifFrameImageData!.width, this.gifFrameImageData!.height);\n }\n\n private fitData(data: any, dataWidth: number, dataHeight: number) {\n let inputWidth: any, inputHeight: any, xoffset: any, yoffset: any;\n if (dataWidth / dataHeight < this.imageAspectRatio) {\n inputWidth = dataWidth;\n inputHeight = dataWidth / this.imageAspectRatio;\n xoffset = 0;\n yoffset = (dataHeight - inputHeight) / 2;\n } else {\n inputHeight = dataHeight;\n inputWidth = dataHeight * this.imageAspectRatio;\n yoffset = 0;\n xoffset = (dataWidth - inputWidth) / 2;\n }\n this.outputCtx!.drawImage(\n data,\n xoffset,\n yoffset,\n inputWidth,\n inputHeight,\n 0,\n 0,\n this.output!.width,\n this.output!.height,\n );\n }\n\n private async addBlurToBackground() {\n let blurValue = '15px';\n if (this.input!.width <= 160) {\n blurValue = '5px';\n } else if (this.input!.width <= 320) {\n blurValue = '10px';\n } else if (this.input!.width <= 640) {\n blurValue = '15px';\n } else if (this.input!.width <= 960) {\n blurValue = '20px';\n } else if (this.input!.width <= 1280) {\n blurValue = '25px';\n } else if (this.input!.width <= 1920) {\n blurValue = '30px';\n }\n\n this.outputCtx!.filter = `blur(${blurValue})`;\n this.outputCtx!.drawImage(this.input!, 0, 0, this.output!.width, this.output!.height);\n }\n\n private initSharpenFilter(): any {\n this.filters.tmpCanvas = document.createElement('canvas');\n this.filters.tmpCtx = this.filters.tmpCanvas.getContext('2d');\n\n this.filters.createImageData = (w: number, h: number) => {\n return this.filters.tmpCtx.createImageData(w, h);\n };\n\n this.filters.convolute = (pixels: ImageData, weights = [0, -1, 0, -1, 5, -1, 0, -1, 0], opaque: boolean) => {\n const side = Math.round(Math.sqrt(weights.length));\n\n const halfSide = Math.floor(side / 2);\n const src = pixels.data;\n const sw = pixels.width;\n const sh = pixels.height;\n // pad output by the convolution matrix\n const w = sw;\n const h = sh;\n const output = this.filters.createImageData(w, h);\n const dst = output.data;\n // go through the destination image pixels\n const alphaFac = opaque ? 1 : 0;\n for (let y = 0; y < h; y = y + 1) {\n for (let x = 0; x < w; x = x + 1) {\n const dstOff = (y * w + x) * 4;\n\n if (src[dstOff + 3] === 0) {\n continue;\n } else if (x < w && y < h) {\n const sy = y;\n const sx = x;\n\n // calculate the weighed sum of the source image pixels that\n // fall under the convolution matrix\n let r = 0,\n g = 0,\n b = 0,\n a = 0;\n for (let cy = 0; cy < side; cy++) {\n for (let cx = 0; cx < side; cx++) {\n const scy = sy + cy - halfSide;\n const scx = sx + cx - halfSide;\n if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {\n const srcOff = (scy * sw + scx) * 4;\n const wt = weights[cy * side + cx];\n r += src[srcOff] * wt;\n g += src[srcOff + 1] * wt;\n b += src[srcOff + 2] * wt;\n a += src[srcOff + 3] * wt;\n }\n }\n }\n dst[dstOff] = r;\n dst[dstOff + 1] = g;\n dst[dstOff + 2] = b;\n dst[dstOff + 3] = a + alphaFac * (255 - a);\n }\n }\n }\n return output;\n };\n }\n}\n"],
|
|
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MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"format": "prettier --write src/**/*.ts"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@100mslive/hms-video": "^0.
|
|
27
|
+
"@100mslive/hms-video": "^0.2.0"
|
|
28
28
|
},
|
|
29
29
|
"name": "@100mslive/hms-virtual-background",
|
|
30
30
|
"author": "ashish17",
|
|
31
31
|
"module": "dist/index.js",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@100mslive/hms-video": "0.5.1
|
|
33
|
+
"@100mslive/hms-video": "0.5.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@tensorflow/tfjs-backend-webgl": "^3.3.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"defineTFLite.ts",
|
|
49
49
|
"importing.test.ts"
|
|
50
50
|
],
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2b27a0da2da14570ec448b6ff8486dff12b7eb4d"
|
|
52
52
|
}
|