Detect whether a person is wearing a mask or not.
The world is facing a global health crisis in the form of the coronavirus. Until widespread vaccination is achieved, one of the most effective prevention strategies is to wear a mask that covers both the nose and mouth. This project addresses that need by proposing a simple yet effective mask detection system. Such a system could be deployed in shops and malls to permit entry only to individuals wearing masks properly.
I designed the model to be as simple and efficient as possible using Haar Cascade classifiers. It uses four classifiers:
- Eye detection
- Eye detection with eyeglasses (to improve accuracy under eyewear)
- Nose detection
- Mouth/Lips detection
The model uses these detections to infer mask usage based on the following logic:
- If eyes, nose, and mouth are all detected → "Mask not detected"
- If eyes and nose are detected but mouth is not → "Mask not worn properly"
- If eyes are detected but nose and mouth are not → "Good, mask worn properly"
- If none are detected → "Failed to detect a face"
Most mask detection models online use Convolutional Neural Networks (CNNs), trained on datasets where masks are often of the same type. However, in real-world scenarios, masks vary in shape, size, design, and color.
The goal isn't to detect the mask itself, but to confirm whether the nose and mouth are covered, while eyes are visible. Haar Cascade classifiers offer several advantages:
- No training time or dataset required
- Faster than CNNs
- Suitable when camera distance is fixed (e.g., marked spot for subjects to stand)
CNNs outperform in varied angles and distances but are not as computationally lightweight. Haar cascades are ideal for fixed, controlled environments—e.g., entrances with uniform backgrounds and lighting.
Current limitations include failure cases when a hand or object blocks the mouth and nose. A potential enhancement could involve comparing skin tone consistency: if the color of the blocked region matches facial skin tone, it's likely not a mask but a hand.
This model uses Haar Cascade classifiers to detect:
- Yes Eyes
- No Nose
- No Mouth
This helps determine if the nose and mouth are covered, implying proper mask usage. Unlike CNN-based approaches that require training, Haar classifiers are fast and computationally light.
The below webcam stream recording shows how the model performs:
