Quick Start Guide

Get your first gaze tracking experiment running in under 10 minutes. This guide walks through setup, configuration, and execution of a basic experiment.

Prerequisites

Required Software

Tool Version Installation
Node.js 14.0+ https://nodejs.org/
http-server Latest npm install -g http-server
OpenSSL Any Included with Git Bash/Linux/macOS

Hardware Requirements

  • Webcam with 720p minimum resolution
  • Quad-core CPU (Intel i5/AMD Ryzen 5 or better)
  • 8GB RAM minimum (16GB recommended)
  • 1920x1080 display minimum

Installation Steps

Step 1: Clone Repository

git clone https://github.com/mrhunsaker/GazeTracking.git
cd GazeTracking

Step 2: Install http-server

npm install -g http-server
Note: On macOS/Linux, you may need to use sudo npm install -g http-server

SSL Certificate Setup

Modern browsers require HTTPS to access webcams. Generate self-signed SSL certificates:

Generate Certificates

openssl req -nodes -new -x509 -keyout server.key -out server.cert

Certificate Generation Prompts

You can press Enter to skip all prompts, or fill them in as follows:

Country Name: US
State: [Your State]
Locality: [Your City]
Organization: Research Lab
Common Name: localhost
Email: your@email.com
Browser Warning: Your browser will show a security warning for self-signed certificates. This is expected - click "Advanced" and "Proceed to localhost" to continue.

Running Your First Experiment

Step 1: Start the Server

Navigate to the experiment folder and start the HTTPS server:

cd StudentFolders/2025_Students
http-server -S -C server.cert -K server.key -p 8080

You should see:

Starting up http-server, serving ./ through https
Available on:
  https://127.0.0.1:8080
  https://192.168.1.100:8080
Hit CTRL-C to stop the server

Step 2: Open in Browser

  1. Open Chrome or Edge (recommended)
  2. Navigate to https://localhost:8080
  3. Click "Advanced" → "Proceed to localhost" (for self-signed cert)
  4. Allow camera permissions when prompted

Step 3: Initialize Experiment

  1. Press any key to start initialization
  2. Enter participant initials (max 6 characters)
  3. Select test type:
    • Shapes: 193 geometric shapes
    • Colors: 10 colored objects
    • Abstract: 403 abstract patterns
  4. Select trial count (10-50)
  5. Click "Start"

Step 4: Calibration

The calibration sequence will begin automatically:

  1. 9-Point Calibration: Click each yellow dot that appears
    • Look directly at each dot before clicking
    • Keep your head still
    • Maintain consistent posture
  2. Quality Validation: System automatically tests accuracy
  3. Refinement (if needed): 3 additional points if quality < 75%
Calibration Tips:
  • Sit 50-70cm from screen
  • Ensure good lighting on your face
  • Remove glasses if possible (reduces reflections)
  • Look at the center of each dot, not the edges

Step 5: Run Experiment

After calibration, trials begin automatically:

  1. Sample Phase: One object shown for 3 seconds
  2. Delay: 2-second black screen
  3. Test Phase: Three objects shown for 10 seconds
    • Type 1 trials: target + 2 identical foils
    • Type 2 trials: target + 2 different foils
  4. Repeat: Continues for selected trial count
  5. Periodic Recalibration: 3-point recal every 10 trials

Data Export

When the experiment completes, data is automatically:

  1. Saved to browser storage (IndexedDB via LocalForage)
  2. Downloaded as JSON file to your Downloads folder

Data File Format

{
  "trialData": [
    {
      "trialNumber": 1,
      "type": 1,
      "startTime": 1706284843120,
      "endTime": 1706284858125,
      "object1": 45,
      "testObjects": [45, 127, 127],
      "positions": [
        {"position": "left", "objectNum": 45, "isTarget": true},
        {"position": "center", "objectNum": 127, "isTarget": false},
        {"position": "right", "objectNum": 127, "isTarget": false}
      ],
      "gazeData": [/* array of gaze points */]
    }
    // ... more trials
  ],
  "gazeData": [/* all gaze points across session */],
  "timestamp": 1706284860000,
  "totalTrials": 20
}

Gaze Data Format

{
  "x": 512.3,              // Filtered gaze X (pixels)
  "y": 384.7,              // Filtered gaze Y (pixels)
  "rawX": 515.1,           // Raw gaze X before filtering
  "rawY": 388.2,           // Raw gaze Y before filtering
  "headPose": {
    "roll": 0.05,          // Head roll angle (radians)
    "pitch": -0.02,        // Head pitch angle (radians)
    "yaw": 0.08,           // Head yaw angle (radians)
    "distance": 125.4      // Face distance metric
  },
  "time": 1706284847123,   // Absolute timestamp
  "relativeTime": 2543,    // Milliseconds since trial start
  "phase": "experiment"    // 'calibration' or 'experiment'
}

Common Issues & Solutions

Camera Not Detected

Symptom: Browser doesn't prompt for camera permission or WebGazer fails to initialize.

Solutions:

  1. Check HTTPS: Webcam access requires SSL
    # Verify URL starts with https://
    https://localhost:8080  ✓
    http://localhost:8080   ✗
  2. Camera Permissions: Check browser settings
    • Chrome: Settings → Privacy → Site Settings → Camera
    • Edge: Settings → Cookies and site permissions → Camera
  3. Camera in Use: Close other apps using webcam (Zoom, Skype, etc.)
  4. Try Different Browser: Chrome recommended, Firefox supported

Poor Calibration Quality

Symptom: Repeated refinement prompts or inaccurate gaze tracking.

Solutions:

  1. Lighting: Ensure face is well-lit
    • Avoid backlighting (window behind you)
    • Use front/side lighting
    • Avoid harsh shadows on face
  2. Distance: Sit 50-70cm from screen
  3. Head Position: Keep head still during calibration
  4. Glasses: Remove if possible (reflections interfere)
  5. Camera Angle: Webcam should be at eye level

SSL Certificate Error

Symptom: Browser shows "Your connection is not private" warning.

Solution:

This is expected for self-signed certificates in local development:

  1. Click "Advanced" button
  2. Click "Proceed to localhost (unsafe)"
  3. Allow camera permissions
Security Note: This warning is safe to bypass for localhost during development. For production deployments, use properly signed certificates from a Certificate Authority.

Slow Performance / Lag

Symptom: Choppy video preview or delayed gaze predictions.

Solutions:

  1. Close Other Apps: Free up CPU/RAM
  2. Lower Video Preview Size: Edit in trialManager.js:
    webgazer.showVideoPreview(false); // Disable preview
  3. Use Chrome: Best TensorFlow.js performance
  4. Check System Requirements: Ensure quad-core CPU, 8GB+ RAM
  5. GPU Acceleration: Enable in browser settings
    • Chrome: Settings → System → "Use hardware acceleration when available"

Images Not Loading

Symptom: "Error loading images" or blank trial screens.

Solutions:

  1. Check Image Folders: Verify folder structure:
    StudentFolders/2025_Students/
      Shapes/        # 193 images: object001.png to object193.png
      Colors/        # 10 images: object001.png to object010.png
      Abstract/      # 403 images: object001.png to object403.png
  2. Case Sensitivity: Folder names must match exactly (Linux/macOS)
  3. Server Path: Ensure server running from correct directory
  4. Console Errors: Check browser console (F12) for specific error messages

Next Steps

Example Experiment Workflow

// index.html - include libraries
<script src="webgazer.js"></script>
<script src="localforage.min.js"></script>
<script type="module">
  import { initializeExperiment } from './trialManager.js';
  
  document.addEventListener('DOMContentLoaded', () => {
    initializeExperiment();
    console.log('Press any key to begin');
  });
</script>

// Workflow automatically handles:
// 1. Participant dialog
// 2. Image loading
// 3. WebGazer init with enhanced features
// 4. 9-point calibration + validation
// 5. Trial loop with periodic recalibration
// 6. Data export to JSON + LocalForage

Support

If you encounter issues not covered here: