xxxxxxxxxx
44
let video;
let TMmodel;
let label = "Identifying...";
function preload(){
TMmodel = ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/Jh4HQ3ll0/model.json');
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
classifyImages();
}
function classifyImages(){
TMmodel.classify(video, handleResults);
}
function handleResults(error, result){
if(error){
console.error(error);
return;
}
//uncomment the line below to see the details of the result of the classification process
//in the concole below
console.log(result);
label = result[0].label;
classifyImages();
}
function draw() {
background(220);
//draw the video (not mirrored)
image(video, 0, 0);
//draw the label at the bottom of the canvas
textSize(36);
fill(255, 0, 0);
textAlign(CENTER, CENTER);
text(label, width/2, height - 18);
}