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) } } }