Real-time facial and eye detection system with gaze-based mouse control, built with OpenCV and C++.
A computer vision application that detects faces and eyes from webcam input, then uses eye-gaze tracking to control the system mouse cursor. Designed for hands-free computer interaction and accessibility applications.
- Real-Time Face Detection - Haar Cascade classifier with multi-scale detection
- Eye Tracking - Detects eyes within face region and localizes pupils
- Gaze-Based Mouse Control - Moves cursor based on eye position using xdotool
- Movement Stabilization - Sliding window averaging for smooth cursor movement
- Visual Feedback - Bounding boxes and tracking circles overlay on video feed
| Component | Technology |
|---|---|
| Language | C++ (C++11 standard) |
| Computer Vision | OpenCV 4 |
| Build System | Make |
| System Integration | xdotool (Linux mouse control) |
face-tracker/
├── face_detector.cpp # Simple face detection with coordinate output
├── eye_detector.cpp # Full eye tracking + mouse control (172 lines)
├── face-cascade.xml # Haar Cascade classifier for faces (661KB)
├── Makefile # Build configuration
└── .gitignore # Compiled binaries ignored
- Linux with X11 (for xdotool mouse control)
- OpenCV 4 development libraries
- g++ compiler
- Webcam
# Install dependencies (Ubuntu/Debian)
sudo apt-get install build-essential libopencv-dev xdotool
# Clone and build
git clone [email protected]:Kevin-Mok/face-tracker.git
cd face-tracker
make
# Run face detector
./face_detector
# Run eye tracker with mouse control
./eye_detector- Capture frame from webcam at 30 FPS
- Convert to grayscale and apply histogram equalization
- Run Haar Cascade
detectMultiScale(scale 1.1, min 150x150) - Draw bounding rectangle and output center coordinates
- Detect face region to constrain eye search
- Find eyes using Haar Cascade within face ROI
- Apply Hough Circle Transform to locate eyeballs
- Select darkest circle (pupil detection via pixel intensity)
- Apply stabilization averaging over 5-frame window
- Calculate position differential and scale to cursor movement
- Execute
xdotool mousemovefor cursor control
-
Computer Vision Pipeline
- Multi-stage detection: face → eyes → pupils
- Real-time processing at 30 FPS
- Histogram equalization for lighting robustness
-
Algorithm Design
- Hough Circle Transform for circular feature detection
- Intensity-based pupil selection (darkest circle wins)
- Sliding window stabilization for noise reduction
-
System Integration
- Direct X11 mouse control via xdotool subprocess
- Shell command execution from C++ application
- Coordinate scaling and boundary checking
-
Accessibility Application
- Hands-free computer interaction
- Assistive technology potential
- Alternative input method development
- Computer Vision: OpenCV, Haar Cascades, Hough Transform
- C++ Development: Real-time video processing, STL vectors
- Algorithm Implementation: Multi-stage detection, signal smoothing
- Linux System Programming: Process execution, X11 integration
# Basic face detection (outputs coordinates to stdout)
./face_detector
# Eye tracking with mouse control
./eye_detector
# Press 'q' or Ctrl+C to exitKey parameters in eye_detector.cpp:
- Stabilization window: 5 frames (adjustable in
stabilize()) - Mouse sensitivity: 100x horizontal, 80x vertical scaling
- Minimum face size: 150x150 pixels
- Frame rate: 30 FPS (33ms wait)