This project demonstrates how to detect facial landmarks in real-time using OpenCV. It uses a pre-trained Haarcascade classifier for face detection and a pre-trained LBF (Local Binary Features) model for facial landmark detection. The application captures frames from a webcam, detects faces and their landmarks, and displays them with connected lines and circles.
- Real-time face detection using Haarcascade classifier.
- Real-time facial landmark detection using the LBF model.
- Visualization of facial landmarks with both circles (dots) and lines connecting the points.
- Saves the last captured frame with detected landmarks.
- Python 3.7+
- OpenCV (cv2)
- NumPy
- Internet connection to download the necessary models
-
Clone the Repository:
git clone https://github.com/yourusername/facial-landmark-detection.git cd facial-landmark-detection
-
Install the Required Packages:
You can install the required Python packages using pip:
pip install opencv-python opencv-contrib-python numpy
-
Download the Pre-trained Models:
The script automatically downloads the Haarcascade classifier for face detection and the LBF model for facial landmark detection if they are not already present in the
data
directory.
-
Run the Script:
python facial_landmark_detection.py
-
Functionality:
- The script opens a window showing the live feed from your webcam.
- Detected faces and their landmarks are displayed with circles and lines.
- Press
q
to quit the application and close the window.
-
Saved Output:
- The script saves the last captured frame with detected landmarks as
face-detect.jpg
in the current directory.
- The script saves the last captured frame with detected landmarks as
'''
Facial Landmark Detection in Python with OpenCV
Detection from webcam
'''
# Import Packages
import cv2
import os
import urllib.request as urlreq
import numpy as np