# Quartz Inspection Core C++ TensorRT realtime inspection app for the Hikvision camera pipeline.https://marketplace.cursorapi.com/open-vsx-mirror/vscode/asset/openai/chatgpt/26.5506.31421/Microsoft.VisualStudio.Services.Icons.Default?targetPlatform=linux-x64 This folder is intentionally separate from the Python training and prediction code. It contains its own copied `runs/` model artifacts while adding a faster runtime path based on `Geekgineer/YOLOs-CPP-TensorRT`. ## Layout - `src/hik_predict_trt.cpp`: Hikvision camera + YOLO26 segmentation TensorRT runtime. - `config/labels.names`: class names used by the C++ runtime. - `scripts/export_yolo26_seg_onnx.py`: exports `runs/segment/yolo26_tile_seg_v3/weights/best.pt` to ONNX. - `scripts/build_engine.sh`: builds an FP16 TensorRT engine with `trtexec`. - `third_party/YOLOs-CPP-TensorRT`: cloned dependency. ## Prerequisites - NVIDIA driver working (`nvidia-smi` must succeed). - CUDA and TensorRT compatible with `YOLOs-CPP-TensorRT`. - OpenCV C++ development files. - Hikvision MVS SDK at `/opt/MVS`. Current machine note: CUDA 12.2, TensorRT 10.1.0, OpenCV 4.2, and Hikvision MVS SDK were detected. The FP16 TensorRT engine has been built at `models/yolo26_tile_seg_v3_fp16.trt`. ## Build ```bash cd /home/quangtrung/quartz_inspection_core python3 scripts/export_yolo26_seg_onnx.py scripts/build_engine.sh cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CUDA_COMPILER=/usr/local/cuda-12.2/bin/nvcc cmake --build build -j ``` If TensorRT is installed outside common paths, point both engine generation and CMake at it: ```bash TENSORRT_DIR=/path/to/TensorRT scripts/build_engine.sh cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Release \ -DTENSORRT_DIR=/path/to/TensorRT \ -DCMAKE_CUDA_COMPILER=/usr/local/cuda-12.2/bin/nvcc ``` If `trtexec` is elsewhere, use: ```bash TRTEXEC=/path/to/trtexec scripts/build_engine.sh ``` ## Run ```bash ./build/hik_predict_trt \ --engine models/yolo26_tile_seg_v3_fp16.trt \ --labels config/labels.names ``` Useful options: - `--pixel-format mono8|bgr8|bayer_rg8` - `--frame-skip 1` - `--imgsz 864` - `--display-scale 0.3` - `--save-dir captures` Keys: - `ESC` or `q`: exit. - `s`: save current original/result frame. ## Behavior Matched From `hik_predict.py` - Resize camera frame before inference when the max side is larger than `imgsz`. - 4-pass fallback: 1. original frame at `conf=0.175` 2. light CLAHE at `conf=0.30` 3. gamma correction for dark/bright frames at `conf=0.30` 4. strong CLAHE at `conf=0.08`, retaining only `crack` - Single-class filter: - drops class `good` - if multiple defect classes remain, keeps only the class with the highest max confidence - Mask cleanup and overlay drawing similar to `ResultVisualizer`. ## Class Mapping Note `config/labels.names` follows the current `predict.py` mapping: ```text crack, glue_strip, good, gray_stroke, oil, rough ``` `tile_yolo26/data.yaml` currently lists 5 classes. If the trained model really has 5 outputs, update `labels.names` and the class IDs in `src/hik_predict_trt.cpp` to match the exported model before production use.