@dannadori/posenet-worker-js
v1.0.32
Published
This is webworker module for [Posenet](https://github.com/tensorflow/tfjs-models/tree/master/posenet).
Downloads
35
Maintainers
Readme
This is webworker module for Posenet.
PoseNet
Install
$ npm install \@dannadori/posenet-worker-js
API
generatePoseNetDefaultConfig: () => PoseNetConfig;
generateDefaultPoseNetParams: () => PoseNetOperationParams;
drawSkeltonAndPoint: (srcCanvas: HTMLCanvasElement, prediction: poseNet.Pose[]) => ImageData;
PoseNetWorkerManager
init(config?: PoseNetConfig | null): Promise<unknown>;
predict(targetCanvas: HTMLCanvasElement, params?: PoseNetOperationParams): Promise<poseNet.Pose[]>;
Configuration and Parameter
export interface PoseNetConfig{
browserType : BrowserType
model : ModelConfig
processOnLocal : boolean
// processWidth : number
// processHeight : number
}
export enum PoseNetFunctionType{
SinglePerson,
MultiPerson,// Not implemented
}
export interface PoseNetOperationParams{
type : PoseNetFunctionType
singlePersonParams : SinglePersonInterfaceConfig
multiPersonParams : MultiPersonInferenceConfig
}
Step by step
Create environment and install package
$ npx create-react-app demo --template typescript
$ cd demo/
$ npm install
$ npm install @dannadori/posenet-worker-js
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 { PoseNetWorkerManager, generateDefaultPoseNetParams, generatePoseNetDefaultConfig, drawSkeltonAndPoint } from '@dannadori/posenet-worker-js'
class App extends React.Component{
manager = new PoseNetWorkerManager()
config = generatePoseNetDefaultConfig()
params = generateDefaultPoseNetParams()
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)=>{
const imageData = drawSkeltonAndPoint(this.srcCanvas, res)
console.log(res)
this.dstCanvas.getContext("2d")!.putImageData(imageData, 0, 0)
})
}
srcImage.src = "./srcImage.jpg"
}
render = ()=>{
return (
<div className="App">
</div>
);
}
}
export default App;
build and start
$ npm run start