Skip to content

Tejas-ux257/face-detection-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Face Detection Project 🎯

A Python-based face detection application using OpenCV that can detect faces in images and provide real-time face detection through webcam. Features ✨

Image Face Detection: Upload any image and detect faces with bounding boxes Real-time Detection: Use your webcam for live face detection Eye Detection: Also detects eyes within detected faces Screenshot Capture: Save screenshots during real-time detection Multiple Output Formats: Save processed images with timestamps

Requirements πŸ“‹

Python 3.7 or higher OpenCV (cv2) NumPy A working webcam (for real-time detection)

Installation πŸš€

Clone the repository bashgit clone https://github.com/yourusername/face-detection-project.git cd face-detection-project

Create a virtual environment (recommended) bashpython -m venv face_detection_env

On Windows

face_detection_env\Scripts\activate

On macOS/Linux

source face_detection_env/bin/activate

Install required packages bashpip install -r requirements.txt

Usage πŸ’»

Run the application bashpython main.py

Choose from the menu

Option 1: Detect faces in an image file

Enter the path to your image View the result with detected faces highlighted

Option 2: Real-time face detection

Your webcam will start Press 'q' to quit Press 's' to save a screenshot

Project Structure πŸ“ face-detection-project/ β”‚ β”œβ”€β”€ main.py # Main application file β”œβ”€β”€ requirements.txt # Python dependencies β”œβ”€β”€ README.md # Project documentation β”œβ”€β”€ output/ # Processed images (created automatically) β”œβ”€β”€ screenshots/ # Webcam screenshots (created automatically) └── sample_images/ # Sample images for testing (optional) How It Works πŸ” The project uses OpenCV's Haar Cascade classifiers for face detection:

Haar Cascades: Pre-trained classifiers that detect objects (faces/eyes) Image Processing: Converts images to grayscale for better detection Detection Algorithm: Scans the image at multiple scales Bounding Boxes: Draws rectangles around detected faces Real-time Processing: Processes video frames continuously

Key Functions πŸ› οΈ

detect_faces_in_image(): Process static images detect_faces_webcam(): Real-time webcam detection Automatic creation of output directories Timestamp-based file naming Error handling for various scenarios

Sample Output πŸ“Έ The application will:

Draw blue rectangles around detected faces Draw green rectangles around detected eyes Display the number of faces found Save processed images with timestamps

Troubleshooting πŸ”§ Webcam not working?

Ensure your camera is not being used by another application Check camera permissions in your system settings

No faces detected?

Ensure good lighting conditions Make sure faces are clearly visible and front-facing Try with different images

Installation issues?

Make sure you have Python 3.7+ Try upgrading pip: pip install --upgrade pip On some systems, you might need: pip install opencv-python-headless

Contributing 🀝

Fork the repository Create a feature branch (git checkout -b feature/amazing-feature) Commit your changes (git commit -m 'Add amazing feature') Push to the branch (git push origin feature/amazing-feature) Open a Pull Request

Future Enhancements πŸš€

Face recognition (identify specific people) Multiple face detection algorithms GUI interface using tkinter Batch processing for multiple images Face mask detection Age and gender prediction

License πŸ“„ This project is open source and available under the MIT License. Author πŸ‘¨β€πŸ’» Created by Tejas kumar d Acknowledgments πŸ™

OpenCV community for the amazing computer vision library Haar Cascade classifiers for face detection Python community for excellent documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages