Skip to content

Instantly share code, notes, and snippets.

@RomainMaillot13
Created November 2, 2018 11:01
Show Gist options
  • Save RomainMaillot13/f0ff27f8b0419089175399ab239f4a61 to your computer and use it in GitHub Desktop.
Save RomainMaillot13/f0ff27f8b0419089175399ab239f4a61 to your computer and use it in GitHub Desktop.
Video detection
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