xxxxxxxxxx
56
//https://teachablemachine.withgoogle.com/models/RnTqOkMCJ/
let myModel;
let myVideo;
let myResults;
function preload() {
myModel = ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/RnTqOkMCJ/model.json', modelLoaded)
}
function modelLoaded(){
console.log('myModel', myModel)
}
function setup() {
createCanvas(800, 600);
myVideo = createCapture(VIDEO);
myVideo.hide();
classifyMyVideo();
textAlign(CENTER);
textSize(35);
fill(255);
}
function draw() {
background(220);
image(myVideo, 0,0, width, height);
if(myResults){
const label = myResults[0].label;
text(myResults[0].label, 230, 250, width/2, height/2);
if (label == 'No Water Bottle'){
text('😀', width/2, height/2, + 100)
}
if (label == 'Water Bottle'){
text('😂', width/2, height/2, + 100)
}
}
}
function classifyMyVideo(){
myModel.classify(myVideo, gotResults);
}
function gotResults(error, results){
if(error){
console.log(error);
}
if(results){
console.log(results);
myResults= results;
classifyMyVideo();
}
}