Created
November 2, 2018 11:01
-
-
Save RomainMaillot13/f0ff27f8b0419089175399ab239f4a61 to your computer and use it in GitHub Desktop.
Video detection
This file contains 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
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment