xxxxxxxxxx
74
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
}
let video;
let label = "Checking...";
let classifier;
let modelURL = 'https://teachablemachine.withgoogle.com/models/u47LH64IF/';
// STEP 1: Load the model
function preload() {
classifier = ml5.imageClassifier(modelURL + 'model.json');
}
function setup() {
createCanvas(500, 520);
// Create the video
video = createCapture(VIDEO);
video.hide();
// STEP 2: Start classifying
classifyVideo();
}
// STEP 2 classify the video
function classifyVideo() {
classifier.classify(video, gotResults);
}
function draw() {
background(0);
image(video, 0, 0);
textSize(32);
textAlign(CENTER, CENTER);
fill(255);
text(label, width / 2, height - 16);
// Emoji check mark will appear when Banana is shown
let emoji = "⌚";
let question = "Banana";
if (label == question) {
emoji = "✔";
} else if (label != question) {
emoji = "❌";
}
// Drawing the emoji and question section
textSize(60);
text(emoji, width -40 , height - 60 );
textSize(30)
text("Find: " + question, width -400 , height -100 );
}
// STEP 3: Get the classification!
function gotResults(error, results) {
if (error) {
console.error(error);
return;
}
// Storing the label and classifying again!
label = results[0].label;
classifyVideo();
}