File size: 8,757 Bytes
cb3c674 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | # 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
|