This project uses OpenCV's Haar Cascade for face detection and performs hyperparameter tuning to improve detection accuracy.
The face detection model used here is a pre-trained Haar Cascade classifier, which operates by scanning the input image in a sliding window approach.
To improve detection accuracy, the project employs hyperparameter tuning on parameters such as scaleFactor
, minNeighbors
, and minSize
.
scaleFactor
: Image scaling factor.minNeighbors
: Minimum number of neighbors for a rectangle to retain it.minSize
: Minimum size of the bounding box for detection.
The evaluation of the model's performance is based on:
- True Positives (TP): Correctly detected faces in images with faces.
- False Positives (FP): Non-face images incorrectly classified as containing faces.
- True Negatives (TN): Correctly identified non-face images.
- False Negatives (FN): Faces missed in images containing faces.
The accuracy is calculated as:
The tuning function iterates through different combinations of parameters to find the best configuration for maximizing accuracy.
This project uses two datasets:
- Face Dataset: This dataset consists only of faces of humans.
- Non-Face Dataset: This dataset consists of images of flowers, airplanes, motorcycles, nature, dogs, and cats, which are not considered faces of humans..
- Clone the repository:
git clone https://github.com/sahasri/Object-Detection-with-Haar-Cascade.git cd Object-Detection-with-Haar-Cascade
- Install the required dependencies:
pip install -r requirements.txt
- Download dataset: The required datasets are included in the repository as zip files.
- faces-dataset.zip: This zip file contains 200 images of faces of human.
- non-faces_dataset.zip: This zip file contains 200 images of non-faces, such as flowers, airplanes, motorcycles, nature, dogs, and cats.
- And also datasets are available in kaggle.
kaggle datasets download -d sahasrimanimendra/non-faces-dataset kaggle datasets download -d sahasrimanimendra/faces-dataset
Object-Detection-with-Haar-Cascade/
├── faces_dataset/
│ ├── 001.jpg
│ ├── 002.jpg
│ └── ...
├── non_faces_dataset/
│ ├── 001.jpg
│ ├── 002.jpg
│ └── ...
├── Object-Detection-with-Haar-Cascade.ipynb
├── requirements.txt
└── README.md