How be politely request that face masks must be worn in public to prevent the spread of disease? Machine Learning can help!

Simply modify the code of image classifier example (demo) from the coding session. Here is the result:

Before wearing a mask. You can not see youself on the screen.

Purple ink on my face is not a mask, just for web privacy.

After wearing a mask. You can see your masked face now….

Thing could be improved: De-bouncing for search results.

// Copyright (c) 2018 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

/* ===
ml5 Example
Webcam Image Classification using MobileNet and p5.js
This example uses a callback pattern to create the classifier
=== */

let classifier;
let video;
let resultsP;
let mask_result;


function setup() {
  createCanvas(710, 400);
  // Create a camera input
  video = createCapture(VIDEO);
  textSize(40);
  video.hide();

  // Initialize the Image Classifier method with MobileNet and the video as the second argument
  classifier = ml5.imageClassifier('MobileNet', video, modelReady);
  resultsP = createP('Loading model and video...');
}

function draw() {

  if(mask_result !== -1){

    image(video, 0, 0);

  }else{

     clear();
     text('Please Wear A Mask', 100, 200);

  }
  
   // draw the video frame to canvas
  console.log(mask_result);
  
}

function modelReady() {
  console.log('Model Ready');
  classifyVideo();
}

// Get a prediction for the current video frame
function classifyVideo() {
  classifier.classify(gotResult);
}

// When we get a result
function gotResult(err, results) {
  // The results are in an array ordered by confidence.
  mask_result = results[0].label.search("mask");

  resultsP.html(results[0].label + ' ' + nf(results[0].confidence, 0, 2));
  classifyVideo();
}