From: bentoo overlay
Subject: [PATCH] Build against OpenCV 5

digiKam 9.2.0 caps OpenCV at 4.99.0 (https://bugs.kde.org/522887, resolved
UPSTREAM, no port; master unchanged as of 2026-12-02). bentoo ships
media-libs/opencv-5 in the same SLOT as ::gentoo's 4.x, so the cap would
make the package unbuildable there.

- Lift the cap. Face recognition does not work on OpenCV 5 (same bug).
- OpenCV 5 dropped cv::dnn::readNetFromTensorflow and the aesthetic
  detector's NIMA model only ships as a TensorFlow graph, so on OpenCV >= 5
  s_loadModel() reports the detector unavailable and returns false, the
  path upstream already takes when the model file is missing.

The ebuild warns about both in pkg_postinst. Drop once upstream ports to
OpenCV 5.
---
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -19,7 +19,7 @@
 set(KF6_MIN_VERSION                         "6.5.0")        # Qt6 Version compatible.
 set(EXIV2_MIN_VERSION                       "0.27.1")       # Prior version crash frequently.
 set(OPENCV_MIN_VERSION                      "4.8.0")        # Version of the DNN module only suitable with the face recognition.
-set(OPENCV_MAX_VERSION                      "4.99.0")       # Not yet ported to 5.0 and later (See bug #522887).
+set(OPENCV_MAX_VERSION                      "5.99.0")       # bentoo: ships OpenCV 5; face recognition is broken there (bug #522887).
 set(LENSFUN_MIN_VERSION                     "0.2.8.0")      # For Lens auto-correction plugin.
 set(KSANE_MIN_VERSION                       "21.12.0")      # For digital scanner support.
 
--- a/core/libs/imgqsort/detectors/aesthetic_detector.cpp
+++ b/core/libs/imgqsort/detectors/aesthetic_detector.cpp
@@ -147,6 +147,19 @@
         {
             qCDebug(DIGIKAM_DETECTOR_LOG) << "Aesthetic detector model:" << model;
 
+#if CV_VERSION_MAJOR >= 5
+
+            // OpenCV 5 removed the TensorFlow importer, and this model only
+            // ships as a TensorFlow graph (https://bugs.kde.org/522887).
+
+            qCCritical(DIGIKAM_DETECTOR_LOG) << "Aesthetic DNN model needs the TensorFlow importer, removed in OpenCV"
+                                             << CV_VERSION;
+            qCCritical(DIGIKAM_DETECTOR_LOG) << "Aesthetic detection feature cannot be used!";
+
+            return false;
+
+#else
+
 #ifdef Q_OS_WIN
 
             s_model = cv::dnn::readNetFromTensorflow(nnmodel.toLocal8Bit().constData());
@@ -161,6 +174,8 @@
             s_model.enableWinograd(false);
 
             return true;
+
+#endif
         }
         else
         {
