nedo-vision-worker-core 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nedo-vision-worker-core might be problematic. Click here for more details.
- nedo_vision_worker_core-0.3.0/MANIFEST.in +4 -0
- nedo_vision_worker_core-0.3.0/PKG-INFO +444 -0
- nedo_vision_worker_core-0.3.0/README.md +393 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/__init__.py +58 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/ai/FrameDrawer.py +144 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/ai/ImageDebugger.py +126 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/ai/VideoDebugger.py +69 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/ai/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/callbacks/DetectionCallbackManager.py +306 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/callbacks/DetectionCallbackTypes.py +150 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/callbacks/__init__.py +27 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/cli.py +239 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/config/ConfigurationManager.py +173 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/config/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/core_service.py +303 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/database/DatabaseManager.py +236 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/database/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/BaseDetector.py +23 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/DetectionManager.py +83 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/RFDETRDetector.py +80 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/YOLODetector.py +70 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/detection_processing/DetectionProcessor.py +29 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/detection_processing/HumanDetectionProcessor.py +101 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/detection_processing/PPEDetectionProcessor.py +207 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/detection/detection_processing/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/doctor.py +342 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/blue/inner_corner.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/blue/inner_frame.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/blue/line.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/blue/top_left.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/blue/top_right.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/red/inner_corner.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/red/inner_frame.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/red/line.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/red/top_left.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/drawing_assets/red/top_right.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/boots-green.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/boots-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/gloves-green.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/gloves-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/goggles-green.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/goggles-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/helmet-green.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/helmet-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/mask-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/vest-green.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/icons/vest-red.png +0 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/__init__.py +20 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/ai_model.py +62 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/auth.py +14 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/config.py +9 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/dataset_source.py +30 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/logs.py +9 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/ppe_detection.py +39 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/ppe_detection_label.py +20 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/restricted_area_violation.py +20 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/user.py +10 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/worker_source.py +19 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/worker_source_pipeline.py +21 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/worker_source_pipeline_config.py +24 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/worker_source_pipeline_debug.py +15 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/models/worker_source_pipeline_detection.py +14 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/PipelineConfigManager.py +32 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/PipelineManager.py +133 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/PipelinePrepocessor.py +40 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/PipelineProcessor.py +381 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/PipelineSyncThread.py +234 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/pipeline/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/preprocessing/ImageResizer.py +42 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/preprocessing/ImageRoi.py +61 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/preprocessing/Preprocessor.py +16 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/preprocessing/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/AIModelRepository.py +31 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/PPEDetectionRepository.py +149 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/RestrictedAreaRepository.py +94 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/WorkerSourcePipelineDebugRepository.py +81 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/WorkerSourcePipelineDetectionRepository.py +71 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/WorkerSourcePipelineRepository.py +79 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/WorkerSourceRepository.py +19 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/repositories/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/services/SharedVideoStreamServer.py +276 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/services/VideoSharingDaemon.py +808 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/services/VideoSharingDaemonManager.py +257 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/RTMPStreamer.py +146 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/SharedVideoDeviceManager.py +383 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/StreamSyncThread.py +80 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/VideoStream.py +286 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/VideoStreamManager.py +273 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/streams/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/tracker/SFSORT.py +325 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/tracker/TrackerManager.py +157 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/tracker/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/BoundingBoxMetrics.py +53 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/DrawingUtils.py +354 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/ModelReadinessChecker.py +188 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/PersonAttributeMatcher.py +70 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/PersonRestrictedAreaMatcher.py +45 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/TablePrinter.py +28 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core/util/__init__.py +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/PKG-INFO +444 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/SOURCES.txt +108 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/dependency_links.txt +1 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/entry_points.txt +2 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/requires.txt +20 -0
- nedo_vision_worker_core-0.3.0/nedo_vision_worker_core.egg-info/top_level.txt +1 -0
- nedo_vision_worker_core-0.3.0/pyproject.toml +149 -0
- nedo_vision_worker_core-0.3.0/requirements.txt +12 -0
- nedo_vision_worker_core-0.3.0/setup.cfg +4 -0
- nedo_vision_worker_core-0.3.0/setup.py +13 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nedo-vision-worker-core
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Nedo Vision Worker Core Library for AI Vision Processing
|
|
5
|
+
Author-email: Willy Achmat Fauzi <willy.achmat@gmail.com>
|
|
6
|
+
Maintainer-email: Willy Achmat Fauzi <willy.achmat@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://gitlab.com/sindika/research/nedo-vision/nedo-vision-worker-core-v2
|
|
9
|
+
Project-URL: Documentation, https://gitlab.com/sindika/research/nedo-vision/nedo-vision-worker-core-v2/-/blob/main/README.md
|
|
10
|
+
Project-URL: Repository, https://gitlab.com/sindika/research/nedo-vision/nedo-vision-worker-core-v2
|
|
11
|
+
Project-URL: Bug Reports, https://gitlab.com/sindika/research/nedo-vision/nedo-vision-worker-core-v2/-/issues
|
|
12
|
+
Keywords: computer-vision,machine-learning,ai,worker-core,deep-learning,object-detection,neural-networks,video-processing,pytorch,yolo
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: Multimedia :: Video
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: System :: Hardware
|
|
28
|
+
Classifier: Environment :: GPU
|
|
29
|
+
Classifier: Environment :: No Input/Output (Daemon)
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
Requires-Dist: alembic>=1.8.0
|
|
33
|
+
Requires-Dist: numpy>=1.21.0
|
|
34
|
+
Requires-Dist: opencv-python>=4.6.0
|
|
35
|
+
Requires-Dist: pillow>=8.0.0
|
|
36
|
+
Requires-Dist: psutil>=5.9.0
|
|
37
|
+
Requires-Dist: scipy>=1.9.0
|
|
38
|
+
Requires-Dist: shapely>=1.8.0
|
|
39
|
+
Requires-Dist: SQLAlchemy>=1.4.0
|
|
40
|
+
Requires-Dist: torch>=1.9.0
|
|
41
|
+
Requires-Dist: torchvision>=0.10.0
|
|
42
|
+
Requires-Dist: ultralytics>=8.0.0
|
|
43
|
+
Requires-Dist: rfdetr<2.0.0,>=1.2.0
|
|
44
|
+
Provides-Extra: dev
|
|
45
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
48
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
49
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pre-commit>=2.17.0; extra == "dev"
|
|
51
|
+
|
|
52
|
+
# Nedo Vision Worker Core
|
|
53
|
+
|
|
54
|
+
A powerful Python library for AI-powered computer vision processing in the Nedo Vision platform. This library provides real-time video processing, object detection, PPE compliance monitoring, and safety violation detection with an extensible callback system.
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- **Real-time AI Detection**: Advanced PPE and safety compliance detection
|
|
59
|
+
- **Multi-stream Processing**: Handle multiple video sources simultaneously
|
|
60
|
+
- **Extensible Callbacks**: Event-driven architecture for detection handling
|
|
61
|
+
- **System Diagnostics**: Built-in health checking and troubleshooting
|
|
62
|
+
- **Database Integration**: Persistent storage for detections and configurations
|
|
63
|
+
- **Drawing Utilities**: Rich visualization tools for detections
|
|
64
|
+
- **GPU Acceleration**: CUDA support for optimal performance
|
|
65
|
+
- **RTMP Streaming**: Real-time video streaming capabilities
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
### Basic Installation
|
|
70
|
+
|
|
71
|
+
Install the package from PyPI:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install nedo-vision-worker-core
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Installation with RF-DETR Support
|
|
78
|
+
|
|
79
|
+
RF-DETR is an optional dependency for advanced object detection. Install it separately:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Install the main package
|
|
83
|
+
pip install nedo-vision-worker-core
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### GPU Support
|
|
87
|
+
|
|
88
|
+
For GPU support with CUDA 12.1:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install nedo-vision-worker-core --extra-index-url https://download.pytorch.org/whl/cu121
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Development Installation
|
|
95
|
+
|
|
96
|
+
For development with all tools:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install nedo-vision-worker-core[dev]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Quick Start
|
|
103
|
+
|
|
104
|
+
### Using the CLI
|
|
105
|
+
|
|
106
|
+
After installation, you can use the worker core CLI:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Show CLI help
|
|
110
|
+
nedo-worker-core --help
|
|
111
|
+
|
|
112
|
+
# Run with default settings
|
|
113
|
+
nedo-worker-core run
|
|
114
|
+
|
|
115
|
+
# Run with custom configuration
|
|
116
|
+
nedo-worker-core run --log-level DEBUG --storage-path /data
|
|
117
|
+
|
|
118
|
+
# System health check
|
|
119
|
+
nedo-worker-core doctor
|
|
120
|
+
|
|
121
|
+
# Run with custom server configuration
|
|
122
|
+
nedo-worker-core run --storage-path /custom/storage --rtmp-server rtmp://server.com:1935/live
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Configuration Options
|
|
126
|
+
|
|
127
|
+
The service supports various configuration options:
|
|
128
|
+
|
|
129
|
+
- `--drawing-assets`: Path to drawing assets directory
|
|
130
|
+
- `--log-level`: Logging level (DEBUG|INFO|WARNING|ERROR)
|
|
131
|
+
- `--storage-path`: Storage path for databases and files
|
|
132
|
+
- `--rtmp-server`: RTMP server URL for video streaming
|
|
133
|
+
|
|
134
|
+
### Detection Callbacks
|
|
135
|
+
|
|
136
|
+
The worker core provides a unified callback system for handling detection events:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from nedo_vision_worker_core import (
|
|
140
|
+
CoreService,
|
|
141
|
+
DetectionType,
|
|
142
|
+
CallbackTrigger,
|
|
143
|
+
DetectionData,
|
|
144
|
+
register_immediate_ppe_callback
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def handle_ppe_detection(detection_data: DetectionData):
|
|
148
|
+
"""Handle PPE detection events."""
|
|
149
|
+
if detection_data.has_violations():
|
|
150
|
+
# Send alert for safety violations
|
|
151
|
+
send_safety_alert(
|
|
152
|
+
person_id=detection_data.person_id,
|
|
153
|
+
violations=[v.label for v in detection_data.get_violations()],
|
|
154
|
+
confidence=detection_data.confidence_score,
|
|
155
|
+
image_path=detection_data.image_path
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Log all detections for compliance tracking
|
|
159
|
+
log_detection_event(detection_data)
|
|
160
|
+
|
|
161
|
+
def handle_area_violation(detection_data: DetectionData):
|
|
162
|
+
"""Handle restricted area violations."""
|
|
163
|
+
# Immediate security response
|
|
164
|
+
trigger_security_alert(
|
|
165
|
+
location=detection_data.pipeline_id,
|
|
166
|
+
person_id=detection_data.person_id,
|
|
167
|
+
timestamp=detection_data.timestamp
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Quick registration
|
|
171
|
+
register_immediate_ppe_callback("safety_monitor", handle_ppe_detection)
|
|
172
|
+
|
|
173
|
+
# Advanced registration
|
|
174
|
+
CoreService.register_callback(
|
|
175
|
+
name="security_monitor",
|
|
176
|
+
callback=handle_area_violation,
|
|
177
|
+
trigger=CallbackTrigger.ON_NEW_DETECTION,
|
|
178
|
+
detection_types=[DetectionType.AREA_VIOLATION]
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# Start processing
|
|
182
|
+
service = CoreService()
|
|
183
|
+
service.run()
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Advanced Usage
|
|
187
|
+
|
|
188
|
+
For interval-based monitoring and complex workflows:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from nedo_vision_worker_core import (
|
|
192
|
+
register_interval_ppe_callback,
|
|
193
|
+
register_immediate_area_callback,
|
|
194
|
+
IntervalMetadata
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
def handle_ongoing_ppe_violations(detection_data: DetectionData):
|
|
198
|
+
"""Handle PPE violations that are currently active (called periodically while violations persist)."""
|
|
199
|
+
metadata = detection_data.get_interval_metadata()
|
|
200
|
+
if metadata:
|
|
201
|
+
# This callback is only triggered when there are active violations
|
|
202
|
+
current_violations = metadata['current_violation_state']
|
|
203
|
+
people_in_violation = metadata['unique_persons_in_violation']
|
|
204
|
+
|
|
205
|
+
# Take action for ongoing violations
|
|
206
|
+
if people_in_violation > 0:
|
|
207
|
+
# Escalate persistent violations
|
|
208
|
+
escalate_safety_violation(
|
|
209
|
+
pipeline_id=detection_data.pipeline_id,
|
|
210
|
+
violation_types=current_violations,
|
|
211
|
+
affected_count=people_in_violation,
|
|
212
|
+
state_time=metadata['state_timestamp']
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# Continue monitoring until violations are resolved
|
|
216
|
+
log_ongoing_violation_state(detection_data, metadata)
|
|
217
|
+
|
|
218
|
+
def emergency_response(detection_data: DetectionData):
|
|
219
|
+
"""Handle immediate area violations."""
|
|
220
|
+
# Trigger immediate emergency protocols
|
|
221
|
+
emergency_alert = {
|
|
222
|
+
'alert_type': 'RESTRICTED_AREA_BREACH',
|
|
223
|
+
'location': detection_data.pipeline_id,
|
|
224
|
+
'person_id': detection_data.person_id,
|
|
225
|
+
'confidence': detection_data.confidence_score,
|
|
226
|
+
'timestamp': detection_data.timestamp,
|
|
227
|
+
'evidence_image': detection_data.image_path
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
# Send to security team
|
|
231
|
+
notify_security_team(emergency_alert)
|
|
232
|
+
|
|
233
|
+
# Log incident for investigation
|
|
234
|
+
log_security_incident(emergency_alert)
|
|
235
|
+
|
|
236
|
+
def handle_ongoing_area_violations(detection_data: DetectionData):
|
|
237
|
+
"""Handle area violations that are currently active (called periodically while violations persist)."""
|
|
238
|
+
metadata = detection_data.get_interval_metadata()
|
|
239
|
+
if metadata:
|
|
240
|
+
# This is called every X seconds while people are still in restricted areas
|
|
241
|
+
active_violations = metadata['total_active_violations']
|
|
242
|
+
|
|
243
|
+
if active_violations > 0:
|
|
244
|
+
# Continuous monitoring for ongoing security breaches
|
|
245
|
+
maintain_security_alert(
|
|
246
|
+
location=detection_data.pipeline_id,
|
|
247
|
+
ongoing_violations=active_violations,
|
|
248
|
+
duration_check=metadata['state_timestamp']
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# Register immediate callbacks (triggered on each new detection)
|
|
252
|
+
register_immediate_area_callback("immediate_security", emergency_response)
|
|
253
|
+
|
|
254
|
+
# Register interval callbacks (triggered periodically ONLY when violations are currently active)
|
|
255
|
+
register_interval_ppe_callback("ongoing_ppe_monitor", handle_ongoing_ppe_violations, interval_seconds=30)
|
|
256
|
+
register_interval_area_callback("ongoing_area_monitor", handle_ongoing_area_violations, interval_seconds=15)
|
|
257
|
+
|
|
258
|
+
# Monitor multiple detection types with custom logic
|
|
259
|
+
def safety_coordinator(detection_data: DetectionData):
|
|
260
|
+
"""Coordinate safety responses across all detection types."""
|
|
261
|
+
if detection_data.detection_type == DetectionType.PPE_DETECTION:
|
|
262
|
+
handle_ppe_safety(detection_data)
|
|
263
|
+
elif detection_data.detection_type == DetectionType.AREA_VIOLATION:
|
|
264
|
+
handle_security_breach(detection_data)
|
|
265
|
+
|
|
266
|
+
CoreService.register_callback(
|
|
267
|
+
name="safety_coordinator",
|
|
268
|
+
callback=safety_coordinator,
|
|
269
|
+
trigger=CallbackTrigger.ON_NEW_DETECTION,
|
|
270
|
+
detection_types=[DetectionType.PPE_DETECTION, DetectionType.AREA_VIOLATION]
|
|
271
|
+
)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Programmatic Usage
|
|
275
|
+
|
|
276
|
+
You can use the core service programmatically in your applications:
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
from nedo_vision_worker_core import CoreService
|
|
280
|
+
|
|
281
|
+
# Basic usage - start the service with default settings
|
|
282
|
+
service = CoreService()
|
|
283
|
+
service.run()
|
|
284
|
+
|
|
285
|
+
# Custom configuration
|
|
286
|
+
service = CoreService(
|
|
287
|
+
log_level="INFO",
|
|
288
|
+
storage_path="./data"
|
|
289
|
+
)
|
|
290
|
+
service.run()
|
|
291
|
+
|
|
292
|
+
# With error handling
|
|
293
|
+
try:
|
|
294
|
+
service = CoreService(log_level="DEBUG")
|
|
295
|
+
service.run()
|
|
296
|
+
except KeyboardInterrupt:
|
|
297
|
+
print("Service stopped")
|
|
298
|
+
except Exception as e:
|
|
299
|
+
print(f"Error: {e}")
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Architecture
|
|
303
|
+
|
|
304
|
+
### Core Components
|
|
305
|
+
|
|
306
|
+
- **CoreService**: Main service orchestrator with callback management
|
|
307
|
+
- **Detection Pipeline**: AI model processing with PyTorch backend
|
|
308
|
+
- **Callback System**: Unified event handling with immediate and interval triggers
|
|
309
|
+
- **Resource Monitor**: System resource monitoring (GPU, CPU, memory)
|
|
310
|
+
- **Database Manager**: Persistent storage for detections and configurations
|
|
311
|
+
|
|
312
|
+
### Callback System
|
|
313
|
+
|
|
314
|
+
#### Trigger Types
|
|
315
|
+
|
|
316
|
+
- **`ON_NEW_DETECTION`**: Triggered immediately on each detection
|
|
317
|
+
- **`ON_VIOLATION_INTERVAL`**: Triggered periodically only when violations occur in the interval
|
|
318
|
+
|
|
319
|
+
#### Detection Types
|
|
320
|
+
|
|
321
|
+
- **`PPE_DETECTION`**: Personal Protective Equipment compliance
|
|
322
|
+
- **`AREA_VIOLATION`**: Restricted area violations
|
|
323
|
+
- **`GENERAL_DETECTION`**: All detection events
|
|
324
|
+
|
|
325
|
+
#### Data Structure
|
|
326
|
+
|
|
327
|
+
```python
|
|
328
|
+
class DetectionData:
|
|
329
|
+
detection_id: str
|
|
330
|
+
person_id: str
|
|
331
|
+
pipeline_id: str
|
|
332
|
+
detection_type: DetectionType
|
|
333
|
+
confidence_score: float
|
|
334
|
+
timestamp: datetime
|
|
335
|
+
image_path: str
|
|
336
|
+
metadata: dict
|
|
337
|
+
|
|
338
|
+
def get_violations(self) -> List[DetectionAttribute]
|
|
339
|
+
def get_compliance(self) -> List[DetectionAttribute]
|
|
340
|
+
def has_violations(self) -> bool
|
|
341
|
+
def get_interval_metadata(self) -> Optional[IntervalMetadata]
|
|
342
|
+
|
|
343
|
+
class IntervalMetadata(TypedDict):
|
|
344
|
+
state_timestamp: str # ISO format datetime of current state
|
|
345
|
+
total_active_violations: int # Current number of active violations
|
|
346
|
+
unique_persons_in_violation: int # Number of people currently in violation
|
|
347
|
+
current_violation_state: Dict[str, int] # Current violation types and counts
|
|
348
|
+
violation_summary: Dict[str, int] # violation_type -> count (deprecated, use current_violation_state)
|
|
349
|
+
total_violations: int # total violations in interval (deprecated, use total_active_violations)
|
|
350
|
+
violation_count_in_interval: int # violations in this specific interval
|
|
351
|
+
interval_start: str # ISO format datetime
|
|
352
|
+
interval_end: str # ISO format datetime
|
|
353
|
+
unique_persons: int # total unique persons in interval
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
#### API Methods
|
|
357
|
+
|
|
358
|
+
```python
|
|
359
|
+
# Core callback registration methods
|
|
360
|
+
CoreService.register_callback(name, callback, trigger, detection_types, interval_seconds)
|
|
361
|
+
CoreService.unregister_callback(name)
|
|
362
|
+
CoreService.list_callbacks()
|
|
363
|
+
|
|
364
|
+
# Convenience functions for common use cases
|
|
365
|
+
register_immediate_ppe_callback(name, callback)
|
|
366
|
+
register_immediate_area_callback(name, callback)
|
|
367
|
+
register_interval_ppe_callback(name, callback, interval_seconds)
|
|
368
|
+
register_interval_area_callback(name, callback, interval_seconds)
|
|
369
|
+
|
|
370
|
+
# Example: Managing callbacks programmatically
|
|
371
|
+
def setup_safety_monitoring():
|
|
372
|
+
"""Setup comprehensive safety monitoring system."""
|
|
373
|
+
|
|
374
|
+
# Register immediate response callbacks
|
|
375
|
+
register_immediate_ppe_callback("ppe_safety", handle_ppe_violations)
|
|
376
|
+
register_immediate_area_callback("area_security", handle_area_breaches)
|
|
377
|
+
|
|
378
|
+
# Register periodic reporting
|
|
379
|
+
register_interval_ppe_callback("hourly_report", generate_hourly_report, interval_seconds=3600)
|
|
380
|
+
|
|
381
|
+
# Verify registration
|
|
382
|
+
active_callbacks = CoreService.list_callbacks()
|
|
383
|
+
logging.info(f"Active monitoring: {len(active_callbacks)} callbacks registered")
|
|
384
|
+
|
|
385
|
+
return active_callbacks
|
|
386
|
+
|
|
387
|
+
# Cleanup callbacks when needed
|
|
388
|
+
def cleanup_monitoring():
|
|
389
|
+
"""Remove specific callbacks."""
|
|
390
|
+
CoreService.unregister_callback("ppe_safety")
|
|
391
|
+
CoreService.unregister_callback("area_security")
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Dependencies
|
|
395
|
+
|
|
396
|
+
The service relies on several key technologies:
|
|
397
|
+
|
|
398
|
+
- **PyTorch**: Deep learning framework with CUDA support
|
|
399
|
+
- **OpenCV**: Computer vision and video processing
|
|
400
|
+
- **SQLAlchemy**: Database ORM and management
|
|
401
|
+
- **FFmpeg**: Video streaming and processing
|
|
402
|
+
- **Ultralytics**: YOLO model implementations
|
|
403
|
+
|
|
404
|
+
## Development Setup
|
|
405
|
+
|
|
406
|
+
For development and testing:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# Clone and setup development environment
|
|
410
|
+
git clone <repository-url>
|
|
411
|
+
cd nedo-vision-worker-core-v2
|
|
412
|
+
|
|
413
|
+
# Create virtual environment
|
|
414
|
+
python -m venv .venv
|
|
415
|
+
source .venv/bin/activate # Linux/Mac
|
|
416
|
+
# or
|
|
417
|
+
.venv\Scripts\activate # Windows
|
|
418
|
+
|
|
419
|
+
# Install in development mode
|
|
420
|
+
pip install -e .
|
|
421
|
+
|
|
422
|
+
# Run tests
|
|
423
|
+
python test.py
|
|
424
|
+
|
|
425
|
+
# Check system health
|
|
426
|
+
nedo-worker-core doctor
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Troubleshooting
|
|
430
|
+
|
|
431
|
+
### Common Issues
|
|
432
|
+
|
|
433
|
+
1. **CUDA not detected**: Ensure NVIDIA drivers and CUDA toolkit are installed
|
|
434
|
+
2. **FFmpeg not found**: Install FFmpeg for video processing capabilities
|
|
435
|
+
3. **Permission errors**: Check storage directory permissions
|
|
436
|
+
4. **Model loading issues**: Verify model files and network connectivity
|
|
437
|
+
|
|
438
|
+
### Support
|
|
439
|
+
|
|
440
|
+
For issues and questions:
|
|
441
|
+
|
|
442
|
+
- Check the logs for detailed error information
|
|
443
|
+
- Run `nedo-worker-core doctor` for system diagnostics
|
|
444
|
+
- Verify all dependencies are properly installed
|