Skip to content

Latest commit

ย 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Eye Tracking System

A real-time eye tracking system based on Python, using webcam for gaze tracking, voice calibration, and real-time heatmap display. Designed for macOS with support for Chinese and English voice commands. image

๐Ÿ“– Documentation

  • English: README_EN.md - Complete English documentation
  • ไธญๆ–‡: README_CN.md - ๅฎŒๆ•ดไธญๆ–‡่ชชๆ˜Žๆ–‡ไปถ

๐Ÿ†• Two Systems Available

This repository contains two eye tracking systems:

1. Gaze Heatmap System (New, Recommended) โญ

  • Location: gaze_heatmap/
  • Features: ETH-XGaze model (default, best accuracy), L2CS-Net support, comprehensive CLI, advanced calibration
  • Best for: Research, accuracy evaluation, detailed analysis
  • Quick Start: See Gaze Heatmap Quick Start

2. Voice-Controlled System (Original)

  • Location: Root directory (gaze_tracker.py)
  • Features: Voice commands, simple interface
  • Best for: Quick demos, simple use cases
  • Quick Start: See Original System Quick Start

๐Ÿš€ Gaze Heatmap System Quick Start

The new Gaze Heatmap System provides advanced gaze tracking with ETH-XGaze as the default model (best accuracy, supports MPS GPU acceleration):

โš ๏ธ Important Usage Notes

Before using the system, please note:

  • ๐Ÿ“ Viewing Distance: Maintain approximately 60cm distance from the screen for optimal accuracy
  • ๐ŸŽฏ Head Position: Keep your head relatively still during calibration and tracking
  • ๐Ÿ’ก Lighting: Ensure adequate and uniform lighting; avoid backlighting or shadows
  • ๐Ÿ‘“ Glasses: Avoid reflective glasses that may interfere with tracking
  • ๐Ÿช‘ Posture: Maintain a stable sitting posture throughout the session
  • ๐Ÿ”„ Recalibration: Recalibrate if you change position or lighting conditions significantly

Setup and Usage

cd gaze_heatmap

# Setup conda environment (one-time)
conda create -n gaze_eth python=3.10 -y
conda activate gaze_eth
pip install -r requirements.txt

# 1. Calibrate (required first)
python main.py calibrate --output my_calibration.yaml

# 2. Run live demo
python main.py demo --calibration my_calibration.yaml

# 3. Record session
python main.py record --calibration my_calibration.yaml --duration 60

# 4. Evaluate accuracy
python main.py evaluate --calibration my_calibration.yaml --num-points 20

Available Commands

Command Description
calibrate Run 9/16-point calibration procedure
demo Live demo with real-time heatmap
record Record gaze session with heatmap
evaluate Evaluate tracking accuracy
label Annotate recorded heatmaps

Key Features

  • ๐ŸŽฏ ETH-XGaze Model: State-of-the-art gaze estimation (default, supports MPS GPU acceleration)
  • ๐Ÿ“Š Comprehensive CLI: Full command-line interface for all operations
  • ๐Ÿ”ฌ Accuracy Evaluation: Built-in metrics (angular error, screen error, precision)
  • ๐Ÿ“ˆ Advanced Calibration: Polynomial regression with edge weighting
  • ๐ŸŽจ Real-time Heatmap: Live visualization with smoothing and fixation detection
  • ๐Ÿ’พ Data Export: Save sessions, heatmaps, and evaluation reports

Model Accuracy Comparison

Based on testing results, the supported models rank as follows:

Model Accuracy Performance Notes
ETH-XGaze โญโญโญ Relatively usable Fast (MPS GPU support) Default model, relatively better than alternatives
L2CS-Net โญโญ Limited Moderate Requires manual weight download
MediaPipe โญโญ Limited Fastest Fallback option, no additional setup required

Test Results: ETH-XGaze > L2CS > MediaPipe

Note: All models have limitations in accuracy. ETH-XGaze performs relatively better among the available options and supports Apple Silicon GPU acceleration via MPS, making it the default choice.

Known Limitations:

  • โš ๏ธ Edge/Corner Sensitivity: All models show reduced sensitivity when gazing at screen edges and corners. The tracking accuracy decreases significantly in peripheral areas compared to the center of the screen.
  • This is a common limitation in webcam-based gaze tracking systems and may require additional calibration points at screen edges to improve edge accuracy.

For detailed documentation, see gaze_heatmap/how_to_run.md


๐Ÿš€ Original System Quick Start

# 1. Setup (one-time)
./setup.sh

# 2. Quick start
./quick_start.sh

# 3. High precision mode (best accuracy)
./run_high_precision.sh

๐ŸŽฏ Features

  • ๐ŸŽฏ Real-time Gaze Tracking: High-precision facial feature extraction using Mediapipe
  • ๐ŸŽค Voice Calibration: Support for "here"/"้€™่ฃก" voice commands for calibration and recording
  • ๐Ÿ”ฅ Real-time Heatmap: Real-time gaze point heatmap display with smooth and decay effects
  • ๐Ÿ“Š Data Recording: Automatic recording of gaze point data to CSV files
  • ๐Ÿ–ฅ๏ธ Multi-screen Support: Automatic detection of primary screen resolution
  • ๐ŸŽจ Visual Debugging: Optional camera debug window
  • ๐Ÿš€ High Precision Mode: Multi-frame averaging, polynomial regression, edge weighting for improved accuracy
  • ๐Ÿ”ง Camera Mirroring: Optional horizontal mirroring to fix left-right tracking issues
  • ๐Ÿ“ˆ Accuracy Evaluation: Built-in 5x5 test grid for quantitative accuracy assessment

๐Ÿ› ๏ธ System Requirements

  • macOS 10.15+
  • Python 3.8+
  • Built-in or external webcam
  • Microphone
  • At least 4GB RAM

๐Ÿ“‹ Available Scripts

Script Description Language
./quick_start.sh Quick start with default settings English
./run_high_precision.sh High precision mode (best accuracy) English
./run_basic.sh Basic version with options English
./run_overlay.sh Advanced full-screen overlay version English
./run_high_sensitivity.sh High sensitivity version English

๐Ÿ”ง Installation

# Clone the repository
git clone <repository-url>
cd webcam_voice_label

# Run setup script
./setup.sh

๐Ÿ“š Usage Examples

Basic Usage

# Quick start (recommended)
./quick_start.sh

# High precision mode (best accuracy)
./run_high_precision.sh

# Basic version with debug window
./run_basic.sh

# Advanced full-screen overlay
./run_overlay.sh

Manual Usage

# Basic tracking
python gaze_tracker.py

# With debug window
python gaze_tracker.py --show-cam-debug

# High precision with camera mirroring
python gaze_tracker.py --rows 4 --cols 4 --cam-mirror

# Use Chinese model
python gaze_tracker.py --vosk-model ./vosk-model-small-cn-0.22

# Evaluate accuracy
python evaluate_accuracy.py

๐Ÿ“Š Output

The system generates a gaze_points.csv file with timestamped gaze coordinates:

timestamp,x,y
1640995200.123,960,540
1640995205.456,1200,300

๐ŸŽฏ Accuracy

  • High Precision Mode: ~1-2cm error (0.5-1ยฐ viewing angle)
  • Ideal conditions: ~1-3cm error (1-2ยฐ viewing angle)
  • General conditions: ~3-5cm error
  • Difficult conditions: >5cm error

Accuracy Improvements (v2.0)

  • Multi-frame Averaging: Collects 0.4 seconds of samples per calibration point
  • Polynomial Regression: Uses 2nd-degree polynomial features for better non-linear mapping
  • Edge Weighting: Gives higher weight to edge calibration points for better corner accuracy
  • Camera Mirroring: Optional horizontal mirroring to fix left-right tracking issues

๐Ÿ”ง Troubleshooting

Common Issues

  1. Camera not working: Check System Preferences > Security & Privacy > Camera
  2. Microphone not working: Check System Preferences > Security & Privacy > Microphone
  3. Audio errors: Run brew install portaudio && pip install --force-reinstall sounddevice
  4. Poor tracking: Use high precision mode, recalibrate, check lighting, adjust posture, try camera mirroring

๐Ÿ—๏ธ Technical Stack

  • Mediapipe: Facial feature extraction and iris detection
  • Vosk: Offline speech recognition
  • OpenCV: Image processing and display
  • Scikit-learn: Regression model training
  • PyQt6: Advanced overlay interface

๐Ÿ”ฌ Technical Principles

Machine Learning vs. Simple Geometry

This system uses polynomial regression rather than simple geometric calculations:

Method Accuracy Why Better
Simple Geometry 5-10cm error Only works in ideal conditions
ML Regression 1-3cm error Handles real-world variations

Key Technical Features

  • Polynomial Regression: 2nd-degree features for non-linear mapping
  • Multi-frame Averaging: 0.4s samples per calibration point for noise reduction
  • Edge Weighting: Higher weight for corner calibration points
  • Personal Adaptation: Learns individual facial geometry

Mathematical Model

f: R^n โ†’ Rยฒ
f(facial_features) = (screen_x, screen_y)

Input: Normalized eye/iris coordinates
Output: Screen pixel coordinates
Model: Polynomial regression with edge weighting

For detailed technical documentation, see:

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿค Contributing

Welcome to submit Issues and Pull Requests to improve this project.

๐Ÿ“ž Contact

For questions or suggestions, please contact through GitHub Issues.

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages