A real-time face edge detection, face shape classification, and emotion recognition system using MediaPipe and OpenCV. Features ultra-precise edge tracking with 21 landmark points, accurate face shape detection across 7 categories, and real-time emotion analysis using facial action units.
- Real-time Face Edge Detection: Ultra-thin, precise blue outline tracking your face contour
- 21 Landmark Points: Strategically placed points across forehead, temples, cheeks, jawline, and chin
- Face Shape Classification: Detects 7 face shapes with high accuracy:
- Oval, Round, Square, Heart, Diamond, Oblong, Triangle
- Emotion Recognition : Real-time emotion detection using facial geometry:
- Happy, Sad, Angry, Surprised, Neutral, Disgusted, Fearful
- Temporal Smoothing: Advanced stabilization for zero jitter
- Image Adjustments:
- Brightness control
- Saturation adjustment
- Black & White toggle
- Professional UI: Clean interface with real-time statistics and emotion feedback
The system provides:
- Dark Blue Lines: Face edge outline (1px precision)
- Light Blue Dots: 21 stable landmark points on face perimeter
- Face Shape Display: Locked shape after 50-sample analysis
- Emotion Display: Color-coded real-time emotion with confidence scores
- Emotion Statistics: Session summary showing emotion distribution
opencv-python>=4.5.0
mediapipe>=0.10.0
numpy>=1.21.0- Clone the repository:
git clone https://github.com/chetx27/cvproject-facefilter.git
cd cvproject-facefilter- Install dependencies:
pip install -r requirements.txt- Run the application:
Original version (Face shape + edge detection only):
python face_filter.pyEnhanced version with emotion recognition:
python face_emotion_analysis.py| Key | Function |
|---|---|
Q / ESC |
Quit application |
+ / = |
Increase brightness |
- |
Decrease brightness |
W |
Increase saturation |
S |
Decrease saturation |
SPACE |
Toggle Black & White mode |
R |
Reset face shape detection |
E |
Toggle emotion display (emotion version only) |
- Uses MediaPipe's FaceMesh with 95% detection confidence
- Tracks 36 facial landmarks forming the face oval
- Applies weighted temporal smoothing (8-frame buffer)
- Selects 21 strategic points for visualization
The algorithm measures:
- Face Length to Width Ratio: Overall face proportions
- Jaw to Cheek Ratio: Jaw tapering analysis
- Forehead to Cheek Ratio: Upper face width
- Temple Width: Midface narrowing detection
Classification Logic:
- Collects 50 samples over ~2-3 seconds
- Requires 60% consistency (30/50) to lock result
- Uses majority voting for final classification
- Once locked, the result remains stable
The emotion detection system uses Facial Action Units (AU) analysis:
Key Metrics Calculated:
- Eye Aspect Ratio (EAR): Detects eye openness for surprise/fear
- Mouth Aspect Ratio (MAR): Measures mouth opening for surprise/happiness
- Eyebrow Height: Tracks eyebrow position for anger/surprise
- Mouth Curvature: Analyzes smile/frown for happiness/sadness
Emotion Detection Rules:
- Happy: Mouth curves upward + increased MAR (smile detection)
- Sad: Mouth curves downward + slightly closed eyes
- Angry: Lowered eyebrows + tight mouth
- Surprised: Raised eyebrows + wide eyes + open mouth
- Fearful: Raised eyebrows + wide eyes + partially open mouth
- Disgusted: Lowered eyebrows + raised upper lip
- Neutral: All features in normal/baseline ranges
Temporal Smoothing:
- 15-frame buffer for emotion stability
- Majority voting prevents rapid flickering
- Confidence scores based on consistency
- 300-frame history tracking (10 seconds at 30 FPS)
| Shape | Characteristics |
|---|---|
| Oval | Balanced proportions, slightly longer than wide |
| Round | Short face, equal width throughout |
| Square | Angular jaw, balanced width, short face |
| Heart | Wide forehead, narrow pointed chin |
| Diamond | Wide cheeks, narrow forehead & jaw |
| Oblong | Long face, similar width throughout |
| Triangle | Narrow forehead, wide jaw |
| Emotion | Display Color | Indicators |
|---|---|---|
| Happy | Green | Smile, squinted eyes |
| Sad | Blue | Frown, droopy features |
| Angry | Red | Furrowed brows, tight mouth |
| Surprised | Cyan | Wide eyes, raised brows, open mouth |
| Neutral | Gray | Relaxed features |
| Disgusted | Olive | Wrinkled nose, raised upper lip |
| Fearful | Purple | Wide eyes, tense features |
- Resolution: 1920x1080 (Full HD)
- Frame Rate: Real-time (30+ FPS on modern hardware)
- Detection Confidence: 95%
- Tracking Confidence: 95%
- Face Edge Smoothing: 8-frame buffer
- Emotion Smoothing: 15-frame buffer
- Shape Analysis: 50-sample consensus
- Emotion History: 300 frames (10 seconds)
cvproject-facefilter/
│
├── face_filter.py # Original face edge + shape detection
├── face_emotion_analysis.py # Enhanced version with emotion recognition
├── webcam_test.py # Webcam testing utility
├── requirements.txt # Python dependencies
├── README.md # This file
├── LICENSE # MIT License
└── .gitignore # Git ignore file
Face Shape Detection:
Face Shape Detected: Oval
Confidence: 42/50 samples
All detections: {'Oval': 42, 'Round': 5, 'Square': 3}
Emotion Statistics (on exit):
=== Emotion Statistics ===
Happy: 45.2%
Neutral: 32.8%
Surprised: 12.4%
Sad: 6.3%
Angry: 2.1%
Fearful: 1.2%
Disgusted: 0.0%
This project demonstrates:
- Computer Vision: Real-time facial landmark detection and tracking
- Feature Engineering: Anthropometric measurements and facial action units
- Signal Processing: Temporal smoothing and noise reduction
- Pattern Recognition: Multi-class classification with confidence scoring
- Human-Computer Interaction: Real-time visual feedback systems
Potential Research Extensions:
- Emotion dataset collection and annotation
- ML model training for improved accuracy
- Cross-cultural emotion expression analysis
- Accessibility applications for emotion awareness
- Mental health monitoring systems
##Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- MediaPipe by Google for facial landmark detection
- OpenCV for computer vision operations
- Face shape classification research and anthropometric standards
- Facial Action Coding System (FACS) for emotion recognition principles
chetx27 - GitHub: @chetx27
Project Link: https://github.com/chetx27/cvproject-facefilter
- Requires good lighting for optimal detection
- May need adjustment for extreme camera angles
- First detection takes 2-3 seconds for accuracy
- Emotion detection accuracy varies with lighting and facial expressions intensity
Note: This application requires a webcam and runs in real-time. Make sure your camera is connected and permissions are granted.