Skip to content

datumbrain/cam-feed-ai-classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cam-feed-ai-classifier

A real-time AI-powered camera feed classifier that uses YOLOv8 to detect and classify whether people are actively working at their desks. Supports both MacBook built-in cameras and iPhone cameras via Continuity Camera.

Python OpenCV YOLOv8 License

πŸš€ Features

  • Real-time AI Classification: Live desk work activity detection using YOLOv8
  • Multi-Camera Support: Works with MacBook cameras and iPhone cameras
  • Person & Equipment Detection: Identifies people, laptops, keyboards, mice, and phones
  • Pose Analysis: Advanced body posture analysis for accurate work state detection
  • Live Statistics: Real-time counts of working vs. idle people
  • High Performance: Optimized frame processing with adjustable quality modes

πŸ“Š Classifications

  • 🟒 Working: Person at desk with active working posture
  • 🟑 At Desk: Person at desk but not actively engaged
  • 🟠 At Desk (Idle): Person at desk with minimal activity
  • πŸ”΄ Away from Desk: Person not positioned at workspace

πŸ› οΈ Installation

Prerequisites

  • Python 3.8+
  • macOS (tested on macOS 13+)
  • Camera access permissions

Setup

  1. Clone the repository

    git clone https://github.com/yourusername/cam-feed-ai-classifier.git
    cd cam-feed-ai-classifier
  2. Install dependencies

    # Using pipenv (recommended)
    pipenv install
    
    # Or using pip
    pip install -r requirements.txt
  3. Grant camera permissions

    • System Preferences β†’ Security & Privacy β†’ Camera
    • Enable access for Terminal/IDE

🎯 Quick Start

MacBook Camera

pipenv shell
python main.py

iPhone Camera Setup

Method 1: Continuity Camera (macOS 13+)

  1. iPhone: Settings β†’ General β†’ AirPlay & Handoff β†’ Continuity Camera βœ“
  2. Mac: System Settings β†’ General β†’ AirPlay & Handoff β†’ iPhone Widgets βœ“
  3. Keep iPhone unlocked and nearby

Method 2: Third-party Apps

Then run:

pipenv run python main.py

⌨️ Controls

Key Action
q Quit application
s Save current frame
t Test camera connection
f Toggle full processing mode
c Show available cameras
r Reset/restart detection

πŸ“ Project Structure

cam-feed-ai-classifier/
β”œβ”€β”€ LICENSE                   # Project license
β”œβ”€β”€ Pipfile                   # Pipenv dependencies
β”œβ”€β”€ Pipfile.lock              # Locked dependency versions
β”œβ”€β”€ main.py                   # Main application
β”œβ”€β”€ pyproject.toml            # Project configuration
β”œβ”€β”€ .gitignore                # Git ignore rules
β”œβ”€β”€ .pre-commit-config.yaml   # Pre-commit hooks
└── README.md                 # This file

πŸ”§ Configuration

Camera Detection

The system automatically detects available cameras:

  • Index 0: MacBook built-in camera (1280x720)
  • Index 1: iPhone/external camera (1920x1080+)
  • Index 2+: Additional cameras

Adjusting Sensitivity

Edit confidence thresholds in main.py:

# Object detection confidence
obj_results = self.yolo_model.predict(frame, conf=0.3)

# Working pose threshold
is_working = working_score > 0.5  # Adjust 0.1-0.9

Performance Tuning

# Frame processing (every Nth frame)
skip_frames = 2  # Process every 3rd frame

# Camera resolution
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)   # Higher = better quality
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)  # Higher = slower processing

🧠 How It Works

AI Pipeline

  1. Object Detection (YOLOv8): Detects persons and work equipment
  2. Spatial Analysis: Determines desk positioning relationships
  3. Pose Estimation (YOLOv8-pose): Analyzes body keypoints
  4. Classification Logic: Combines spatial + pose data for final status
  5. Real-time Display: Live visualization with statistics

Detection Logic

  • Proximity Check: Person within range of work equipment
  • Posture Analysis: Sitting position, shoulder alignment, head orientation
  • Hand Position: Typing posture detection via wrist/elbow keypoints
  • Engagement Score: Combined confidence metric (0.0-1.0)

πŸŽ›οΈ Output Display

The interface shows:

  • Live camera feed with bounding boxes
  • Person classifications with confidence scores
  • Equipment detection highlights
  • Real-time statistics (People | At Desk | Working)
  • Processing mode and timestamp
  • Camera resolution info

πŸ› Troubleshooting

Camera Issues

# Test camera availability
python -c "import cv2; print([cv2.VideoCapture(i).isOpened() for i in range(5)])"

Common Solutions:

  • Close other camera apps (Zoom, Teams, etc.)
  • Restart Terminal/IDE after granting permissions
  • Try different camera indices (0, 1, 2)
  • For iPhone: ensure same Apple ID, WiFi/Bluetooth enabled

Performance Issues

  • Use MacBook camera for better performance
  • Reduce resolution in camera settings
  • Increase frame skipping (skip_frames = 3)
  • Toggle full processing mode with f key

Detection Quality

  • Ensure good lighting conditions
  • Position camera to capture full desk area
  • Use iPhone camera for higher resolution
  • Adjust confidence thresholds

πŸ”¬ Technical Details

Dependencies

  • ultralytics: YOLOv8 models for detection and pose estimation
  • opencv-python: Computer vision and camera handling
  • numpy: Numerical computations for pose analysis

Models

  • yolov8n.pt: Lightweight object detection (~6MB)
  • yolov8n-pose.pt: Human pose estimation (~6MB)

Models are automatically downloaded on first run.

COCO Classes Used

  • Class 0: Person
  • Class 56: Chair
  • Class 63: Laptop
  • Class 64: Mouse
  • Class 66: Keyboard
  • Class 67: Cell phone

πŸ“Š Performance

Typical Performance:

  • MacBook Camera: ~15-20 FPS (720p)
  • iPhone Camera: ~10-15 FPS (1080p)
  • Detection Accuracy: ~85-90% in good lighting

System Requirements:

  • RAM: 4GB+ recommended
  • CPU: Modern Intel/Apple Silicon
  • Storage: 200MB for models and dependencies

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please run pre-commit hooks before submitting:

pre-commit run --all-files

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Ultralytics for YOLOv8 models
  • OpenCV for computer vision capabilities
  • COCO dataset for training data

⚠️ Privacy Notice

This tool processes camera feeds locally. Please respect privacy laws and obtain consent when monitoring individuals in workplace environments.


Made with ❀️ at Datum Brain for productivity insights.

About

Camera feed AI classifier tested with iPhone continuity camera. Using Yolo (v8).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages