Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<p align="center">
<img width="300" src="lab07.gif">
</p>

```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();
}
```
Binary file added lab07.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.