Prateek Pant
Published © LGPL

COVID19 Cracker - Recognize person and facemask

As lock down eases , SOP mandates face masks in public places. This project is to identify folks who are not wearing masks and warn them.

IntermediateShowcase (no instructions)16 hours327
COVID19 Cracker - Recognize person and facemask

Things used in this project

Story

Read more

Schematics

Setup

Logitech webcam is connected to Raspberry PI board and host streams using webrtc protocol.

Covid Mask model

Code

WebRTC video capture to video Element

JavaScript
Capture video from webcamera into video element
 new signal("ws://192.168.0.53:8888/webrtc",
                        function (stream) {
                          
                            videoEl.srcObject = stream;

                        },
                        function (error) {
                            alert(error);
                        },
                        function () {
                            console.log('websocket closed. bye bye!');
                            videoEl.srcObject = null;
                         
                        },
                        function (message) {
                            alert(message);
                        }
        
                  );

Detect Faces

JavaScript
Fetch dataset images and compare with image captured from live stream
function loadLabeledImages() {
  const labels = ['Prateek','Gaurav']
  return Promise.all(
    labels.map(async label => {
      const descriptions = [];
      for (let i = 1; i <= 2; i++) {
        const img = await faceapi.fetchImage(`./labeled_images/${label}/${i}.jpg`)
        console.log("label",label);
        console.log("index",i);
        const detectionsl = await faceapi.detectSingleFace(img).withFaceLandmarks().withFaceDescriptor()
        descriptions.push(detectionsl.descriptor)
      }
    
      return new faceapi.LabeledFaceDescriptors(label, descriptions)


    })
  )
}

Mobilenet Classification

JavaScript
Load and classify mask model using Mobilenet classification
  //label='Model is ready';
  classifier.load('./model.json',customModelReady);
  label='custom model loaded';

 //Classify images and output results
 classifier.classify(gotResults); 

Credits

Prateek Pant

Prateek Pant

2 projects • 3 followers
Video Enthusiast

Comments