Skip to content

Latest commit

 

History

History
107 lines (59 loc) · 2.88 KB

File metadata and controls

107 lines (59 loc) · 2.88 KB

FaceFilter-with-OpenCV


Put on sunglasses for the camera.

sunglasses

You can inspect the face with sunglasses.

This project requires Python and OpenCV.


Requirements (Used in this repository):


How to Work

detect_and_draw Function:

  • Arguments:

    • img: Current frame image read from the webcam

    • cascade: Haar Cascade classifier for face detection

    • nested_cascade: Haar Cascade classifier for eye detection

    • scale: Scale for resizing the image

    • try_flip: Flag for attempting eye direction

    • glasses: Sunglasses image

  • Functionality:

    1. Convert the image read from the webcam to grayscale and resize it.

    2. Use Haar Cascade to detect faces.

    3. Find eyes around the detected face and calculate the center points of the eyes.

    4. Overlay sunglasses on the face using the center points of both eyes.

    5. Return the overlaid image.

overlay_image Function:

  • Arguments:

    • background: Background image

    • foreground: Image to overlay

    • location: Location to overlay the image

  • Functionality:

    1. Overlay sunglasses on the background image.

    2. The transparent part of the sunglasses does not affect the background image.

    3. Return the overlaid image.

Process Description:

  1. Load Haar Cascades:

    Load Haar Cascade classifiers from the files

  2. Load Sunglasses Image:

    Load the sunglasses image from the 'sunglasses.png' file.

  3. Start Webcam Capture:

    Open the webcam using OpenCV and begin reading frames.

  4. Frame Processing:

    Converts the frame to grayscale and resizes it.

    Utilizes the Haar Cascade classifier to detect faces in the frame.

    Locates eyes around the detected face and calculates their center points.

    Overlays sunglasses on the face using the center points of the eyes.

  5. Handle Keyboard Input

    If the 'q' key is pressed, the program exits.


Command:

python finalcode.py


Result:

Result