File size: 5,577 Bytes
4ed7d03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Project Structure Guide

## Overview

NETRA is now organized into clear, logical sections for easy maintainability and scalability.

```
NETRA/
β”œβ”€β”€ src/                     Source code
β”‚   β”œβ”€β”€ detectors/          AI detection modules
β”‚   β”œβ”€β”€ pipeline/           Video processing pipeline
β”‚   └── utils/              Utility functions
β”œβ”€β”€ models/                 Trained AI model weights
β”œβ”€β”€ config/                 Configuration files
β”œβ”€β”€ webapp/                 Flask web application
β”œβ”€β”€ docs/                   Documentation
β”œβ”€β”€ tests/                  Unit tests
└── README.md              Main documentation
```

## Directory Details

### `/src` - Source Code

Contains all core application code organized by functionality.

#### `/src/detectors`
All AI detection models wrapped in consistent interfaces:

- **`yolo_detector.py`** - Object detection (people, cars, animals)
  - Uses YOLOv8 from Ultralytics
  - Model: `models/object_detection/yolov8n.pt`

- **`violence_detector.py`** - Violence/fight detection
  - Uses Keras CNN trained on violence data
  - Model: `models/violence_detection/violence_model.h5`

- **`weapon_detector.py`** - Gun/knife detection
  - Uses custom trained YOLO model
  - Models: `models/weapon_detection/best.pt`, `models/object_detection/yolov8n.pt`

- **`pose_detector.py`** - Human pose detection
  - Uses YOLOv11 Pose
  - Model: `models/pose_detection/yolo11n-pose.pt`

- **`anomaly_detector.py`** - Anomalous behavior detection
  - Uses PyTorch anomaly model
  - Model: `models/anomaly_detection/best.bin`

#### `/src/pipeline`
Video input and processing modules:

- **`video_capture.py`** - Camera/RTSP stream capture
  - Motion detection using MOG2
  - ROI extraction for efficient processing

#### `/src/utils`
Helper utilities and common functions (for future expansion)

### `/models` - Trained Model Weights

Organized by detection type:

```
models/
β”œβ”€β”€ object_detection/      YOLO object models
β”œβ”€β”€ violence_detection/    Violence detection models
β”œβ”€β”€ weapon_detection/      Weapon detection models
β”œβ”€β”€ pose_detection/        Pose detection models
└── anomaly_detection/     Anomaly detection models
```

Each folder contains the trained weights ready for inference.

### `/config` - Configuration Files

Centralized configuration management:

- **`settings.py`** - Application-wide settings
  - Flask configuration
  - Database settings
  - File upload parameters
  - Session management

- **`model_config.py`** - Model-specific configuration
  - All model paths (easy updates)
  - Detection thresholds
  - Processing parameters

### `/webapp` - Flask Web Application

The complete web interface:

```
webapp/
β”œβ”€β”€ app.py                 Main Flask application
β”œβ”€β”€ templates/             HTML templates
β”œβ”€β”€ static/               CSS, JavaScript, images
β”œβ”€β”€ uploads/              User uploaded videos
β”œβ”€β”€ processed/            Processed video outputs
└── instance/             SQLite database
```

### `/docs` - Documentation

- **`ARCHITECTURE.md`** - System architecture overview
- **`ANOMALY_DETECTION_GUIDE.md`** - Anomaly detection setup
- **`SETUP.md`** - Installation and setup instructions
- **`API.md`** - API reference

### `/tests` - Unit Tests

Test files for core modules (optional for future):

- `test_detectors.py` - Tests for detector modules
- `test_pipeline.py` - Tests for video pipeline

## Import Examples

### Old Structure (Before)
```python
from NETRA.violence_detector import ViolenceDetector
from NETRA.yolo_detector import YOLODetector
from pose_detection import PoseDetection
```

### New Structure (After)
```python
from src.detectors import ViolenceDetector, YOLODetector, PoseDetection
from src.pipeline import VideoCapture
from config import MODEL_PATHS, DETECTION_THRESHOLDS
```

## File Organization Benefits

βœ… **Clear Separation** - Code organized by functionality
βœ… **Easy Navigation** - Developers know where to find things
βœ… **Scalability** - Easy to add new detectors or features
βœ… **Maintainability** - Configuration centralized
βœ… **Model Management** - All models in one organized place
βœ… **Documentation** - All docs in dedicated folder

## Configuration Usage

### Accessing Model Paths

```python
from config import MODEL_PATHS, get_model_path

# Get specific model path
violence_model = get_model_path('violence')

# Get all available models
from config import get_all_available_models
models = get_all_available_models()
# Output: {'violence': True, 'yolo': True, 'weapon': True, ...}
```

### Accessing Thresholds

```python
from config import DETECTION_THRESHOLDS

yolo_threshold = DETECTION_THRESHOLDS['yolo']  # 0.25
violence_threshold = DETECTION_THRESHOLDS['violence']  # 0.6
```

### Accessing Settings

```python
from config import SECRET_KEY, MAX_CONTENT_LENGTH, UPLOAD_FOLDER

print(f"Max upload: {MAX_CONTENT_LENGTH}")
print(f"Upload location: {UPLOAD_FOLDER}")
```

## Next Steps

1. βœ… New folder structure created
2. βœ… Files reorganized
3. βœ… Configuration centralized
4. πŸ”„ Update imports in `webapp/app.py`
5. πŸ”„ Test all functionality

## Troubleshooting

**"Module not found" errors:**
- Ensure sys.path includes project root
- Check that `__init__.py` files exist in all packages

**Model not loading:**
- Check `config/model_config.py` paths
- Verify model files exist in `models/` directory
- Check file permissions

**Import issues:**
- Run from project root directory
- Ensure Python path includes `src/`