p5 sketch with BodyPix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
747 B

let bodypix;
let video;
let segmentation;
let img;
let ready = false;
const options = {
outputStride: 16,
segmentationThreshold: 0.3
}
function preload() {
video = createCapture(VIDEO);
bodypix = ml5.bodyPix(video, options, modelReady)
}
function setup() {
createCanvas(480, 360);
video.size(480, 360);
}
function modelReady(){
console.log('model ready!');
ready = true;
bodypix.segment(gotResults)
}
function gotResults(err, result) {
if (err) {
console.log(err)
return
}
segmentation = result;
bodypix.segment(gotResults)
}
function draw() {
background(0);
image(video, 0, 0, 480, 360)
if(ready){
if(segmentation) {
image(segmentation.maskBackground, 0, 0, 480, 360)
console.log(segmentation)
}
}
}