A Pen by Shigeru Kobayashi on CodePen.
Created
August 30, 2018 04:42
-
-
Save kotobuki/8f061252f03f729038bfc11aa0332345 to your computer and use it in GitHub Desktop.
Video Classification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Webcam Image Classification using MobileNet and p5.js</title> | |
</head> | |
<body> | |
<h1>Webcam Image Classification using MobileNet and p5.js</h1> | |
<p id='status'>Loading Model...</p> | |
<p> | |
The MobileNet model labeled this as <span id="result">...</span> | |
<br/>with a confidence of <span id="probability">...</span>. | |
</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://github.com/ml5js/ml5-examples/blob/master/p5js/ImageClassification/ImageClassification_Video/sketch.js | |
let classifier; | |
let video; | |
function setup() { | |
noCanvas(); | |
// Create a camera input | |
video = createCapture(VIDEO); | |
// Initialize the Image Classifier method with MobileNet and the video as the second argument | |
classifier = ml5.imageClassifier("MobileNet", video, modelReady); | |
} | |
function modelReady() { | |
// Change the status of the model once its ready | |
select("#status").html("Model Loaded"); | |
// Call the classifyVideo function to start classifying the video | |
classifyVideo(); | |
} | |
// Get a prediction for the current video frame | |
function classifyVideo() { | |
classifier.predict(gotResult); | |
} | |
// When we get a result | |
function gotResult(err, results) { | |
// The results are in an array ordered by probability. | |
select("#result").html(results[0].className); | |
select("#probability").html(nf(results[0].probability, 0, 2)); | |
classifyVideo(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.1/p5.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.1/addons/p5.dom.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.1/addons/p5.sound.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/ml5.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment