
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
segmentation-person-media
Advanced tools
Person segmentation from a media element and manipulate background in the browser
Person segmentation from a media element and manipulate background in the browser.
To segment person, it's using BodyPix from tensor-flow project.
npm install segmentation-person-media
import { load } from 'segment-person-media'
const segmentationPersonMedia = await load()
// 1. Create a MediaStream from HTMLVidelElement
const localVideo = document.getElementById('local-video') as HTMLVideoElement
// 1.1 Mask
const maskedStream = segmentationMedia.createMaskedStream({ src: localVideo } })
// 1.2 Change background
const imageData = getSelectedBackgroundImage()
const changedBackGroundStream = segmentationMedia.createChangedBackgroundStream({ src: localVideo, backgroundImage: imageData })
// 1.3 Blur
const bluredStream = segmentationMedia.createBluredStream({ src: localVideo })
// 2. Create a ImageData from HTMLImageElement
const personImage = document.getElementById('person-image') as HTMLImageElement
// 2.1 Mask
const maskedImageData = await segmentationMedia.createMaskedImageData({ src: personImage })
// 2.2 Change background
const imageData = getSelectedBackgroundImage()
const changedBackGroundImageData = await segmentationMedia.createChangedBackgroundImageData({
src: personImage, backgroundImage: imageData
})
// 2.3 Blur
const bluredImageData = await segmentationMedia.createBluredImageData({
src: personImage
})
You can check demo code lines to get to know details of how to use.
https://github.com/joe-re/segmentation-person-media/blob/main/demo/main.ts
You need to the model data to segment person at first.
const segmentationPersonMedia = await load()
SegmentPersonMedia accepts the same arguments as BodyPix and you can adjust it for your project.
ref: https://github.com/tensorflow/tfjs-models/tree/master/body-pix#loading-the-model
For creating a stream APIs, it requires canvas.captureStream for the browser.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream
SegmentationConfig is the same as segmentPerson's config from BodyPix.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#person-segmentationCreate a masked background stream from HTMLVideoElement.
const stream = segmentationMedia.createMaskedStream({ src: localVideo } }
{
src: HTMLVideoElement,
frameRate?: number, // default: 30
options?: {
color?: { // default: { r: 255, g: 255, b: 255, a: 255 }
r: number,
g: number,
b: number,
a: number
},
maskOpacity?: number, // default: 1
maskBlurAmount?: number, // default: 0
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawMask.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#bodypixdrawmask
MediaStream
Create a changed background stream from HTMLVideoElement.
const stream = segmentationMedia.createChangedBackgroundStream({ src: localVideo, backgroundImage: imageData })
{
src: HTMLVideoElement,
frameRate?: number, // default: 30
backgroundImage: HTMLImageElement | HTMLCanvasElement | ImageData,
options?: {
maskOpacity?: number, // default: 1
maskBlurAmount?: number, // default: 0
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawMask.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#bodypixdrawmask
MediaStream
Create a blured background stream from HTMLVideoElement.
const stream = segmentationMedia.createBluredStream({ src: localVideo })
{
src: HTMLVideoElement,
frameRate?: number, // default: 30
options?: {
backgroundBlurAmount?: number, // default: 9
edgeBlurAmount?: number, // default: 9
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawBokehEffect.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#inputs-4
MediaStream
Create a masked background image data from MediaElement.
const imageData = segmentationMedia.createMaskedImageData({ src: personImage })
{
src: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement,
options?: {
color?: { // default: { r: 255, g: 255, b: 255, a: 255 }
r: number,
g: number,
b: number,
a: number
},
maskOpacity?: number, // default: 1
maskBlurAmount?: number, // default: 0
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawMask.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#bodypixdrawmask
ImageData
Create a masked background image data from MediaElement.
const imageData = await segmentationMedia.createChangedBackgroundImageData({
src: personImage, backgroundImage: imageData
})
{
src: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement,
backgroundImage: HTMLImageElement | HTMLCanvasElement | ImageData,
options?: {
maskOpacity?: number, // default: 1
maskBlurAmount?: number, // default: 0
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawMask.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#bodypixdrawmask
MediaStream
Create a blured background image data from MediaElement.
const imageData = await segmentationMedia.createBluredImageData({
src: personImage
})
{
src: HTMLVideoElement,
options?: {
backgroundBlurAmount?: number, // default: 9
edgeBlurAmount?: number, // default: 9
flipHorizontal?: boolean // default: false
},
config?: SegmentationConfig
}
Options includes some parameters to give drawPix.drawBokehEffect.
https://github.com/tensorflow/tfjs-models/tree/master/body-pix#inputs-4
FAQs
Person segmentation from a media element and manipulate background in the browser
We found that segmentation-person-media demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.