# CodeProject.AI Server — Intégration Heimdall **Version :** 2.9.5 | **Repo :** [codeproject/CodeProject.AI-Server](https://github.com/codeproject/CodeProject.AI-Server) | **License :** SSPL --- ## 1. Présentation CodeProject.AI Server est un microservice IA **auto-hébergé, gratuit et open-source**. Il expose une API REST qui permet d'envoyer des images (snapshots) et de recevoir des résultats de détection : objets, visages, plaques, scènes, etc. ## 2. Modules disponibles ### Computer Vision (utilisés par Heimdall) | Module | Version | Description | Backend | GPU | |---|---|---|---|---| | **Object Detection (YOLOv8)** | 1.6.2 | Détection 80 classes COCO | Python, PyTorch | NVIDIA CUDA | | **Object Detection (YOLOv5 .NET)** | 1.14.0 | Détection objets (ONNX + DirectML) | C#, ONNX | DirectML (Windows) | | **Object Detection (YOLOv5 6.2)** | 1.10.0 | Détection objets (PyTorch) | Python, PyTorch | NVIDIA CUDA 11.5+ | | **Object Detection (Coral)** | 2.4.0 | Détection avec accélérateur Coral TPU | Python, TFLite | Coral TPU | | **License Plate Reader** | 3.3.3 | Lecture plaques (ALPR) mono/multi-ligne | Python, PaddleOCR | NVIDIA CUDA | | **Face Processing** | 1.12.3 | Détection, reconnaissance, comparaison visages | Python, PyTorch | NVIDIA CUDA | | **Scene Classification** | 1.8.0 | Classification 365 scènes | Python, PyTorch | NVIDIA CUDA | | **Optical Character Recognition** | 2.2.3 | OCR général (PaddleOCR) | Python, PaddlePaddle | NVIDIA CUDA | ### Modules utiles (non utilisés directement par Heimdall) | Module | Description | |---|---| | **Background Remover** | Supprime l'arrière-plan d'une image | | **Super Resolution** | Augmente la résolution d'une image par IA | | **Portrait Filter** | Effet bokeh (profondeur de champ) | | **Cartoonizer** | Transforme une photo en style anime | | **Sound Classifier** | Classifie les sons (UrbanSound8K) | | **Sentiment Analysis** | Analyse de sentiment d'un texte | | **Text Summary** | Résumé automatique de texte | | **LlamaChat** | LLM local (chat) | | **MultiModeLLM** | LLM multimodal (texte + image) | | **Text to Image** | Génération d'image par texte (Stable Diffusion) | --- ## 3. API REST — Endpoints utilisés par Heimdall Base URL : `http://codeproject-ai:32168` ### 3.1 Object Detection — `/v1/vision/detection` ```http POST http://codeproject-ai:32168/v1/vision/detection Content-Type: multipart/form-data image: min_confidence: 0.4 ``` Réponse : ```json { "success": true, "predictions": [ { "x_min": 100, "x_max": 200, "y_min": 50, "y_max": 200, "confidence": 0.95, "label": "person" }, { "x_min": 300, "x_max": 400, "y_min": 100, "y_max": 180, "confidence": 0.87, "label": "car" } ], "count": 2, "inferenceMs": 45, "processMs": 120 } ``` **Classes COCO détectables** (80) — les plus pertinentes pour Heimdall : ``` person, bicycle, car, motorcycle, bus, truck, train, boat cat, dog, horse, sheep, cow, bear, deer backpack, umbrella, handbag, suitcase, sports ball, bottle chair, sofa, bench, potted plant, dining table, tv monitor, laptop ``` ### 3.2 Custom Object Detection — `/v1/vision/custom/{model-name}` Modèles personnalisés disponibles par défaut : | Model | Classes détectées | |---|---| | `ipcam-animal` | bird, cat, dog, horse, sheep, cow, bear, deer, rabbit, raccoon, fox, skunk, squirrel, pig | | `ipcam-dark` | bicycle, bus, car, cat, dog, motorcycle, person | | `ipcam-general` | person, vehicle + ipcam-dark | | `ipcam-combined` | person, bicycle, car, motorcycle, bus, truck, bird, cat, dog, horse, sheep, cow, bear, deer, rabbit, raccoon, fox, skunk, squirrel, pig | ```http POST http://codeproject-ai:32168/v1/vision/custom/ipcam-general ``` Lister les modèles disponibles : ```http POST http://codeproject-ai:32168/v1/vision/custom/list ``` ### 3.3 License Plate Reader (ALPR) — `/v1/vision/alpr` ```http POST http://codeproject-ai:32168/v1/vision/alpr Content-Type: multipart/form-data upload: ``` Réponse : ```json { "success": true, "predictions": [ { "x_min": 100, "x_max": 250, "y_min": 200, "y_max": 240, "label": "AA-123-XX", "confidence": 0.92 } ], "count": 1, "inferenceMs": 180, "processMs": 250 } ``` ### 3.4 Face Detection — `/v1/vision/face` ```http POST http://codeproject-ai:32168/v1/vision/face Content-Type: multipart/form-data image: min_confidence: 0.5 ``` ### 3.5 Face Recognition — `/v1/vision/face/recognize` Nécessite d'avoir enregistré des visages au préalable. ```http POST http://codeproject-ai:32168/v1/vision/face/recognize Content-Type: multipart/form-data image: min_confidence: 0.5 ``` Réponse : ```json { "success": true, "predictions": [ { "x_min": 100, "x_max": 200, "y_min": 50, "y_max": 200, "confidence": 0.91, "label": "Jean Dupont", "userid": "user_123" } ] } ``` ### 3.6 Register Face — `/v1/vision/face/register` ```http POST http://codeproject-ai:32168/v1/vision/face/register Content-Type: multipart/form-data image: userid: "user_123" username: "Jean Dupont" ``` ### 3.7 Scene Classification — `/v1/vision/scene` 365 scènes disponibles (conference_room, parking, kitchen, forest...). ```http POST http://codeproject-ai:32168/v1/vision/scene Content-Type: multipart/form-data image: ``` ### 3.8 Health Check ```http GET http://codeproject-ai:32168/v1/status/ping → { "success": true, "message": "pong" } ``` --- ## 4. — Pipeline Heimdall → CodeProject.AI ```text Agent envoie snapshot (toutes les 200ms) │ ▼ Pré-détection CPU (YOLOv8 nano) │ ├─ Rien détecté → ignore │ └─ Personne/Véhicule/Animal → envoie snapshot au Central │ ▼ Heimdall API → POST /v1/vision/detection ──────────────────────────────────────────── │ │ │ ▼ ▼ ▼ CodeProject.AI CodeProject.AI CodeProject.AI Object Detection ALPR (si plaque Face Rec (si (YOLOv5/v8) activée + véhicule) visage + activée) │ │ │ └────────────────────┴──────────────────────┘ │ ▼ Création événement + Notification (Hangfire) ``` ### Filtrage par DetectionProfile Avant d'appeler CodeProject.AI, l'API vérifie le profil de détection de la caméra : ```csharp // Heimdall.Api → AiController.cs [HttpPost("detect/{cameraId}")] public async Task DetectAsync(Guid cameraId, IFormFile snapshot) { var profile = await _db.CameraDetectionProfiles .FirstOrDefaultAsync(p => p.CameraId == cameraId); var tasks = new List(); // Object detection (toujours si au moins un objet activé) if (profile.DetectPerson || profile.DetectVehicle || profile.DetectAnimal) { tasks.Add(CallObjectDetectionAsync(snapshot, profile)); } // License plate (uniquement si véhicule activé) if (profile.DetectVehicle && profile.LicensePlateRecognition) { tasks.Add(CallAlprAsync(snapshot)); } // Face recognition (uniquement si personne activée) if (profile.DetectPerson && profile.FaceRecognition) { tasks.Add(CallFaceRecognitionAsync(snapshot)); } await Task.WhenAll(tasks); // ... } ``` --- ## 5. Docker — Configuration ```yaml services: codeproject-ai: image: codeproject/ai-server:2.9.5 ports: - "32168:32168" volumes: - codeproject_ai_modules:/app/modules - codeproject_ai_models:/app/../../../models # modèles pré-téléchargés environment: - CPAI_LAUNCHER_GPU=GPU # auto-détection, ou CPU pour CPU only deploy: resources: reservations: devices: - driver: nvidia count: all capabilities: [gpu] restart: unless-stopped volumes: codeproject_ai_modules: codeproject_ai_models: ``` ### Variables d'environnement | Variable | Valeur | Description | |---|---|---| | `CPAI_LAUNCHER_GPU` | `GPU` (défaut) ou `CPU` | Forcer CPU si pas de GPU | | `CPAI_PORT` | `32168` | Port du serveur | | `CPAI_MODULE_OBJECTDETECTION` | `true` / `false` | Activer/désactiver module | | `CPAI_MODULE_ALPR` | `true` / `false` | Activer/désactiver ALPR | | `CPAI_MODULE_FACE` | `true` / `false` | Activer/désactiver Face | --- ## 6. Performances ### Temps d'inférence moyens (CodeProject.AI v2.9.5) | Module | GPU (RTX 3060) | CPU (i5-10gen) | Raspberry Pi 4 | |---|---|---|---| | Object Detection YOLOv8 | 25-50ms | 150-300ms | 800-1500ms | | Object Detection YOLOv5 .NET (DirectML) | 30-60ms | 200-400ms | — | | License Plate Reader | 150-250ms | 500-1000ms | 3000-5000ms | | Face Detection | 20-40ms | 100-200ms | 500-1000ms | | Face Recognition (1 visage) | 30-50ms | 200-400ms | — | | Scene Classification | 15-30ms | 80-150ms | — | ### Impact sur le pipeline Heimdall (1080p, GPU) | Étape | Durée | Cumulative | |---|---|---| | Capture snapshot FFmpeg | ~50ms | 50ms | | Pré-détection YOLOv8 nano (Agent CPU) | ~30ms | 80ms | | Envoi HTTPS snapshot au Central | ~20ms | 100ms | | **CodeProject.AI Object Detection** | **~40ms** | **140ms** | | **CodeProject.AI ALPR** (si véhicule) | **~200ms** | **340ms** | | **CodeProject.AI Face Rec** (si personne) | **~40ms** | **180ms** | | Sauvegarde événement DB | ~15ms | 195ms | | Notification (Hangfire) | ~5ms | 200ms | **Total avec GPU : ~200-350ms par snapshot traité.** Intervalle snapshot par défaut : 200ms → pas de backlog. --- ## 7. Gestion des modèles Les modèles sont téléchargés automatiquement par CodeProject.AI au premier démarrage. Ils sont stockés dans les volumes Docker : ``` /usr/share/codeproject.ai/modules/ ├── ObjectDetectionYOLOv8/ │ ├── assets/ │ │ └── yolov8m.onnx # ~40 Mo │ └── models/ ├── ALPR/ │ ├── assets/ │ └── models/ └── FaceProcessing/ └── assets/ ``` ### Modèles personnalisés (ipcam-*) Heimdall peut utiliser les modèles personnalisés `ipcam-general`, `ipcam-animal`, `ipcam-dark`, `ipcam-combined` déjà inclus dans CodeProject.AI. Ces modèles sont optimisés pour la vidéosurveillance (meilleure détection des animaux, sombre, etc.). --- ## 8. Déploiement multi-instances (Mesh) CodeProject.AI supporte le **Mesh** : plusieurs instances peuvent être chaînées pour répartir la charge : ```text Heimdall Central → CodeProject.AI (GPU principal) │ ▼ CodeProject.AI (GPU secondaire) → ALPR │ ▼ CodeProject.AI (CPU) → Face Recognition ``` Non requis pour Heimdall v1, mais disponible pour montée en charge. --- ## 9. Tests d'intégration ``` CodeProject.AI responds to ping at /v1/status/ping Object detection returns predictions from snapshot Object detection with min_confidence=0.9 returns fewer results ALPR reads license plate from vehicle snapshot Face detection finds faces in person snapshot Face recognition matches registered person Scene classification returns label for indoor scene Custom model ipcam-general detects person in dark image Custom model ipcam-animal detects dog in snapshot Invalid image returns error with success=false Module deselection (CPAI_MODULE_ALPR=false) disables ALPR ```