Skip to content

Commit

Permalink
Add/face detection model (#151)
Browse files Browse the repository at this point in the history
* face detection model added

* title corrected

* title updated/comments removed/links updated
  • Loading branch information
that-ar-guy authored Jan 18, 2025
1 parent a37dd87 commit 7a8fad2
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
168 changes: 168 additions & 0 deletions docs/projects/computer-vision/face-detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Face Detection


### AIM
The goal of this project is to build a face detection system using OpenCV, which identifies faces in static images using Haar Cascades.


### DATASET LINK
For this project we are going to use the pretrained Haar Cascade XML file for face detection from OpenCV's Github repository.

[https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml](https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml)


### NOTEBOOK LINK
[https://colab.research.google.com/drive/1upcl9sa5cL5fUuVLBG5IVuU0xPYs3Nwf#scrollTo=94ggAdg5AnUk](https://colab.research.google.com/drive/1upcl9sa5cL5fUuVLBG5IVuU0xPYs3Nwf#scrollTo=94ggAdg5AnUk)


### LIBRARIES NEEDED

??? quote "LIBRARIES USED"

- OpenCV
- Random
- Matplotlib

---

### DESCRIPTION
This project involves building a face detection model using OpenCV's pre-trained Haar Cascade Classifiers to detect faces in images.

!!! info "What is the requirement of the project?"
- A face detection system is needed for various applications such as security, attendance tracking, and facial recognition systems.
- This project demonstrates a basic use of computer vision techniques for detecting faces in static images.


??? info "Why is it necessary?"
- Face detection is the first crucial step in many computer vision applications such as face recognition and emotion analysis.
- It is an essential component in systems that require human identification or verification.

??? info "How is it beneficial and used?"
- Face detection can be used in automation systems, for example, in attendance tracking, photo tagging, and security surveillance.
- It enables various applications in user experience enhancement and biometric systems.

??? info "How did you start approaching this project? (Initial thoughts and planning)"
- I began by exploring OpenCV documentation, focusing on how to implement Haar Cascade for face detection.
- Initially, I focused on static image detection, planning to extend the project to video-based detection in the future.

??? info "Mention any additional resources used (blogs, books, chapters, articles, research papers, etc.)."
- OpenCV documentation
- Book: "Learning OpenCV 3" by Adrian Kaehler and Gary Bradski

---

### EXPLANATION

#### DETAILS OF THE DIFFERENT FEATURES

- Haar Cascade Classifier: A machine learning-based approach for detecting objects in images or video. It works by training on a large set of positive and negative images of faces.
- Cascade Classifier*: The classifier works through a series of stages, each aimed at increasing detection accuracy.
- Face Detection: The primary feature of this project is detecting human faces in static images, which is the first step in many facial recognition systems.



---

#### PROJECT WORKFLOW

=== "Step 1"

Initial data exploration and understanding:
- Research the Haar Cascade method for face detection in OpenCV.
- Collect sample images for testing the model's performance.


=== "Step 2"

Data cleaning and preprocessing:
- Ensure all input images are properly formatted (e.g., grayscale images for face detection).
- Resize or crop images to ensure optimal processing speed.


=== "Step 3"

Feature engineering and selection:
- Use pre-trained Haar Cascade classifiers for detecting faces.
- Select the appropriate classifier based on face orientation and conditions (e.g., frontal face, profile).


=== "Step 4"

Model training and evaluation:
- Use OpenCV's pre-trained Haar Cascade models.
- Test the detection accuracy on various sample images.


=== "Step 5"

Model optimization and fine-tuning:
- Adjust parameters such as scale factor and minNeighbors to enhance accuracy.
- Experiment with different input image sizes to balance speed and accuracy.


=== "Step 6"

Validation and testing:
- Validate the model's effectiveness on different test images, ensuring robust detection.
- Evaluate the face detection accuracy based on diverse lighting and image conditions.


---

#### PROJECT TRADE-OFFS AND SOLUTIONS

=== "Trade Off 1"
- Accuracy vs. computational efficiency.
- Solution: Fine-tuned classifier parameters to ensure a balance between accuracy and speed.

=== "Trade Off 2"
- Detection performance vs. image resolution.
- Solution: Optimized input image resolution and processing flow to ensure both fast processing and accurate detection.

---

### SCREENSHOTS

!!! success "Project workflow"

``` mermaid
graph LR
A[Start] --> B{Face Detected?}
B -->|Yes| C[Mark Face]
C --> D[Display Result]
B -->|No| F[Idle/Do Nothing]
```

---

### CONCLUSION

#### KEY LEARNINGS

!!! tip "Insights gained from the data"
- Gained an understanding of face detection using Haar Cascades.
- Improved ability to optimize computer vision models for accuracy and speed.

??? tip "Improvements in understanding machine learning concepts"
- Learned how to handle trade-offs between accuracy and speed in real-time applications.
- Gained hands-on experience with the implementation of object detection algorithms.

??? tip "Challenges faced and how they were overcome"
- Challenge: Low detection accuracy in poor lighting conditions.
- Solution: Adjusted classifier parameters and added preprocessing steps to improve accuracy.

---

#### USE CASES

=== "Application 1"

**Security Surveillance Systems**

- Used for identifying individuals or monitoring for intruders in secure areas.

=== "Application 2"

**Attendance Systems**

- Used to automate attendance tracking by detecting the faces of students or employees.
13 changes: 13 additions & 0 deletions docs/projects/computer-vision/index.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Computer Vision 🎥

<div style="display: flex; flex-direction: column; gap: 10px;">

<!-- OpenCV Face Detection -->
<a href="face-detection" style="padding: 0 2px 0 16px; background-color: rgba(39, 39, 43, 0.4); border: 1px solid rgba(76, 76, 82, 0.4); border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); overflow: hidden; transition: transform 0.2s; display: flex; align-items: center;">
<img src="https://imerit.net/wp-content/uploads/2021/07/Face-Detection-in-Images-with-Bounding-Boxes.jpg" alt="OpenCV Logo" style="width: 300px; height: 150px; object-fit: cover; border-radius: 10px;" />
<div style="padding: 15px;">
<h2 style="margin: 0; font-size: 20px;">Face Detection Model</h2>
<p style="font-size: 16px;">Detecting faces in images using OpenCV's powerful Haar cascades.</p>
<p style="font-size: 12px;">📅 2025-01-16 | ⏱️ 10 mins</p>
</div>
</a>

</div>

0 comments on commit 7a8fad2

Please sign in to comment.