# Screenshot Capture Feature for Live Camera Monitoring ## Overview The NETRA system now automatically captures and saves screenshots whenever unusual activity is detected during live camera monitoring. This feature helps create a comprehensive audit trail of all detected threats and security events. ## What Gets Captured ### 1. **Weapon Detection** 🔫 - **Trigger**: When a weapon (gun or knife) is detected - **Alert Level**: HIGH - **Storage Location**: `uploads/detections/` - **Captured Frame**: The annotated frame showing the detected weapon ### 2. **Violence Detection** 👊 - **Trigger**: When violent activity is detected in the frame - **Alert Levels**: Can be LOW, MEDIUM, HIGH, or CRITICAL - **Storage Location**: `uploads/detections/` - **Details Saved**: Violence class name and confidence score ### 3. **Anomaly Detection** ❓ - **Trigger**: When unusual/anomalous behavior is detected - **Alert Levels**: Based on anomaly severity - **Storage Location**: `uploads/detections/` - **Details Saved**: Anomaly score and description ### 4. **Unsafe Pose + Weapon** ⚠️ - **Trigger**: When a weapon is detected AND person is in unsafe/risky pose - **Alert Levels**: HIGH or CRITICAL (depending on pose risk) - **Storage Location**: `uploads/detections/` - **Details Saved**: - Pose action (standing, sitting, lying, etc.) - Risk level (LOW_RISK or HIGH_RISK) - Weapon presence indicator ## How Screenshots Are Saved ### Automatic Capture Process 1. **Detection Occurs**: When any of the above conditions are met during live camera streaming 2. **Screenshot Captured**: The current frame is saved as a JPEG image 3. **Database Record**: A record is created with: - Detection type (weapon, violence, anomaly, risk) - Alert level (LOW, MEDIUM, HIGH, CRITICAL) - Confidence score - Timestamp - User ID (for multi-user environments) - JSON details about the detection 4. **File Storage**: - Files are stored in: `uploads/detections/` - Filename format: `detection_{type}_{timestamp}_{unique_id}.jpg` - Example: `detection_violence_20250503_143022_a7f2b1c3.jpg` ## Viewing Captured Screenshots ### In Live Camera Dashboard 1. Start the Live Camera monitoring 2. Select detection models (Weapon, Violence, Anomaly, Pose, etc.) 3. Click "Start Camera" 4. Once unusual activity is detected, screenshots appear in the **"Recent Detections"** gallery 5. Click on any thumbnail to view full details ### Recent Detections Gallery Features - **Visual Thumbnails**: Shows last 12 captured detections - **Alert Badge**: Color-coded severity indicator - 🔵 LOW: Blue - 🟠 MEDIUM: Orange - 🔴 HIGH: Red - ⚫ CRITICAL: Dark Red - **Detection Type Emoji**: Quick visual identification - 🔫 Weapon - 👊 Violence - ❓ Anomaly - ⚠️ Risk - **Timestamp**: Shows exact time of detection - **Auto-refresh**: Updates every 5 seconds ### Detection Details Modal Click any detection thumbnail to open a detailed view showing: - Full-size screenshot - Detection type and classification - Alert level/severity - Timestamp - Confidence score ## Storage Structure ``` uploads/ ├── detections/ │ ├── detection_weapon_20250503_143022_a7f2b1c3.jpg │ ├── detection_violence_20250503_143045_b8g3c2d4.jpg │ ├── detection_anomaly_20250503_143101_c9h4d3e5.jpg │ └── ... (more detection files) ``` ## Database Storage ### DetectionHistory Model All screenshots are tracked in the `DetectionHistory` database table: | Field | Type | Purpose | | ----------------- | -------- | ---------------------------- | | id | Integer | Unique identifier | | user_id | Integer | Which user detected it | | detection_type | String | weapon/violence/anomaly/risk | | alert_level | String | LOW/MEDIUM/HIGH/CRITICAL | | confidence | Float | Confidence score (0.0-1.0) | | image_filename | String | JPG filename | | detection_details | JSON | Additional details | | detected_at | DateTime | When it was detected | | session_date | Date | Date of detection | ## API Endpoints ### Retrieve Detection History ``` GET /api/detection-history?limit=20&type=weapon ``` **Response**: ```json { "success": true, "data": [ { "id": 1, "detection_type": "weapon", "alert_level": "HIGH", "confidence": 0.95, "image_filename": "detection_weapon_20250503_143022_a7f2b1c3.jpg", "detected_at": "2025-05-03T14:30:22", "details": { "weapon_class": "gun" } } ] } ``` ### Retrieve Detection Screenshot ``` GET /api/detection-image/{filename} ``` Returns the JPEG image file with proper security verification. ## Configuration ### Thresholds (from config/model_config.py) ```python DETECTION_THRESHOLDS = { 'yolo': 0.5, # Object detection confidence 'weapon': 0.5, # Weapon detection confidence 'violence': 0.5, # Violence detection confidence 'anomaly': 0.5 # Anomaly detection threshold } ALERT_HIT_THRESHOLD = 3 # Consecutive detections before alert ``` ### Screenshot Format - **Format**: JPEG - **Quality**: Default OpenCV JPEG compression - **Size**: Full camera frame resolution - **Naming**: `detection_{type}_{timestamp}_{uuid}.jpg` ## Security Features 1. **User Isolation**: Each user only sees their own detections 2. **File Verification**: System verifies ownership before serving images 3. **Path Validation**: Prevents directory traversal attacks 4. **Session Protection**: All endpoints require user authentication ## Usage Best Practices ### For Security Personnel 1. **Monitor Regularly**: Check the Recent Detections gallery every few minutes 2. **Review Details**: Click detections to understand the threat context 3. **Record Sessions**: Use the "Record" button to save video with detections 4. **Export Evidence**: Download screenshots for incident reports ### For System Administrators 1. **Storage Management**: Monitor disk space (detections folder can grow) 2. **Database Maintenance**: Periodically archive old detection records 3. **Alert Thresholds**: Adjust detection thresholds based on false positive rates 4. **Backup**: Include detection screenshots in regular backups ## Troubleshooting ### Screenshots Not Being Captured 1. **Check**: Ensure detection models are selected and enabled 2. **Check**: Camera is actually running (green indicator should show) 3. **Check**: Directory permissions for `uploads/detections/` 4. **Solution**: Verify all required models are loaded in Model Manager ### Gallery Not Updating 1. **Check**: Browser console for JavaScript errors 2. **Refresh**: Reload the page 3. **Check**: Server is running and `/api/detection-history` endpoint is accessible 4. **Solution**: Clear browser cache and reload ### Images Not Loading 1. **Check**: File exists in `uploads/detections/` 2. **Check**: File permissions allow reading 3. **Check**: User is logged in 4. **Solution**: Restart Flask application ## Performance Considerations - **Screenshot Saving**: ~50-100ms per detection (non-blocking) - **Database Records**: Minimal overhead, indexed by user_id and date - **Storage**: ~500KB per screenshot (1080p JPEG) - **Gallery Load**: ~100ms for 12 thumbnails ## Integration Points ### With Other Features - **Live Stats**: Detection count updates in real-time - **Session Recording**: Screenshots synchronized with video recordings - **Detection Alerts**: Pop-up notifications when threats detected - **Historical Analysis**: All detections indexed by date ## Future Enhancements Possible improvements for future versions: - [ ] Real-time browser notifications on detection - [ ] Email alerts for high-severity detections - [ ] Bulk export of detection reports - [ ] Detection filtering and search - [ ] Advanced analytics and trends - [ ] Configurable screenshot resolution - [ ] Video clip extraction around detections - [ ] ML-based false positive filtering ## Summary The screenshot capture feature automatically documents every detected threat during live monitoring, creating an audit trail of security events. Screenshots are immediately available in the Recent Detections gallery with easy access to detailed information, making incident investigation and reporting quick and reliable. ✅ **Status**: Fully Implemented and Production Ready