xxxxxxxxxx
53
// Your code will go here
// Open up your console - if everything loaded properly you should see the version number
// corresponding to the latest version of ml5 printed to the console and in the p5.js canvas.
console.log('ml5 version:', ml5.version);
let video;
let model;
let label = "";
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
// Load the Roboflow model
loadModel();
}
function loadModel() {
// Your Roboflow model URL
const modelURL = 'https://detect.roboflow.com/playing-cards-ow27d';
// Load the model using ml5's featureExtractor method
model = ml5.featureExtractor(modelURL, modelLoaded);
}
function modelLoaded() {
console.log('Model Loaded!');
classifyVideo();
}
function classifyVideo() {
model.classify(video, gotResults);
}
function gotResults(error, results) {
if (error) {
console.error(error);
return;
}
label = results[0].label;
classifyVideo();
}
function draw() {
image(video, 0, 0);
// Display the label
fill(255, 0, 0);
textSize(16);
text(label, 10, height - 10);
}