Skip to content

Kevin-Mok/face-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Tracker

Real-time facial and eye detection system with gaze-based mouse control, built with OpenCV and C++.

OpenCV C++ Linux

Overview

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.

Features

  • 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

Tech Stack

Component Technology
Language C++ (C++11 standard)
Computer Vision OpenCV 4
Build System Make
System Integration xdotool (Linux mouse control)

Project Structure

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

Installation

Prerequisites

  • Linux with X11 (for xdotool mouse control)
  • OpenCV 4 development libraries
  • g++ compiler
  • Webcam

Setup

# 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

How It Works

Face Detection Pipeline

  1. Capture frame from webcam at 30 FPS
  2. Convert to grayscale and apply histogram equalization
  3. Run Haar Cascade detectMultiScale (scale 1.1, min 150x150)
  4. Draw bounding rectangle and output center coordinates

Eye Tracking Algorithm

  1. Detect face region to constrain eye search
  2. Find eyes using Haar Cascade within face ROI
  3. Apply Hough Circle Transform to locate eyeballs
  4. Select darkest circle (pupil detection via pixel intensity)
  5. Apply stabilization averaging over 5-frame window
  6. Calculate position differential and scale to cursor movement
  7. Execute xdotool mousemove for cursor control

Why This Project is Interesting

Technical Highlights

  1. Computer Vision Pipeline

    • Multi-stage detection: face → eyes → pupils
    • Real-time processing at 30 FPS
    • Histogram equalization for lighting robustness
  2. Algorithm Design

    • Hough Circle Transform for circular feature detection
    • Intensity-based pupil selection (darkest circle wins)
    • Sliding window stabilization for noise reduction
  3. System Integration

    • Direct X11 mouse control via xdotool subprocess
    • Shell command execution from C++ application
    • Coordinate scaling and boundary checking
  4. Accessibility Application

    • Hands-free computer interaction
    • Assistive technology potential
    • Alternative input method development

Skills Demonstrated

  • 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

Usage Examples

# Basic face detection (outputs coordinates to stdout)
./face_detector

# Eye tracking with mouse control
./eye_detector
# Press 'q' or Ctrl+C to exit

Configuration

Key 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)

Author

Kevin Mok

About

Track user's face.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors