From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Antonio Rojas <arojas@archlinux.org>
Date: Sat, 4 Jul 2026 18:02:56 +0200
Subject: [PATCH] opencv 5

---
 .../gst-plugins-bad/ext/opencv/gstcameracalibrate.cpp    | 1 +
 subprojects/gst-plugins-bad/ext/opencv/gstfaceblur.h     | 2 +-
 subprojects/gst-plugins-bad/ext/opencv/gstfacedetect.h   | 2 +-
 subprojects/gst-plugins-bad/ext/opencv/gsthanddetect.h   | 1 +
 .../gst-plugins-bad/ext/opencv/gstsegmentation.cpp       | 1 +
 .../gst-plugins-bad/gst-libs/gst/opencv/meson.build      | 9 ++++++---
 6 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstcameracalibrate.cpp b/subprojects/gst-plugins-bad/ext/opencv/gstcameracalibrate.cpp
index b24dea09a311..bbabf02d7396 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstcameracalibrate.cpp
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstcameracalibrate.cpp
@@ -85,6 +85,7 @@
 
 #include <opencv2/imgproc.hpp>
 #include <opencv2/calib3d.hpp>
+#include <opencv2/objdetect.hpp>
 
 #include <gst/opencv/gstopencvutils.h>
 
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstfaceblur.h b/subprojects/gst-plugins-bad/ext/opencv/gstfaceblur.h
index 476c35bcc402..aa9ce14216db 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstfaceblur.h
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstfaceblur.h
@@ -51,7 +51,7 @@
 #include <gst/opencv/gstopencvvideofilter.h>
 
 #include <opencv2/core.hpp>
-#include <opencv2/objdetect.hpp>
+#include <opencv2/xobjdetect.hpp>
 
 G_BEGIN_DECLS
 /* #defines don't like whitespacey bits */
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstfacedetect.h b/subprojects/gst-plugins-bad/ext/opencv/gstfacedetect.h
index 27ee7d7854b5..39e8f6131103 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstfacedetect.h
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstfacedetect.h
@@ -51,7 +51,7 @@
 
 #include <gst/gst.h>
 #include <gst/opencv/gstopencvvideofilter.h>
-#include <opencv2/objdetect.hpp>
+#include <opencv2/xobjdetect.hpp>
 
 G_BEGIN_DECLS
 /* #defines don't like whitespacey bits */
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gsthanddetect.h b/subprojects/gst-plugins-bad/ext/opencv/gsthanddetect.h
index 1c414cdb0cd8..edbd90bcc114 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gsthanddetect.h
+++ b/subprojects/gst-plugins-bad/ext/opencv/gsthanddetect.h
@@ -49,6 +49,7 @@
 /* opencv */
 #include <opencv2/core.hpp>
 #include <opencv2/objdetect.hpp>
+#include <opencv2/xobjdetect.hpp>
 
 G_BEGIN_DECLS
 /* #defines don't like whitespacey bits */
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstsegmentation.cpp b/subprojects/gst-plugins-bad/ext/opencv/gstsegmentation.cpp
index 439d14da4eec..efd96c8592ce 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstsegmentation.cpp
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstsegmentation.cpp
@@ -91,6 +91,7 @@
 
 #include "gstsegmentation.h"
 #include <opencv2/imgproc.hpp>
+#include <opencv2/geometry/2d.hpp>
 
 GST_DEBUG_CATEGORY_STATIC (gst_segmentation_debug);
 #define GST_CAT_DEFAULT gst_segmentation_debug
diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/opencv/meson.build b/subprojects/gst-plugins-bad/gst-libs/gst/opencv/meson.build
index 60cb12b652cf..4ddf71f9f823 100644
--- a/subprojects/gst-plugins-bad/gst-libs/gst/opencv/meson.build
+++ b/subprojects/gst-plugins-bad/gst-libs/gst/opencv/meson.build
@@ -32,9 +32,12 @@ libopencv_headers = [
 gstopencv_cargs = []
 opencv_dep = dependency('opencv', version : ['>= 3.0.0', '< 3.5.0'], required : false, include_type: 'system' )
 if not opencv_dep.found()
-  opencv_dep = dependency('opencv4', version : ['>= 4.0.0'], required : opencv_opt, include_type: 'system')
+  opencv_dep = dependency('opencv4', version : ['>= 4.0.0'], required : false, include_type: 'system')
   if not opencv_dep.found()
-    subdir_done()
+    opencv_dep = dependency('opencv5', version : ['>= 5.0.0'], required : opencv_opt, include_type: 'system')
+    if not opencv_dep.found()
+      subdir_done()
+    endif
   endif
 endif
 
@@ -65,7 +68,7 @@ gstopencv_cargs += cxx.get_supported_arguments(['-Wno-missing-include-dirs', '-W
 # Use prefix from pkg-config to be compatible with cross-compilation
 fsmod = import('fs')
 opencv_path_name = ''
-foreach d : ['opencv', 'OpenCV', 'opencv4']
+foreach d : ['opencv', 'OpenCV', 'opencv4', 'opencv5']
   if fsmod.is_dir(opencv_prefix / 'share' / d)
     opencv_path_name = d
     break
