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
Detection Occurs: When any of the above conditions are met during live camera streaming
Screenshot Captured: The current frame is saved as a JPEG image
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
File Storage:
- Files are stored in:
uploads/detections/ - Filename format:
detection_{type}_{timestamp}_{unique_id}.jpg - Example:
detection_violence_20250503_143022_a7f2b1c3.jpg
- Files are stored in:
Viewing Captured Screenshots
In Live Camera Dashboard
- Start the Live Camera monitoring
- Select detection models (Weapon, Violence, Anomaly, Pose, etc.)
- Click "Start Camera"
- Once unusual activity is detected, screenshots appear in the "Recent Detections" gallery
- 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:
{
"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)
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
- User Isolation: Each user only sees their own detections
- File Verification: System verifies ownership before serving images
- Path Validation: Prevents directory traversal attacks
- Session Protection: All endpoints require user authentication
Usage Best Practices
For Security Personnel
- Monitor Regularly: Check the Recent Detections gallery every few minutes
- Review Details: Click detections to understand the threat context
- Record Sessions: Use the "Record" button to save video with detections
- Export Evidence: Download screenshots for incident reports
For System Administrators
- Storage Management: Monitor disk space (detections folder can grow)
- Database Maintenance: Periodically archive old detection records
- Alert Thresholds: Adjust detection thresholds based on false positive rates
- Backup: Include detection screenshots in regular backups
Troubleshooting
Screenshots Not Being Captured
- Check: Ensure detection models are selected and enabled
- Check: Camera is actually running (green indicator should show)
- Check: Directory permissions for
uploads/detections/ - Solution: Verify all required models are loaded in Model Manager
Gallery Not Updating
- Check: Browser console for JavaScript errors
- Refresh: Reload the page
- Check: Server is running and
/api/detection-historyendpoint is accessible - Solution: Clear browser cache and reload
Images Not Loading
- Check: File exists in
uploads/detections/ - Check: File permissions allow reading
- Check: User is logged in
- 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