xxxxxxxxxx
47
let bodypix;
let segmentation;
let img;
function preload() {
img = loadImage('data/harriet.jpg');
bodypix = ml5.bodyPix()
}
function setup() {
createCanvas(480, 560);
bodypix.segment(img, gotResults)
}
function gotResults(err, result) {
if (err) {
console.log(err)
return
}
segmentation = result;
// get the array data from the result object.
const array1 = segmentation.raw.data;
console.log(segmentation.raw.data);
console.log(array1);
// processing the array I got but there was a problem
for (int i = 0; i < array1.length ;i++){
if(array1[i] == 0){
console.log(array[i]);
// array1[i] = 50;
}else{
array1[i] = 180;
}
}
console.log(array1);
background(0);
image(img, 0, 0, width, height)
image(segmentation.maskBackground, 0, 0, width, height)
}
}