A computer vision project that detects whether a person is wearing a face mask or not using machine learning and image processing techniques.
- Detects face with mask and face without mask
- Uses computer vision & deep learning
- Real-time detection (if webcam enabled)
- Easy to train and test
- Python
- OpenCV
- TensorFlow / Keras
- NumPy
- Matplotlib
Face_Mask_Detection/
│
├── dataset/
│ ├── with_mask/
│ └── without_mask/
├── model/
├── train_model.py
├── detect_mask.py
├── requirements.txt
└── README.md1️⃣ Clone the Repository
git clone https://github.com/sofialtamsh/Face_Mask_Detection.git2️⃣ Create a Virtual Environment (Recommended)
python -m venv venv3️⃣ Activate the Virtual Environment
Windows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activate4️⃣ Install Dependencies
pip install -r requirements.txt🔹 1. Train the Model
python train_model.py- Loads images from the dataset
- Trains the CNN model
- Saves the trained model in model
🔹 2. Run Face Mask Detection
python detect_mask.pyUses webcam or video feed, Detects faces in real-time
Displays:
- Green box → Mask detected
- Red box → No mask detected
- Press ESC to quit
🖼️ Example Output
[INFO] Starting video stream...
[INFO] Mask detected with 98.45% confidenceOn-screen:
- Bounding box around face
- Label: Mask / No Mask
- Confidence percentage
Ensure your dataset is structured as follows:
dataset/
├── with_mask/
│ ├── img1.jpg
│ ├── img2.jpg
│ └── ...
└── without_mask/
├── img1.jpg
├── img2.jpg
└── ...Guidelines:
- Images should be clear and front-facing when possible
- Supported formats: .jpg, .png
- Balanced classes improve model accuracy
- Convolutional Neural Network (CNN)
- Image preprocessing using OpenCV
- Binary classification:
- With Mask
- Without Mask
- Trained using TensorFlow/Keras
- Model saved in the model/ directory after training
TensorFlow
OpenCV-Python
NumPy
Matplotlib
Scikit-learn- Always activate the virtual environment before running scripts
- Ensure proper lighting for better face detection
- You can improve accuracy by adding more training images
Pull requests are welcome!
For major changes, please open an issue first to discuss what you’d like to change.
MIT License © 2025 Sofi Altamsh