xxxxxxxxxx
43
//let img;
let video;
let detector;
let detections = [];
function preload() {
//img = loadImage('dog_cat640.jpg');
detector = ml5.objectDetector("cocossd");
}
function gotDetections(error, results) {
if (error) {
console.error(error);
}
detections = results;
detector.detect(video,gotDetections);
}
function setup() {
createCanvas(640, 480);
// createCanvas(640, 640);
video = createCapture(VIDEO);
video.size(640,480);
video.hide();
detector.detect(video, gotDetections);
}
function draw() {
image(video, 0, 0);
for (let i = 0; i < detections.length; i++) {
let object = detections[i];
stroke(0, 255, 0);
strokeWeight(4);
noFill();
rect(object.x, object.y, object.width, object.height);
noStroke();
fill(255);
textSize(24);
text(object.label, object.x + 10, object.y + 24);
}
}