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.
- 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
- Python 3.8 or higher
- Webcam for eye tracking
- Keyboard for typing speed measurement
-
Clone or download this repository to your local machine
-
Navigate to the project directory:
cd focus_tracker- Install the required dependencies:
pip install -r requirements.txtRun the GUI application with:
python focus_tracker_app_gui.pyOr use the provided batch script:
start_gui.batRun the command-line application with:
python focus_tracker_app.pyOr use the provided batch script:
start_cmd.batAfter 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.
If eye tracking is getting stuck at 0.00:
- Webcam Access: Make sure your webcam is properly connected and not being used by another application
- Lighting Conditions: Ensure you're in a well-lit environment where your face can be clearly seen
- Face Position: Position yourself directly in front of the webcam, about 2-3 feet away
- Mediapipe Installation: Verify that Mediapipe is correctly installed:
pip install mediapipe --upgrade - CV2 Installation: Ensure OpenCV is properly installed:
pip install opencv-python --upgrade
- Permissions: The keyboard module may require administrator/root privileges
- Background Processes: Close other applications that might interfere with keyboard monitoring
- 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
- Launch the application using the command above
- Click
Start Sessionto begin a new tracking session - Click
Start Eye Trackingto begin monitoring your eye movements- A webcam window will appear showing your face with tracking points
- Click
Start Keyboard Trackingto begin monitoring your typing - Work or study normally while the application tracks your focus
- Use the
Stop Eye TrackingandStop Keyboard Trackingbuttons to pause tracking as needed - When finished, click
Stop Sessionto end the session - Click
Generate Reportto view a detailed analysis of your focus patterns
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.
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
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
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.
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
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
- 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
- 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
This project is open-source and available for educational purposes.
- MediaPipe for facial landmark detection
- OpenCV for computer vision capabilities
- scikit-learn for machine learning algorithms
- pandas and matplotlib for data analysis and visualization
For questions or suggestions, please reach out to the developer.
- 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
- 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