xxxxxxxxxx
let capture;
let detector;
let detections = [];
function preload() {
detector = ml5.objectDetector("cocossd");
}
function setup() {
createCanvas(640, 480);
capture = createCapture(VIDEO, gotCapture);
capture.size(640, 480);
capture.hide();
}
function draw() {
image(capture, 0, 0);
for (let o of detections) {
stroke(0, 255, 0);
strokeWeight(2);
noFill();
rect(o.x, o.y, o.width, o.height);
noStroke();
fill(255, 0, 0);
textSize(24);
text(o.label, o.x + 10, o.y - 10);
}
}
function gotCapture(error, results) {
detector.detect(capture, gotDetections);
}
function gotDetections(error, results) {
if (error) {
print("error " + error);
}
detections = results;
detector.detect(capture, gotDetections);
}