From 5d2f673a814b3d2a5207860f7f21bfed42c65d68 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Thu, 30 Jul 2026 13:07:42 +0200 Subject: [PATCH] build: support OpenCV 5 and TensorRT 10 OpenCV: distros (Arch/CachyOS) now ship OpenCV 5 as default. The config package rejects a 5.x install when find_package requests 4, so probe for 5 first and fall back to 4. All components used here (core, imgproc, imgcodecs, videoio, dnn, objdetect, highgui) exist in both. TensorRT: nvinfer1::Dims5 was removed in TRT 10 (Dims2..Dims4 remain in NvInferLegacyDims.h). Build the TransNetV2 rank-5 input shape via the generic nvinfer1::Dims, which is valid on both 8.x and 10.x. --- CMakeLists.txt | 11 ++++++++++- src/backends/trt_backend.cpp | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee53db7..8a889fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,17 @@ endif() add_subdirectory(external/KPN) # OpenCV (video decode, image ops, DNN inference, face detection) -find_package(OpenCV 4 REQUIRED COMPONENTS +# Accept 4 or 5: the APIs used here are stable across both, and distros have +# begun shipping 5.x as the default (Arch/CachyOS). find_package's version +# argument is a minimum, but OpenCV's config rejects a 5.x install when 4 is +# requested, so probe for 5 first and fall back to 4. +find_package(OpenCV 5 QUIET COMPONENTS core imgproc imgcodecs videoio dnn objdetect highgui) +if(NOT OpenCV_FOUND) + find_package(OpenCV 4 REQUIRED COMPONENTS + core imgproc imgcodecs videoio dnn objdetect highgui) +endif() +message(STATUS "OpenCV: ${OpenCV_VERSION}") # ── Model paths ─────────────────────────────────────────────────────────────── # Defined early so the backend object libraries below can embed it. diff --git a/src/backends/trt_backend.cpp b/src/backends/trt_backend.cpp index b6e8459..4850ad0 100644 --- a/src/backends/trt_backend.cpp +++ b/src/backends/trt_backend.cpp @@ -511,8 +511,17 @@ public: } std::lock_guard lk(mu_); - context_->setInputShape(input_name_.c_str(), - nvinfer1::Dims5{1, kWindow, kFrameH, kFrameW, 3}); + // TensorRT 10 removed the fixed-rank Dims5 helper (Dims2..Dims4 remain + // in NvInferLegacyDims.h). Build the rank-5 shape via the generic Dims, + // which works on both 8.x and 10.x. + nvinfer1::Dims shape{}; + shape.nbDims = 5; + shape.d[0] = 1; + shape.d[1] = kWindow; + shape.d[2] = kFrameH; + shape.d[3] = kFrameW; + shape.d[4] = 3; + context_->setInputShape(input_name_.c_str(), shape); check_cuda(cudaMemcpyAsync(d_input_, buf.data(), buf.size() * 4, cudaMemcpyHostToDevice, stream_), "H2D input");