Skip to content

Face Detection using Haar Cascades In this project, we used OpenCV's Haar Cascade classifier to detect faces in images. We converted images to grayscale, applied the Haar Cascade, and drew green rectangles around detected faces. We also created a generalized function for face detection and tested it on a new image.

License

Notifications You must be signed in to change notification settings

pronzzz/face-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haar Cascade Face Detection 📸 👀


Overview 🔎

This project demonstrates Haar Cascade face detection in Python using OpenCV. Haar Cascade is a machine learning object detection algorithm used to identify faces in images. It's widely employed in real-time face detection applications like security systems and facial recognition software.

Steps Involved 👣

  1. Importing Necessary Libraries: We begin by importing essential libraries like NumPy, OpenCV, and Matplotlib for image manipulation and visualization.

  2. Loading the Test Image: Next, we load the image we want to detect faces in.

  3. Converting to Grayscale: Since OpenCV's face detector works with grayscale images, we convert the loaded image to grayscale.

  4. Haar Cascade Files: We load the pre-trained Haar Cascade classifier for frontal face detection from OpenCV's data repository.

  5. Face Detection: Using the loaded classifier, we detect faces in the grayscale image and store the coordinates of detected faces.

  6. Drawing Rectangles Around Detected Faces: We draw green rectangles around the detected faces using OpenCV's rectangle function.

  7. Displaying the Result: Finally, we display the original image with the detected faces highlighted by rectangles.

  8. Generalizing with a Function: To make the face detection process more reusable, we create a detect_faces() function that takes an image and a cascade classifier as inputs and returns the image with detected faces highlighted.

  9. Applying the Function to a New Image: We test the detect_faces() function on a different image to demonstrate its versatility.

  10. Saving the Result: We save the final image with detected faces for further use or analysis.

Usage 💻

To use this project:

  1. Clone the repository.
  2. Install the required libraries using pip install -r requirements.txt.
  3. Place the test images in the data folder.
  4. Run python main.py to execute the face detection algorithm.

Conclusion 🏁

This project showcases how to use Haar Cascade for face detection in Python with OpenCV. It provides a solid foundation for exploring more advanced face detection techniques and building fascinating applications like face recognition and real-time surveillance systems.

About

Face Detection using Haar Cascades In this project, we used OpenCV's Haar Cascade classifier to detect faces in images. We converted images to grayscale, applied the Haar Cascade, and drew green rectangles around detected faces. We also created a generalized function for face detection and tested it on a new image.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published