Skip to content

Repository files navigation

Focus Tracker Application

A machine learning-based application that tracks eye movements and typing speed to generate comprehensive focus reports on focus levels during work shifts. Now with separate tracking modules for enhanced flexibility and detailed reporting capabilities.

Features

  • Eye Tracking Module: Uses webcam and MediaPipe to track eye movements and calculate focus levels
  • Keyboard Tracking Module: Monitors keyboard input to determine typing speed, keystroke patterns, and word counts
  • Independent Control: Start and stop eye and keyboard tracking separately during a session
  • Machine Learning Classification: Uses RandomForestClassifier to determine focus levels based on collected data
  • Comprehensive Reports: Generates detailed PDF reports with multiple visualizations of focus patterns and typing statistics
  • Graphical User Interface: Easy-to-use interface with buttons for controlling tracking and generating reports
  • Real-time Data Visualization: Provides live graphs of eye focus levels and typing speed
  • Final Focus Report: Summary of user's focus patterns including overall focus percentage, typing speed metrics, and visual analysis

Requirements

  • Python 3.8 or higher
  • Webcam for eye tracking
  • Keyboard for typing speed measurement

Installation

  1. Clone or download this repository to your local machine

  2. Navigate to the project directory:

cd focus_tracker
  1. Install the required dependencies:
pip install -r requirements.txt

Usage

Graphical User Interface (Recommended)

Run the GUI application with:

python focus_tracker_app_gui.py

Or use the provided batch script:

start_gui.bat

Command Line Interface

Run the command-line application with:

python focus_tracker_app.py

Or use the provided batch script:

start_cmd.bat

Final Focus Report

After completing a session, the application generates a comprehensive focus report that includes:

  • Overall Focus Percentage: Percentage of time spent in a focused state
  • Average Typing Speed: Average words per minute during the session
  • Average Eye Focus Level: Mean value of eye focus measurements
  • Visualizations: Multiple graphs including:
    • Eye focus levels over time
    • Typing speed variations
    • Distribution of focus levels
    • Relationship between focus and typing speed

The report is saved as both an image file (.png) and a CSV data file in the reports directory.

Troubleshooting

Eye Tracking Issues

If eye tracking is getting stuck at 0.00:

  1. Webcam Access: Make sure your webcam is properly connected and not being used by another application
  2. Lighting Conditions: Ensure you're in a well-lit environment where your face can be clearly seen
  3. Face Position: Position yourself directly in front of the webcam, about 2-3 feet away
  4. Mediapipe Installation: Verify that Mediapipe is correctly installed: pip install mediapipe --upgrade
  5. CV2 Installation: Ensure OpenCV is properly installed: pip install opencv-python --upgrade

Keyboard Tracking Issues

  1. Permissions: The keyboard module may require administrator/root privileges
  2. Background Processes: Close other applications that might interfere with keyboard monitoring

Usage Tips

  • For best results, use both eye and keyboard tracking together
  • Start a session when you're ready to begin focused work
  • Generate reports after completing significant work periods for valuable insights
  • Experiment with different work environments to see how they affect your focus patterns

How to Use

  1. Launch the application using the command above
  2. Click Start Session to begin a new tracking session
  3. Click Start Eye Tracking to begin monitoring your eye movements
    • A webcam window will appear showing your face with tracking points
  4. Click Start Keyboard Tracking to begin monitoring your typing
  5. Work or study normally while the application tracks your focus
  6. Use the Stop Eye Tracking and Stop Keyboard Tracking buttons to pause tracking as needed
  7. When finished, click Stop Session to end the session
  8. Click Generate Report to view a detailed analysis of your focus patterns

How It Works

Eye Tracking Module (eye_tracker.py)

This module uses the MediaPipe FaceMesh model to detect facial landmarks, particularly focusing on the eyes. It calculates normalized eye openness using eye landmark height-to-width ratios to estimate focus levels., which is used as an indicator of focus level. Eye openness values are mapped to discrete focus levels based on observed attention patterns.

Keyboard Tracking Module (keyboard_tracker.py)

This module tracks keyboard input to calculate:

  • Typing speed in words per minute (WPM)
  • Time between keystrokes
  • Total words typed
  • Most common keys used
  • Detailed typing statistics for the session report

Main Application (focus_tracker_app.py)

The main application coordinates the two tracking modules and provides:

  • A command-based interface for user control
  • Data merging and synchronization between modules
  • Machine learning model training and prediction
  • Enhanced report generation with multiple visualizations

Machine Learning Model

The RandomForestClassifier model is trained on the collected data to classify periods of high and low focus. The model considers eye focus levels, typing speed, and timing patterns to make its predictions. If insufficient data is available, a heuristic method based on thresholds is used instead.

Enhanced Focus Report

After the tracking session, the application generates a comprehensive PDF report with:

  • Overall focus percentage pie chart
  • Focus levels over time intervals
  • Scatter plot of eye focus vs typing speed
  • Distribution histograms for eye focus levels and typing speeds
  • Detailed session statistics and keyboard tracking report

Project Structure

focus_tracker/
├── eye_tracker.py           # Handles eye tracking functionality
├── keyboard_tracker.py      # Handles keyboard tracking functionality
├── focus_tracker_app.py     # Command-line version of the application
├── focus_tracker_app_gui.py # GUI-based version with buttons
├── requirements.txt         # Dependencies
├── README.md                # Documentation
├── data/                    # Directory for storing training data
└── reports/                 # Directory for generated reports

Notes

  • Ensure your webcam is properly connected for eye tracking
  • The application may take a few seconds to initialize the computer vision models
  • Press 'ESC' in the eye tracking window to stop tracking
  • The generated reports are saved in the reports/ directory
  • Both data and reports directories will be created automatically if they don't exist
  • For optimal performance, keep the application window visible during tracking

Troubleshooting

  • Webcam not detected: Ensure your webcam is properly connected and not being used by another application
  • High CPU usage: Lower the resolution of your webcam or close other resource-intensive applications
  • Inaccurate focus detection: Adjust your position to ensure your face is centered in the webcam view
  • Keyboard tracking issues: Make sure you're using a standard keyboard layout
  • ESC Key Not Responding: If the ESC key doesn't stop tracking, use the command interface to stop the session

License

This project is open-source and available for educational purposes.

Acknowledgements

Contact

For questions or suggestions, please reach out to the developer.

Changelog

Version 3.0

  • Added graphical user interface with buttons for controlling all features
  • Added live data visualization for real-time feedback
  • Improved application structure for better maintainability
  • Enhanced user experience with status updates and logging

Version 2.0

  • Separated eye tracking and keyboard tracking into independent modules
  • Added command-based interface for better user control
  • Enhanced focus report with additional visualizations
  • Improved data synchronization between tracking modules
  • Added keyboard-specific statistics to the report

About

Machine learning-based focus tracking system using eye movement and typing behavior

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages