FocusGuard is a real-time webcam monitor for this specific rule:
- Detect a phone in the camera view.
- Detect your face.
- If you appear to be looking at that phone continuously for more than 4 seconds, play a beep warning.
The app now uses a phone-first pipeline.
Detection layer:
- Face, eyes, smile, lips: OpenCV Haar/lip heuristics.
- Phone: YOLOv4-tiny (COCO class:
cell phone) through OpenCV DNN.
Phone-looking layer:
- Select primary face (largest face box).
- Select primary phone (highest-confidence phone box).
- Consider user "looking at phone" when phone is below the face and horizontally close to it.
- If this condition continues for threshold seconds (default 4.0s), fire a beep alert.
Note: this is still a heuristic for "looking at phone" from webcam geometry.
FocusGuard/
README.md
requirements.txt
.gitignore
src/
app.py
attention/
__init__.py
screen_attention_monitor.py
detectors/
__init__.py
haar_feature_detector.py
phone_detector.py
utils/
__init__.py
drawing.py
- Install dependencies with system Python:
py -3.13 -m pip install -r requirements.txtOn first run, model files are downloaded automatically to models/yolo/.
Basic run:
py -3.13 -m src.appCustom camera and thresholds:
py -3.13 -m src.app --camera 0 --width 1280 --height 720 --phone-threshold 4.0 --phone-confidence 0.35- Bounding boxes for face, eyes, smile, and lips.
- Phone timer overlay, for example:
Phone timer: 2.8s / 4.0s. - State text, for example:
Looking at phone,No phone,No face,Phone too far from face. - Alarm when threshold is crossed.
--phone-threshold: seconds before warning, default4.0.--phone-confidence: detector confidence threshold, default0.35.
- On Windows, alarm uses
winsound.Beep. - If beep API is unavailable, the app falls back to terminal bell/message.
- Press
qto quit.
- Use good front lighting for stable face/eye detection.
- Keep camera at eye level.
- Increase
--phone-thresholdif alerts fire too quickly. - Reduce
--phone-confidenceslightly if phone is missed often.