xxxxxxxxxx
33
// ObjectDetection (c) 2021 kouichi.matsuda@gmail.com
let img;
function preload() {
img = loadImage("pose.jpg");
}
function setup() {
let od = ml5.objectDetector("cocossd", () => {
od.detect(img, gotResult);
});
createCanvas(img.width, img.height);
image(img, 0, 0, width, height);
}
function draw() {}
function gotResult(err, r) {
print(r);
if (err) {
print(err);
} else {
for (let i = 0; i < r.length; i++) {
noStroke();
fill(255, 0, 0);
text(r[i].label, r[i].x, r[i].y - 5);
noFill();
stroke(255, 0, 0);
rect(r[i].x, r[i].y, r[i].width, r[i].height);
}
}
}