This project detects whether a person is smiling or not using MediaPipe and OpenCV.
It works by tracking facial landmarks around the lips and analyzing their positions in real time.
- The webcam captures video frames using OpenCV.
- MediaPipe’s face landmark model detects 468 facial landmarks.
- The program uses four key landmarks:
- 61: left lip corner
- 291: right lip corner
- 13: upper lip center
- 14: lower lip center
- It calculates:
- Mouth width: distance between the left and right lip corners
- Mouth height: distance between the upper and lower lips
- The ratio of width to height determines if the person is smiling.
If the ratio is above a threshold (around 1.8), the system labels the person as smiling. Otherwise, it labels them as neutral.
- Python 3.8 or higher
- OpenCV
- MediaPipe
- NumPy
Install dependencies with:
pip install opencv-python mediapipe numpy- Download the MediaPipe model file
face_landmarker.taskfrom the MediaPipe documentation. - Place it in the same directory as the Python scripts.
- Run the main script:
python smile_detection.py- Press
qto quit the program.
smile-detection/
├── smile_detection.py # Main smile detection script
├── detector.py # Initializes and draws landmarks
├── face_landmarker.task # MediaPipe model file
└── README.md # Project documentation
You can adjust the smile detection threshold in smile_detection.py:
if smile_ratio > 1.8:Lower values make it easier to detect a smile. Higher values make detection stricter.