Art Trust

Paper Material Recognizer

Art Trust

https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js https://unpkg.com/ml5@latest/dist/ml5.min.js // Classifier Variable let classifier; // Model URL let imageModelURL = ‘https://teachablemachine.withgoogle.com/models/AJr9IcM-M/’; // Video let video; let flippedVideo; // To store the classification let label = “"; let input; let img; // Load the model first function preload() { classifier = ml5.imageClassifier(imageModelURL + ‘model.json’); } function setup() { createCanvas(400, 400); input = createFileInput(handleFile); input.position(0,450); // Start classifying } function draw() { background(0); // Draw the video image(img, 0, 0, width, height-16); // Draw the label fill(255); textSize(16); textAlign(CENTER); text(label, width / 2, height – 4); } // Get a prediction for the current video frame function classifyVideo() { img.resize(224,224); print(img.width); classifier.classify(img, gotResult); } function handleFile(file) { print(file); if (file.type === ‘image’) { img = loadImage(file.data, classifyVideo) // img.hide(); } else { img = null; } } // When we get a result function gotResult(error, results) { // If there is an error if (error) { console.error(error); return; } // The results are in an array ordered by confidence. // console.log(results[0]); label = results[0].label; // label = “1234″; print(label); draw(); // Classifiy again! // classifyVideo(); }