Python - Detecting Faces in Images
About
This coding example is part of a Udemy Python course using Python to detect faces in images.
Technologies
Languages
- Python3
- Used to create the main application functionality
Libraries / Packages / Modules
- OpenCV
- open-source library that includes several hundreds of computer vision algorithms.
- OpenCV haar-cascade
- OpenCV xml data containing trained classifiers for detecting objects of a particular type e.g. faces, people, vehicles etc.
Tools
- VS Code
- Code Editor
Deployment
The website was developed using VS Code & Git pushed to GitHub, which hosts the repository. I made the following steps to deploy the site:
Cloning python-image-face-detection
Prerequisites
Ensure the following are installed locally on your computer:
- Python 3.6 or higher
- PIP3 Python package installer
- Git Version Control
- PostgreSQL database with pgAdmin management tool
Cloning the GitHub repository
- navigate to simonjvardy/python-image-face-detection GitHub repository.
- Click the Code button
- Copy the clone url in the dropdown menu
- Using your favourite IDE open up your preferred terminal.
- Navigate to your desired file location.
Copy the following code and input it into your terminal to clone Sportswear-Online:
Creation of a Python Virtual Environment
Note: The process may be different depending upon your own OS - please follow this Python help guide to understand how to create a virtual environment.
Run the application locally
- To run the face detection application, enter the following command into the terminal window:
- the output image file contains the image with a green rectangle surrounding the detected face.
- To run the face detection application for multiple faces, enter the following command into the terminal window:
- the output image file contains the image with a green rectangle surrounding the detected faces. In the example image below, OpenCv was unable to detect the face on the right chewing the newspaper page as it is partially obscured.
Acknowledgements
- Udemy: The Python Mega Course - Build 10 Real World Applications Credit: Ardit Sulce
- OpenCV haarcascades