Focus Guardian is a local desktop application that uses your webcam to monitor user attention. It detects whether the user is looking away, looking down, or if no face is present, and provides real-time visual and audio feedback.
Recommended demo mode: SHOW_DEBUG_METRICS=false for a clean recording. Calibration mode: enable debug metrics to inspect eye movement, baseline values, and detection ratios.
- Python 3.12
- Pipenv
- OpenCV
- MediaPipe
- NumPy
- pygame
- python-dotenv
- pylint
- autopep8
The detector loads the model from:
assets/models/face_landmarker.task
You can also change the path with FACE_LANDMARKER_MODEL_PATH.
pipenv installpipenv run python src/main.pyPress q to close the app.
q: quitd: toggle debug metricsl: toggle landmarksr: reset the distraction counter
Start from .env.example and adjust only what you need:
CAMERA_INDEX: webcam indexFRAME_WIDTHandFRAME_HEIGHT: visual preview resolutionANALYSIS_FRAME_WIDTH: frame width used for analysisMIRROR_PREVIEW: mirror-style webcam previewFACE_LANDMARKER_MODEL_PATH: path to the.taskmodelNO_FACE_THRESHOLD_SECONDS: time required to triggerno_faceLOOKING_AWAY_THRESHOLD_SECONDS: time required to triggerlooking_awayLOOKING_DOWN_THRESHOLD_SECONDS: time required to triggerlooking_downRECOVERY_THRESHOLD_SECONDS: minimum stability time required to return tofocusedLOOKING_AWAY_RATIO_THRESHOLD: horizontal sensitivityLOOKING_DOWN_RATIO_THRESHOLD: vertical sensitivityEYES_DOWN_RATIO_THRESHOLD: iris-based downward gaze sensitivityMIN_DETECTION_CONFIDENCE: minimum face detection confidenceMIN_FACE_PRESENCE_CONFIDENCE: minimum face presence confidenceMIN_TRACKING_CONFIDENCE: minimum tracking confidenceMETRIC_SMOOTHING: simple per-frame metric smoothingAUDIO_VOLUME: global audio volume between0.0and1.0SHOW_LANDMARKS: draws the visible face mesh over the user’s faceSHOW_DEBUG_METRICS: shows useful calibration metrics
Audio files are loaded from assets/sounds/. You can configure only SOUND_1_PATH if you want a simple demo with a single MP3 file.