xxxxxxxxxx
let video;
let detector;
let detections;
let voice = new p5.Speech();
function setup() {
createCanvas(640, 480,WEBGL);
video = createCapture(VIDEO);
video.size(width, height);
video.hide();
graphics = createGraphics(640,480);
detector = ml5.objectDetector('cocossd', modelReady)
}
function modelReady() {
console.log('model loaded')
detect();
}
function detect() {
detector.detect(video, gotResults);
}
function gotResults(err, results) {
if (err) {
console.log(err);
return
}
detections = results;
detect();
}
function draw() {
background(63);
translate(-width/2,-height/2);
image(video, 0, 0, width, height);
//graphics.stroke(222);
texture(graphics);
if (detections) {
detections.forEach(detection => {
graphics.fill('black');
graphics.strokeWeight(4);
graphics.textSize(44);
graphics.text(detection.label + ' ' + nf(detection.confidence, 0, 2) + '%' + '\n',random(width),random(height));
graphics.textSize(44);
graphics.text("リモートコントロール",random(width),random(height));
graphics.fill('white');
graphics.text(detection.label + ' ' + nf(detection.confidence, 0, 2) + '%' + '\n',random(width),random(height));
graphics.textSize(44);
graphics.text("リモートコントロール",random(width),random(height));
voice.speak(detection.label);
noStroke();
//fill(2);
strokeWeight(2);
rect(detection.x + 4,detection.y+10,detection.width,detection.height);
fill(222)
//textSize(16);
//text(detection.label + ' ' + nf(detection.confidence, 0, 2) + '%' + '\n' , detection.x + 4, detection.y + 10)
noFill();
strokeWeight(3);
if (detection.label === 'person') {
stroke(0, 255, 0);
} else {
stroke(0, 0, 255);
}
rect(detection.x, detection.y, detection.width, detection.height);
})
graphics.clear();
}
}
🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈
🌟 Thank you for using ml5.js v0.5.0 🌟
Please read our community statement to ensure
that the use of this software reflects the values
of the ml5.js community:
↳ https://ml5js.org/about
Reporting:
↳ https://github.com/ml5js/ml5-library/issues
↳ Email: info@ml5js.org
🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈
p5.Speech: voices loaded!