Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dannadori/bisenetv2-celebamask-worker-js

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dannadori/bisenetv2-celebamask-worker-js

![image](https://user-images.githubusercontent.com/48346627/97803282-822e3e80-1c8c-11eb-8635-74d937e5a8f6.png)

  • 1.0.14
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

BiseNetv2 Celeb A Mask

image

Install

## install
$ npm install @dannadori/bisenetv2-celebamask-worker-js
$ cp node_modules/\@tensorflow/tfjs-backend-wasm/dist/tfjs-backend-wasm.wasm public/

API

generateBisenetV2CelebAMaskDefaultConfig: () => BisenetV2CelebAMaskConfig;
generateDefaultBisenetV2CelebAMaskParams: () => BisenetV2CelebAMaskOperatipnParams;
export declare const createForegroundImage: (srcCanvas: HTMLCanvasElement, prediction: number[][]) => ImageData;

BisenetV2CelebAMaskWorkerManager
init(config: BisenetV2CelebAMaskConfig | null): Promise<unknown>;
predict(targetCanvas: HTMLCanvasElement, params?: BisenetV2CelebAMaskOperatipnParams): Promise<number[][]>;

Configuration and Parameter

export interface BisenetV2CelebAMaskConfig{
    browserType         : BrowserType
    processOnLocal      : boolean
    useTFWasmBackend    : boolean
    wasmPath            : string
    modelPath           : string
    workerPath          : string
}

export interface BisenetV2CelebAMaskOperatipnParams{
    type        : BisenetV2CelebAMaskFunctionType
    processWidth        : number
    processHeight       : number
}

export enum BisenetV2CelebAMaskFunctionType{
    Mask,
    xxx, // Not implemented
}


Step by step

Create environment and install package

$ npx create-react-app demo  --template typescript
$ cd demo/
$ npm install
$ npm install @dannadori/bisenetv2-celebamask-worker-js
$ cp node_modules/\@tensorflow/tfjs-backend-wasm/dist/tfjs-backend-wasm.wasm public/

Add source image to public.

In this time, the name is "srcImage.jpg"

Edit src/App.tsx

Sample code is here.

import React from 'react';
import './App.css';
import { BisenetV2CelebAMaskWorkerManager, generateBisenetV2CelebAMaskDefaultConfig, generateDefaultBisenetV2CelebAMaskParams, createForegroundImage } from '@dannadori/bisenetv2-celebamask-worker-js'

class App extends React.Component{
  
  manager = new BisenetV2CelebAMaskWorkerManager()
  config = generateBisenetV2CelebAMaskDefaultConfig()
  params = generateDefaultBisenetV2CelebAMaskParams()

  srcCanvas = document.createElement("canvas")
  dstCanvas = document.createElement("canvas")

  componentDidMount = () =>{
    document.getRootNode().lastChild!.appendChild(this.srcCanvas)
    document.getRootNode().lastChild!.appendChild(this.dstCanvas)
    const srcImage = document.createElement("img")
    srcImage.onload = () =>{
      this.manager.init(this.config).then(()=>{
        this.srcCanvas.getContext("2d")!.drawImage(
          srcImage, 0, 0, this.srcCanvas.width, this.dstCanvas.height)
        return this.manager.predict(this.srcCanvas, this.params)
      }).then((res)=>{
        console.log(res)
        const foreground = createForegroundImage(this.srcCanvas, res)
        this.dstCanvas.getContext("2d")!.putImageData(foreground, 0, 0)
      })
    }
    srcImage.src = "./srcImage.jpg"
  }

  render = ()=>{
    return (
      <div className="App">
      </div>
    );
  }
}

export default App;

build and start

$ npm run start

Keywords

FAQs

Package last updated on 02 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc