A specialized system for monitoring dog cleanup compliance using live camera feed processing with dual object detection, session management, and email notifications.
- πΆββοΈ Session Triggers: People and dogs entering/leaving start/end monitoring sessions
- π© Waste Counting: Counts poop (or proxy objects) before and after each session
- π Cleanup Analysis: Determines if cleanup occurred by comparing before/after counts
- π§ Smart Notifications: Sends cleanup compliance reports with video footage
- π₯ Video Recording: Records complete sessions for review and evidence
- π₯οΈ Headless Operation: Can run 24/7 on servers without GUI
-
Clone or download the project files
-
Install dependencies:
pip install -r requirements.txt
For Python 3.13+ users: If you encounter installation issues, try:
pip install --upgrade pip setuptools wheel pip install -r requirements.txt
-
Configure for dog poop detection: Update the
.envfile for dog cleanup monitoring:# Dog Poop Detection System Configuration CAMERA_INDEX=0 CONFIDENCE_THRESHOLD=0.5 SESSION_TIMEOUT=10 GRACE_PERIOD_SECONDS=30 OUTPUT_DIR=./recordings # Dual Detection Mode for Dog Cleanup Monitoring DUAL_DETECTION_MODE=true SESSION_TRIGGER_OBJECTS=person,dog COUNTING_OBJECTS=bottle # Use 'bottle' as proxy for 'poop' during testing ADDITIONAL_OBJECTS=cat # Email Configuration EMAIL_SMTP_SERVER=smtp.gmail.com EMAIL_SMTP_PORT=587 EMAIL_FROM=your_email@gmail.com EMAIL_PASSWORD=your_app_password EMAIL_RECIPIENTS=reviewer1@email.com,reviewer2@email.com # Database Configuration DATABASE_PATH=data/mantis.db
-
Configure interactively (recommended):
python configure.py
The system uses SQLite to store all session data and detected objects for analysis and review.
- Session Storage: All tracking sessions with timestamps, object counts, and grace period data
- Object Detection History: Complete record of every detected object with confidence scores and positions
- Activity Logging: Real-time logging of all detections for heatmap generation and spatial analysis
- Email Tracking: Records which sessions have had notification emails sent
- Statistics & Analysis: Query sessions by date range, object counts, and cleanup compliance
- Heatmap Data: Generate activity density maps and spatial analysis reports
# View database statistics
python scripts/database_manager.py stats
# Show recent sessions
python scripts/database_manager.py recent --limit 20
# Show detailed session information
python scripts/database_manager.py details [session-id]
# Export all data to JSON
python scripts/database_manager.py export sessions_backup.json
# Activity analysis commands
python scripts/database_manager.py activity --days 7
python scripts/database_manager.py timeline --hours 24 --class person
python scripts/database_manager.py heatmap heatmap.json --days 1 --grid-size 50# Generate heatmap visualization
python scripts/heatmap_visualizer.py --days 7 --grid-size 40
# Save heatmap data for external tools
python scripts/heatmap_visualizer.py --days 1 --save activity_data.json
# Load and analyze existing heatmap data
python scripts/heatmap_visualizer.py --load activity_data.json
# Filter by object class
python scripts/heatmap_visualizer.py --class person --days 3- Default:
data/mantis.db - Configurable via
DATABASE_PATHin.env - Automatically created on first run
- Excluded from git via
.gitignore
python run.py# Test configuration tool
python configure.py
# Use different camera
python run.py --camera-index 1
# Adjust detection sensitivity
python run.py --confidence 0.7
# Run without GUI (for servers)
python run.py --headless
# Test email notifications
python run.py --test-email
# See all detectable objects
python run.py --list-objects# Test detection functionality
python tests/test_detection.py
# Test email template generation
python tests/test_email_template.py
# Run grace period demonstration
python scripts/grace_period_demo.pyFor Gmail, you'll need to:
- Enable 2-factor authentication
- Create an app-specific password
- Use the app password in
EMAIL_PASSWORD
-
ObjectTracker (
object_tracker.py)- Dual detection mode with session triggers and counting objects
- Manages dog cleanup monitoring sessions
- Records video footage of interactions
- Counts waste items before and after sessions
-
EmailNotificationService (
email_service.py)- Sends cleanup compliance reports
- Attaches session videos as evidence
- Provides detailed before/after analysis
-
TrackingSystemManager (
main.py)- Coordinates dual detection components
- Monitors cleanup sessions
- Handles system lifecycle
- πΆββοΈ Session Start: Person or dog enters the monitored area
- π© Initial Count: System counts waste items (poop/bottles) before interaction
- πΉ Activity Recording: Monitors people/dog movements throughout session
- β±οΈ Session End: No people/dogs detected for configured timeout period
- π’ Final Count: System counts waste items after interaction
- π Cleanup Analysis: Compares before/after counts to determine compliance
- π§ Notification: Email report with cleanup results and video evidence
Visual Indicators:
- π΅ Blue boxes: People and dogs (session triggers)
- π΄ Red boxes: Waste items being counted (poop/bottles)
- π’ Green boxes: Additional tracked objects (cats, etc.)
- DetectedObject: Represents a single detected object with position, confidence, and timestamp
- TrackingSession: Contains complete session data including entry/exit objects and video path
CAMERA_INDEX: Which camera to use (0 for default)CONFIDENCE_THRESHOLD: Minimum confidence for object detection (0.5 recommended)SESSION_TIMEOUT: Seconds to wait before ending a session (10 recommended)GRACE_PERIOD_SECONDS: Time to wait after session ends to detect new poop (30 recommended)
DUAL_DETECTION_MODE=true: Enable specialized dog cleanup monitoringSESSION_TRIGGER_OBJECTS: Objects that start/end sessions (e.g., "person,dog")COUNTING_OBJECTS: Waste items to count before/after (e.g., "bottle" as poop proxy)ADDITIONAL_OBJECTS: Other objects to track (e.g., "cat")
π‘ Important Note: YOLO doesn't include "poop" by default. Use objects like "bottle" or "cup" as proxies for testing, or train a custom model for actual poop detection.
The grace period feature provides a monitoring window after a session ends to detect if new poop appears:
- Session End: When trigger objects (people/dogs) leave and
SESSION_TIMEOUTexpires - Initial Count: System counts poop objects immediately after session timeout
- Grace Period: Waits for
GRACE_PERIOD_SECONDSto allow cleanup time - Final Count: Counts poop objects again after grace period expires
- Analysis: Compares initial vs. final counts to detect new poop or cleanup
This helps detect scenarios where:
- Dogs poop after the owner has already left the area
- Cleanup happens during the grace period
- New poop appears from other dogs shortly after
- Configure SMTP server settings for Gmail/other providers
- Set reviewer email addresses (comma-separated)
- Use app-specific passwords for Gmail
OUTPUT_DIR: Directory for saving videos and session data
# Start tracking
tracker.start_tracking()
# Count objects in current frame
counts = tracker.count_objects_in_frame(frame)
# Get object positions
positions = tracker.get_object_positions(frame)
# Get session summary
summary = tracker.get_session_summary(session_id)
# Get available objects for detection
available_objects = tracker.get_available_objects()
# Get current detection filter info
filter_info = tracker.get_detection_filter_info()
# Update object filter at runtime
tracker.update_object_filter(['person', 'dog'], detect_only_specified=True)# Send session notification
email_service.send_session_notification(session)
# Send test email
email_service.send_test_email()- Saved as
session_{session_id}_{timestamp}.mp4 - Contains raw footage of the entire session
- Saved as
session_{session_id}.json - Contains detailed object information and analysis
{
"session_id": "abc123...",
"start_time": "2025-07-14T10:30:00",
"end_time": "2025-07-14T10:32:30",
"objects_entered": [...],
"objects_exited": [...],
"objects_before_count": 0,
"objects_after_count": 2,
"video_path": "./recordings/session_abc123_20250714_103000.mp4"
}The email template is a comprehensive HTML report that includes:
-
Header Section
- System branding with dog emoji
- Session ID for tracking
- Professional green color scheme
-
Detection Mode Alert
- Clear explanation of dual detection mode
- Session trigger objects (people/dogs)
- Grace period duration
- System purpose and functionality
-
Session Overview
- Start and end timestamps
- Total session duration
- Grace period status (completed/in progress)
- Video attachment availability
-
Statistics Dashboard
- Items before session (baseline count)
- Trigger events entered (people/dogs detected)
- Trigger events exited (people/dogs left)
- Items after session (post-session count)
- Grace period count (final count after grace period)
-
Activity & Departure Summary
- Detailed tables of detected objects
- Object type and count breakdown
- Entry and exit event tracking
-
Change Analysis
- Net change calculation
- Smart alerts based on detection results:
- β "Good Job: X waste items cleaned up!"
β οΈ "Cleanup Alert: X more waste items detected!"- βΉοΈ "No Change: Same number of items before/after"
-
Grace Period Analysis (NEW!)
- Items at session end vs. after grace period
- Grace period change calculation
- Specific grace period alerts:
- π "Additional Detection: X more items during grace period!"
- π§Ή "Grace Period Cleanup: X items cleaned up during grace period!"
- βΉοΈ "No Additional Change: No activity during grace period"
-
Detailed Object Positions
- Precise coordinates for each detected object
- Confidence scores for AI detections
- Timestamps for forensic analysis
-
Video Evidence
- Complete session recording attached as MP4
- File size and duration information
- HTML Format: Professional, mobile-friendly design
- Color-Coded Alerts: Green for good, red for alerts, blue for info
- Responsive Layout: Works on desktop and mobile devices
- Video Attachment: Complete session footage for review
- Detailed Logging: Every detection event with timestamps
You can view a complete example of the email template by opening email_template_example.html in your web browser. This shows exactly how the email report will look with sample data including grace period information.
# View the email template example
open email_template_example.html # macOS
# or
start email_template_example.html # Windows
# or
xdg-open email_template_example.html # Linux-
Camera not found
- Check camera index in configuration
- Ensure camera is not being used by another application
-
Email not sending
- Verify SMTP settings
- Check app password for Gmail
- Test with
--test-emailoption
-
Poor object detection
- Adjust confidence threshold
- Ensure good lighting conditions
- Check camera positioning
-
High CPU usage
- Use headless mode for servers
- Consider reducing camera resolution
- Adjust detection frequency
-
Installation issues on Python 3.13+
- Upgrade
pip,setuptools, andwheelbefore installing requirements:
pip install --upgrade pip setuptools wheel pip install -r requirements.txt
- Upgrade
System logs are saved to tracking_system.log and displayed in console.
# Enable dual detection for dog cleanup monitoring
DUAL_DETECTION_MODE=true
SESSION_TRIGGER_OBJECTS=person,dog
COUNTING_OBJECTS=bottle # Using bottle as poop proxy for testing
ADDITIONAL_OBJECTS=cat# Use cups as waste proxies
COUNTING_OBJECTS=cup
# Use multiple proxy objects
COUNTING_OBJECTS=bottle,cup
# Track additional context
ADDITIONAL_OBJECTS=cat,bicycle,backpack# Once you have a custom trained model for poop detection
COUNTING_OBJECTS=poop- π Dog Park Monitoring: Monitor cleanup compliance in dog parks and public areas
- π Private Property: Track pet waste cleanup on private property
- π³ Trail Monitoring: Ensure hikers clean up after their dogs on trails
- π’ Apartment Complex: Monitor pet areas in residential complexes
- πΎ Training Tool: Help dog owners develop good cleanup habits
- OpenCV: Camera handling and computer vision
- Ultralytics YOLO: AI object detection model
- python-dotenv: Configuration management
- smtplib: Email notifications
- Real-time Processing: ~30 FPS on modern hardware
- Detection Model: YOLOv8 nano for speed/accuracy balance
- Storage: Compressed MP4 video recordings
- Memory: Optimized for 24/7 operation
- Poop Detection: YOLO doesn't include "poop" by default
- Proxy Objects: Use "bottle", "cup", or similar objects for testing
- Custom Training: Train custom models for actual poop detection
- Lighting: Good lighting improves detection accuracy