// Cloned by Cian on 4 Dec 2021 from World "Recognise any image" by Starter user
// Please leave this clone trail here.
// ML5 image recognition using MobileNet
// uses AB framework
// enter URL of image at runtime
// no run, pause, step
AB.drawRunControls = false;
let classifier;
let img;
// asynchronous loads of resources, with callback functions when ready
var classifierLoaded = false;
var imgLoaded = false;
AB.world.newRun = function()
{
ABWorld.init ( 'lightblue' );
//AB.headerRHS();
// DoodleNet load pretrained
doodleClassifier = ml5.imageClassifier('DoodleNet', modelReady)
function modelReady() {
console.log('model loaded');
// pass canvas itself and pass it to model for prediction (retreive from gotResults)
doodleClassifier.classify(canvas, gotResults);
}
// callback prediction from nn
function gotResults(error, results){
if (error){
console.error(error);
return;
}
console.log(results);
}
};
//---- setup -------------------------------------------------------
// Do NOT make a setup function.
// This is done for you in the API. The API setup just creates a canvas.
// Anything else you want to run at the start should go into the following two functions.
let clearButton;
let canvas;
function beforesetup() // Optional
{
// Anything you want to run at the start BEFORE the canvas is created
clearButton = createButton('clear');
clearButton.mousePressed(clearCanvas);
}
function clearCanvas() {
background(255);
}
function aftersetup() // Optional
{
// Anything you want to run at the start AFTER the canvas is created
}
//---- draw -------------------------------------------------------
function draw() // Optional
{
// Can put P5 instructions to be executed every step here, or in AB.world.nextStep()
if (mouseIsPressed) {
strokeWeight(8);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}