xxxxxxxxxx
64
let myVideo;
let myClassifier;
let myResults;
let myVoice;
let myEmojis = {
'monitor': '🖥️',
'water bottle': '🍼',
'ipod': '📱'
}
function setup() {
createCanvas(640, 480);
myVideo = createCapture(VIDEO);
myVideo.hide();
myClassifier = ml5.imageClassifier('MobileNet', modelReady);
textSize(48)
fill(225, 120, 0)
textAlign(CENTER)
myVoice = new p5.Speech();
}
function modelReady() {
console.log(myClassifier);
myClassifier.classify(myVideo, gotResult);
myVoice.listVoices();
}
function gotResult(error, results) {
if (error) {
console.log(error)
}
if (results) {
myResults = results;
myClassifier.classify(myVideo, gotResult);
const mySentence = 'I see ${myResults[0].label}';
myVoice.setVoice('Grandpa (English (UK))');
myVoice.setPitch(1.5);
myVoice.setRate(0.5);
myVoice.speak(mySentence);
}
}
function draw() {
image(myVideo, 0, 0, width, height)
if (myResults) {
text(myResults[0].label, width/2, height/2)
if (myEmojis[myResults[0].label]) {
drawEmojis(myEmojis[myResults[0].label], width/2, height/2)
}
}
}
function drawEmojis(emoji) {
for (let i = 0; i < 20; i++){
for (let j = 0; j < 20; j++){
//text(myEmojis[myResults[0].label], i * 32, j * 24)
textSize(random() * 200);
text(myEmojis[myResults[0].label], random() * 640, random() * 480);
}
}
}