我正在尝试制作一个网络摄像头过滤器,它可以进行身体分割以掩盖人背后的背景并将图片放置在背景中。Zoom 或其他平台上的背景选项之类的。我正在考虑使用 ml5 和 BodyPix,但我只达到了这一点(https://github.com/ml5js/ml5-library/blob/main/examples/p5js/BodyPix/BodyPix_Webcam/sketch.js):
let bodypix;
let video;
let segmentation;
const options = {
outputStride: 8, // 8, 16, or 32, default is 16
segmentationThreshold: 0.3, // 0 - 1, defaults to 0.5
};
function preload() {
bodypix = ml5.bodyPix(options);
}
function setup() {
createCanvas(320, 240);
// load up your video
video = createCapture(VIDEO, videoReady);
video.size(width, height);
}
function videoReady() {
bodypix.segment(video, gotResults);
}
function draw() {
background(0);
if (segmentation) {
image(segmentation.backgroundMask, 0, 0, width, height);
}
}
function gotResults(error, result) {
if (error) {
console.log(error);
return;
}
segmentation = result;
bodypix.segment(video, gotResults);
}
任何人都有将图像放置在背景中的任何解决方案?也许还有另一种方法来编码这样的东西?谢谢!