Made by Ram Bapat
A simple yet effective Python desktop application that identifies human faces in uploaded images. Built with Tkinter for the GUI and OpenCV for powerful face detection.
Caption: Initial view of the application.
Caption: Application after a face has been detected in an uploaded image.
Caption: Application response when no face is detected.
This project is a desktop GUI application built using Python. It allows users to:
- Upload an image file (e.g., JPG, PNG) from their local system.
- View the uploaded image within the application window.
- See processing logs that detail the steps taken by the application.
- Receive a clear textual result: "Yes, human face(s) detected!" or "No human face detected."
- If a face is detected, a green rectangle is drawn around it in the displayed image.
The core face detection is powered by OpenCV, utilizing a pre-trained Haar Cascade classifier. The graphical user interface is built with Python's standard Tkinter library, making it accessible and relatively lightweight. This project serves as a great learning tool for beginners interested in basic computer vision and GUI development with Python.
- User-Friendly GUI: Simple and intuitive interface built with Tkinter.
- Image Upload: Supports common image formats (JPG, JPEG, PNG, BMP, GIF).
- Face Detection: Utilizes OpenCV's Haar Cascade classifiers for identifying frontal human faces.
- Visual Feedback:
- Displays the uploaded image.
- Draws rectangles around detected faces on the displayed image.
- Clear textual result for detection status (with color coding).
- Processing Logs: A scrolled text area shows real-time logs of the application's actions (e.g., image loading, grayscale conversion, detection results).
- Cross-Platform: Being a Python script, it can run on Windows, macOS, and Linux with Python installed.
- Self-Contained: Relies on standard Python libraries and well-known computer vision packages.
- Language: Python 3
- GUI Framework: Tkinter (Python's standard GUI package),
tkinter.ttk
for themed widgets. - Computer Vision: OpenCV-Python (
cv2
) - Image Handling (for GUI): Pillow (
PIL
Fork) - Classifier: Haar Cascade (
haarcascade_frontalface_default.xml
provided by OpenCV) - Development Environment: Virtual Environment (
venv
)
To get a local copy up and running, follow these simple steps.
- Python 3: Ensure Python 3.x is installed on your system. You can download it from python.org.
- pip: Python's package installer (usually comes with Python).
-
Clone the repository (or download the files):
git clone https://github.com/Barrsum/Python-Human-Face-Identifier.git cd Python-Human-Face-Identifier
If you downloaded the files as a ZIP, extract them and navigate into the project folder.
-
Create and Activate a Virtual Environment: (Recommended to keep dependencies isolated)
# For Windows python -m venv .venv .\.venv\Scripts\activate # For macOS/Linux python3 -m venv .venv source .venv/bin/activate
-
Download the Haar Cascade XML file:
- Ensure
haarcascade_frontalface_default.xml
is present in the root project directory. You can download it from OpenCV's GitHub repository.
- Ensure
-
Install Dependencies:
- First, create a
requirements.txt
file if you haven't already. While the virtual environment is active, run:pip freeze > requirements.txt
- Then, install the packages:
(This should install
pip install -r requirements.txt
opencv-python
andPillow
.)
- First, create a
- Ensure your virtual environment is active.
- Run the application script:
The application window should open.
python face_detector_app.py
The application uses a pre-trained Haar Cascade classifier from OpenCV. These classifiers are trained on many positive (images with faces) and negative (images without faces) samples.
- When an image is uploaded, it's first converted to grayscale, as Haar cascades typically work better on single-channel images.
- The
detectMultiScale
function from OpenCV is then used. This function scans the image at multiple scales (sizes) with a sliding window. - At each window position and scale, features (Haar-like features) are extracted and compared against the trained model.
- If the features sufficiently match those of a face, the region is marked as a potential face. Parameters like
scaleFactor
andminNeighbors
help fine-tune the detection process to reduce false positives.
Contributions, issues, and feature requests are welcome! Feel free to fork this repository and submit pull requests.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
- OpenCV Team: For providing the powerful computer vision library and pre-trained classifiers.
- Tkinter & Pillow Developers: For the GUI and image manipulation capabilities in Python.
- Python Software Foundation: For the Python language.
Made with ❤️ by Ram Bapat
- Connect with me on LinkedIn: www.linkedin.com/in/ram-bapat-barrsum-diamos