A C++ program to detect whether an image contains faces wearing a mask using OpenCV
- Image pre-processing:
- Grayscale color conversion
- Histogram equalization
- Gaussian filtering
- Face detection:
- Haar: haarcascade_frontalface_default.xml
- LBP: lbpcascade_frontalface_improved.xml
- Eye detection:
- haarcascade_lefteye_2splits.xml
- haarcascade_righteye_2splits.xml
- haarcascade_eye_tree_eyeglasses.xml
- Skin area segmentation:
- YCrCb color conversion
- Otsu thresholding using Cr component
- Oronasal region selection using eye bounding boxes
- Comparison of skin areas
We tested our program on the selected subset of the entire dataset and manually noted whether the program was able to accurately detect the correct faces and eyes before the actual mask detection algorithm. Based on the individual image results, we calculated the summary results shown in the below table:
Images | Face Detection | Additional Incorrect Face Detection | Eye Detection | Additional Incorrect Eye Detection | Mask Detection | Non-Mask Detection |
---|---|---|---|---|---|---|
Masked Faces | 98.8% | 0% | 97.7% | 2.3% | 96.3% | 3.7% |
Non-Masked Faces | 98.9% | 5.8% | 88.5% | 6.9% | 11% | 89% |
Combined | 98.85% | 2.9% | 90.1% | 4.6% | N/A | N/A |
Based on the combined dataset, we also calculated the below metrics:
Metric | Value |
---|---|
Accuracy | 92.7% |
Precision | 82.8% |
Recall | 96.3% |
F1-Score | 92.9% |
- If the face and eye detection classifiers fail, our program will not be able to check for masks
- Results displayed and written are based on the classifier and detection variables which may not be accurate (E.g., the program might detect 2 faces as expected but the detections might not actually be faces)
- Incorporate smile detection classifiers to distinguish masks from beards
- Improve face and eye detection performance by testing additional pre-processing methods or different classifiers
- Clone the repository
- For testing with new images (".jpg"s only):
- update the DIRECTORY_PATH variable in the main.cpp file to point to the directory containing the test images
- rename images to [with/without]_mask_[image id]_count_[number of faces].jpg to get summary results
- Ensure that C++ 17 is available in the system as the program utilizes the "filesystem" library which is only supported in C++ 17
- Update the OpenCV library path under OpenCV_DIR in the CMakeLists.txt file on line 29
- Build and run the main.cpp program to execute the mask detection algorithm
- Summary results are displayed in the terminal and individual image results are written to a csv file