This project was developed for the hackathon theme "科技无障碍 AI" (Technology Accessibility AI). It uses computer vision and AI to help ADHD individuals maintain focus during work or study sessions.
- Purpose: Helps users stay focused by monitoring their attention via webcam
- How it works:
- Detects when the user is looking away from the screen
- Detects when the user's face/eyes aren't visible to the camera
- Provides immediate visual and audio alerts when attention is lost
- Shows an eye-catching flashing alert that demands attention
- Tracks focus metrics in a status bar
- NEW: Focus Reward System - Plays a celebratory sound and displays positive feedback when user maintains focus for 10 consecutive seconds
- NEW: Brief Distraction Tolerance - Allows short distractions under 2 seconds without resetting focus (for picking up a pen, scratching, etc.)
- NEW: Session Statistics - Tracks total session time, focus time, and focus percentage
- Visually displays focus progress with a progress bar
- Enhanced reward screen with congratulatory message, confetti effects, and countdown timer
- Cursor control via eye tracking (requires calibration)
- Wink detection for click actions
- Simulated mode for testing without camera access
- Python 3.7+
- OpenCV (cv2)
- NumPy
- PyAutoGUI
- Pygame (for audio alerts)
pip install opencv-python numpy pyautogui pygame
The application requires two audio files:
attention.mp3
- Played when attention is lostwow.mp3
- Played as a reward when focus is maintained for 10 seconds
Place these in the same directory as the application.
- Run the application:
python main.py
- You'll see a webcam feed and detection information. Press keys to control the application:
A
: Start ADHD Attention Assistant modeT
: Toggle session statistics displayC
: Start calibration (for cursor control)S
: Start cursor control (after calibration)D
: Return to detection modeQ
: Quit
- Press
A
to activate - Position yourself in front of the camera
- Continue your work as normal
- Brief distractions (under 2 seconds) are tolerated without resetting focus
- If you look away or get distracted for longer periods, the system will flash an alert and play a sound
- If you maintain focus for 10 seconds, you'll receive a positive reward sound and visual feedback
- Press
T
to view session statistics (total time, focus time, focus percentage) - Press any key to dismiss an active alert or reward screen
On macOS, you'll need to grant camera permissions:
- Go to System Settings > Privacy & Security > Camera
- Allow your terminal or IDE to access the camera
If camera access isn't available, the application will run in simulation mode:
- Move your mouse around the screen to control the simulated eye movement
- Move your mouse to the edge of the screen to trigger attention alerts
- Keep your mouse in the center of the screen to trigger focus rewards
This project addresses accessibility needs for individuals with ADHD by providing technology that:
- Reduces distractions
- Helps maintain focus during important tasks
- Creates awareness of attention patterns
- Provides immediate feedback when focus shifts
- Offers positive reinforcement for sustained attention
- Understands natural behavior by allowing brief distractions
- Provides quantitative feedback on focus performance
The AI component uses computer vision to detect face position, eye states, and gaze direction, then applies algorithms to determine attention state and provide appropriate interventions.