xxxxxxxxxx
42
let video;
let classifier;
let predictions = [];
function setup() {
createCanvas(640, 480);
// capture the webcam and store it in 'video'
video = createCapture(VIDEO);
video.size(width, height);
//hide the html video element
video.hide();
// start the classifier
classifier = ml5.imageClassifier('MobileNet', video, modelReady);
}
function modelReady() {
console.log("model ready");
classifyVideo()
}
// Get a prediction for the current video frame
function classifyVideo() {
classifier.classify(gotResults);
}
function gotResults(err, results) {
predictions = results;
classifyVideo();
}
function draw() {
background(220);
image(video, 0, 0, width, height);
if(predictions.length > 0){
textSize(30)
text(predictions[0].label, 10, height/2)
}
}