Skip to content

Commit 984fc5c

Browse files
authored
Add files via upload
0 parents  commit 984fc5c

10 files changed

+40570
-0
lines changed

README.md

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
2+
3+
# Face Recognition and Smile Detection Web Application
4+
5+
![License](https://img.shields.io/badge/license-MIT-green)
6+
![Python Version](https://img.shields.io/badge/python-3.7%2B-blue)
7+
![Flask Version](https://img.shields.io/badge/flask-2.0.3-blue)
8+
![OpenCV Version](https://img.shields.io/badge/opencv-4.5.5-orange)
9+
10+
A real-time face recognition and smile detection web application built using Flask, OpenCV, and scikit-learn. This project showcases how machine learning and computer vision techniques can be used to create interactive and engaging applications with a simple and intuitive web interface.
11+
12+
## Table of Contents
13+
14+
- [Overview](#overview)
15+
- [Features](#features)
16+
- [System Architecture](#system-architecture)
17+
- [Demo](#demo)
18+
- [Installation](#installation)
19+
- [Usage](#usage)
20+
- [Technologies Used](#technologies-used)
21+
- [How It Works](#how-it-works)
22+
- [File Structure](#file-structure)
23+
- [Troubleshooting](#troubleshooting)
24+
- [Contributing](#contributing)
25+
- [License](#license)
26+
- [Acknowledgements](#acknowledgements)
27+
28+
## Overview
29+
30+
The Face Recognition and Smile Detection Web Application is a Python-based project that uses machine learning techniques to identify and recognize faces in real time. The system uses a webcam to capture images, detect faces, recognize identities, and detect smiles. It is designed to be easy to set up and extend, making it a great starting point for developers interested in computer vision and machine learning applications.
31+
32+
This application is primarily intended for educational purposes and demonstrates a practical use case of K-Nearest Neighbors (KNN) for face recognition, combined with OpenCV’s Haar cascades for face and smile detection. It can be further enhanced to include more sophisticated recognition techniques or be integrated into larger systems.
33+
34+
## Features
35+
36+
- **Face Data Collection**: Allows users to capture and save facial data directly from their webcam.
37+
- **Real-Time Face Recognition**: Identifies known faces using a trained KNN model.
38+
- **Smile Detection**: Detects smiles in real time and provides feedback on the screen.
39+
- **Web-Based Interface**: A user-friendly interface built with Flask, making it easy to navigate and interact with.
40+
- **Scalable and Modular**: Designed with extensibility in mind, allowing easy integration of additional features such as eye detection, age estimation, or more advanced recognition models.
41+
- **Cross-Platform Compatibility**: Runs on Windows, macOS, and Linux with minimal setup.
42+
43+
## System Architecture
44+
45+
The application follows a modular architecture, ensuring that each component is separated and can be modified independently. The primary components include:
46+
47+
1. **Web Interface**: Built using Flask, it provides the front-end for users to interact with the system.
48+
2. **Face Detection and Recognition**: Uses OpenCV to detect faces and scikit-learn's KNN for recognizing faces.
49+
3. **Smile Detection**: Uses Haar cascades to identify smiles within detected faces.
50+
4. **Data Management**: Facial data and names are stored using Python’s `pickle` module for easy loading and updating.
51+
52+
### Architecture Diagram
53+
54+
```plaintext
55+
+-------------------+ +------------------------+ +------------------+
56+
| Web Interface | <----> | Face Recognition/ | <----> | Smile Detection |
57+
| (Flask, HTML/CSS) | | Data Collection | | (OpenCV Haar) |
58+
+-------------------+ +------------------------+ +------------------+
59+
|
60+
v
61+
+-----------------------+
62+
| Data Management |
63+
| (Pickle Serialization)|
64+
+-----------------------+
65+
```
66+
67+
## Demo
68+
69+
To see the application in action, you can view a demo video [here](https://youtu.be/BB6jkStwweo?si=n5_dSMJsPmq6KP-L) . The demo showcases how the system detects faces, recognizes known individuals, and identifies smiles in real time.
70+
71+
## Installation
72+
73+
### Prerequisites
74+
75+
Ensure that you have the following installed:
76+
77+
- **Python**: Version 3.7 or above
78+
- **pip**: Python package manager
79+
80+
### Step-by-Step Guide
81+
82+
1. **Clone the Repository**
83+
84+
```bash
85+
git clone https://github.com/kilofrakh/face-recognition-app.git
86+
cd face-recognition-app
87+
```
88+
89+
2. **Create a Virtual Environment** (Recommended)
90+
91+
```bash
92+
python -m venv venv
93+
source venv/bin/activate # On Windows use `venv\Scripts\activate`
94+
```
95+
96+
3. **Install Dependencies**
97+
98+
Install the required dependencies listed in the `requirements.txt` file:
99+
100+
```bash
101+
pip install -r requirements.txt
102+
```
103+
104+
4. **Download Haar Cascades**
105+
106+
Download the Haar cascade files for face and smile detection and place them in the `data/` directory. The files needed are:
107+
108+
- `haarcascade_frontalface_default.xml`
109+
- `haarcascade_smile.xml`
110+
111+
You can download these files from the [OpenCV GitHub repository](https://github.com/opencv/opencv/tree/master/data/haarcascades).
112+
113+
5. **Run the Application**
114+
115+
Start the Flask server:
116+
117+
```bash
118+
python app.py
119+
```
120+
121+
Open your browser and navigate to `http://127.0.0.1:5000` to access the application.
122+
123+
## Usage
124+
125+
1. **Home Page**: The main page with navigation options for collecting face data and recognizing faces.
126+
127+
2. **Collect Faces**: Allows you to enter a name and start capturing facial data. The webcam will capture images, and once enough samples are collected, the data is saved for recognition.
128+
129+
3. **Recognize Faces**: Opens the live video feed with face recognition enabled. If a recognized face is detected, the name will be displayed along with feedback about smiling.
130+
131+
## Technologies Used
132+
133+
- **Flask**: Provides the web framework for building the application interface.
134+
- **OpenCV**: Handles image processing tasks such as face and smile detection.
135+
- **scikit-learn**: Used for implementing the KNN algorithm for face recognition.
136+
- **NumPy**: A fundamental package for numerical computations in Python, used here to handle image data.
137+
- **Bootstrap**: Used for styling the web interface, making it responsive and visually appealing.
138+
139+
## How It Works
140+
141+
### Face Detection
142+
143+
The application uses OpenCV’s Haar cascades for face detection. These are pre-trained classifiers that identify facial features based on patterns.
144+
145+
### Face Recognition
146+
147+
The collected facial data is used to train a KNN classifier. The classifier is trained with images labeled by the user’s name, allowing it to recognize known faces when they appear in the video feed.
148+
149+
### Smile Detection
150+
151+
Once a face is detected, another Haar cascade is used to identify smiles within the detected region. If a smile is detected, the application displays a positive message; otherwise, it encourages the user to smile.
152+
153+
## File Structure
154+
155+
```plaintext
156+
face-recognition-app/
157+
158+
├── app.py # Main application script
159+
├── templates/ # HTML templates for Flask
160+
│ ├── index.html # Home page
161+
│ ├── collect_faces.html # Face collection page
162+
│ └── recognize_faces.html# Face recognition page
163+
164+
├── static/ # Static files (CSS, JS)
165+
166+
├── data/ # Directory to store data files
167+
│ ├── haarcascade_frontalface_default.xml
168+
│ ├── haarcascade_smile.xml
169+
│ ├── faces_data.pkl # Stored facial data
170+
│ └── names.pkl # Stored names
171+
172+
└── requirements.txt # Required Python packages
173+
```
174+
175+
## Troubleshooting
176+
177+
- **Webcam Not Detected**: Ensure that your webcam is properly connected and accessible. Restart your system if necessary.
178+
- **Face Not Recognized**: Make sure you have collected sufficient face data. If recognition fails, try retraining with more samples.
179+
- **Dependencies Issues**: Ensure that all dependencies are correctly installed as per the `requirements.txt` file.
180+
181+
## Contributing
182+
183+
We welcome contributions from the community! To contribute:
184+
185+
1. Fork the repository.
186+
2. Create a new branch: `git checkout -b feature-branch`
187+
3. Make your changes and commit them: `git commit -m 'Add some feature'`
188+
4. Push to the branch: `git push origin feature-branch`
189+
5. Create a pull request.
190+
191+
Please ensure that your code follows the project's coding standards and is well-documented.
192+
193+
## License
194+
195+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
196+
197+
## Acknowledgements
198+
199+
- [OpenCV](https://opencv.org/) for providing excellent computer vision tools.
200+
- [Flask](https://flask.palletsprojects.com/) for the lightweight web framework.
201+
- [scikit-learn](https://scikit-learn.org/) for machine learning functionalities.
202+
- Special thanks to the open-source community for their valuable contributions.
203+
204+
---
205+
206+
This `README.md` provides a comprehensive guide to setting up, running, and understanding the Face Recognition and Smile Detection Web Application. Customize it as needed to fit your specific project and share it to help others easily use and contribute to your application!

0 commit comments

Comments
 (0)