diff --git a/README.md b/README.md index 98f6991..338678e 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,95 @@ ## Submission Instructions - Create a pull request against this repo - push your code and/or a link to a gif or video of your work + +# Result + +

+ +

+ +```JavaScript +// Copyright (c) 2019 ml5 +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +/* === +ml5 Example +Webcam Image Classification using a pre-trained customized model and p5.js +This example uses p5 preload function to create the classifier +=== */ + +// Classifier Variable +let classifier; + +// TODO: Upate your model URL +let imageModelURL = 'https://teachablemachine.withgoogle.com/models/svxO-CtvD/'; + +// Video +let video; +let flippedVideo; +// To store the classification +let label = ""; +let peek_img; + +// Load the model first +function preload() { + classifier = ml5.imageClassifier(imageModelURL + 'model.json'); +} + +function setup() { + createCanvas(320, 260); + + // Create the video + video = createCapture(VIDEO); + video.size(320, 240); + video.hide(); + + peek_img = createImg("https://s.abcnews.com/images/Entertainment/norbert-high-five-dog1-ht-mem-180523_hpMain_16x9_992.jpg"); + peek_img.hide(); + + flippedVideo = ml5.flipImage(video) + // Start classifying + classifyVideo(); +} + +function draw() { + background(0); + + // Draw the video + image(flippedVideo, 0, 0); + + // Draw the label + fill(255); + textSize(16); + textAlign(CENTER); + + // TODO: Custom logic based on labels + if (label === "Class 2") { + image(peek_img, 90, 20, peek_img.width*0.3, peek_img.height*0.3); + text("Puppy High Five!!:))", width / 2, height - 4); + } else if (label === "Class 1") { + text("Where's my puppy:(", width / 2, height - 4); + } +} + +// Get a prediction for the current video frame +function classifyVideo() { + flippedVideo = ml5.flipImage(video) + classifier.classify(flippedVideo, gotResult); +} + +// 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. + label = results[0].label; + // Classifiy again! + classifyVideo(); +} +``` diff --git a/lab07.gif b/lab07.gif new file mode 100644 index 0000000..0c312da Binary files /dev/null and b/lab07.gif differ