Commit Graph
8 Commits
Author SHA1 Message Date
Arnaud Dartois 2fe48f0865 feat(agent): implement real YOLO/ONNX inference in FrameAnalyzerService (#148)
## What
Replace the stub `FrameAnalyzerService.RunInference` (returning `[]`) with a real ONNX Runtime inference pipeline for YOLOv8 object detection.

## Why
The entire detection chain was non-functional — `FrameAnalyzerService` returned empty results, `Microsoft.ML.OnnxRuntime` was not referenced, and no object detection was produced. This is the core AI feature of the Heimdall platform (issue #2, etape-3).

## How
- **Packages**: Added `Microsoft.ML.OnnxRuntime` 1.22.0 and `SixLabors.ImageSharp` 4.1.0 to `Heimdall.Agent.csproj`
- **ONNX session**: `InferenceSession` loaded in constructor with graceful fallback to passthrough mode when model is absent
- **Preprocessing**: JPEG → ImageSharp `Image<Rgb24>` → resize 640×640 → NCHW tensor normalized [0,1]
- **Inference**: ONNX Runtime `Session.Run()` with the preprocessed tensor
- **Post-processing**: YOLOv8 output parsing (`[1, 4+C, 8400]` tensor → bounding boxes + class scores) with class-aware Non-Maximum Suppression (IoU threshold 0.45, confidence threshold 0.25)
- **Tests**: 13 new unit tests for NMS logic, output parsing, bounding box conversion, and COCO class mapping (206 Agent tests total, all green)

## Testing
- `dotnet build` — 0 errors (TreatWarningsAsErrors=true)
- `dotnet test --filter "FullyQualifiedName!~E2E"` — 1282 passed, 0 failed
- E2E failures are pre-existing (Playwright/Chromium not installed on this runner)

## Notes
- Model path configurable via `MODEL_PATH` env var (default: `models/yolov8m.onnx`)
- Passthrough mode preserved when model file is absent — no crash
- Thread-safe: `InferenceSession.Run()` is thread-safe; session created once in constructor

Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/148
2026-08-19 23:06:06 +02:00
Arnaud Dartois c38d69a1e5 feat(agent): pipeline capture vidéo — FFmpeg par caméra, snapshots adaptatifs, frames → analyseur (Fixes #1)
- CameraStreamService enregistré dans le DI + hosted SnapshotPipelineService
  qui synchronise les captures avec les caméras assignées (Central = source de
  vérité via clés camera.<id>.* dans la config agent ; fallback local Agent:Cameras)
- Découpage du flux MJPEG en frames JPEG (JpegFrameSplitter, marqueurs SOI/EOI)
- Intervalle adaptatif (spec Phase 15) : scène vide 1000ms / mouvement 500ms /
  objet détecté 200ms, doublé si CPU > 80% ; état de scène piloté par les
  résultats de l'analyseur + proxy de mouvement (FrameMotionDetector, pixel diff
  réel en Phase 16)
- Channel borné 100 snapshots (DropOldest) — backpressure + compteur de drops
  et log rate-limité (alerte admin via remontée des logs agent)
- Frames réellement transmises à FrameAnalyzerService (compteur AnalyzedFrameCount)
- Central : GET /api/settings/agent/{id} embarque les caméras assignées
  (name/rtsp/sub_rtsp/enabled) ; ConfigReceiverService les applique à chaud
- Tests : JpegFrameSplitter, intervalle adaptatif, tracker de scène, motion
  detector, CameraConfigStore, pipeline (snapshot → analyseur), handler config
2026-08-11 21:16:28 +02:00
Arnaud Dartois 262adc07cf test(agent): add service tests for CameraStream, ConfigReceiver, FrameAnalyzer, SystemMetrics, DTOs 2026-07-23 15:37:20 +00:00
Arnaud Dartois 363b43f779 fix: prevent orphaned TaskCompletionSource in frame queue
Changed BoundedChannelFullMode from DropOldest to DropWrite.
With DropOldest, the oldest queued job is silently removed when the
channel is full, but its TaskCompletionSource is never completed —
causing the caller to hang indefinitely.

DropWrite rejects new writes when full, returning TryWrite=false,
which triggers the existing graceful fallback (tcs.TrySetResult(null)).
2026-07-19 15:54:46 +00:00
Arnaud Dartois d9f5224e21 fix: resolve review findings — SignalR JWT, enum serialization, TCS leak, thread safety 2026-07-19 15:54:13 +00:00
Arnaud Dartois 70176124cb refactor(css): merge duplicate dark mode media blocks into one
- Single @media (prefers-color-scheme: dark) block containing both
  auth-specific rules and general (body, blazor-error-ui) rules
- Removes duplicate @media query, simplifies maintenance
2026-07-19 15:49:46 +00:00
Arnaud Dartois 255c3f6260 fix: resolve CA1822 and CA1859 in FrameAnalyzerService 2026-07-19 15:30:51 +00:00
Arnaud Dartois 488996a760 fix: add missing System.Threading.Channels import in FrameAnalyzerService 2026-07-19 15:30:08 +00:00