PKGBUILDs/extra/gstreamer/0004-opencv-Allow-building-against-4.6.x.patch
2022-06-06 18:05:15 +00:00

135 lines
5.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Date: Mon, 6 Jun 2022 00:30:08 +0200
Subject: [PATCH] opencv: Allow building against 4.6.x
Replace the broken version checks with one modeled after
`GLIB_CHECK_VERSION`.
---
.../gst-plugins-bad/ext/opencv/gstcvtracker.cpp | 14 +++++++-------
.../gst-plugins-bad/ext/opencv/gstcvtracker.h | 11 +++++++++--
subprojects/gst-plugins-bad/ext/opencv/meson.build | 2 +-
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.cpp b/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.cpp
index 492c9cf9b877..0c5dfda35f0a 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.cpp
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.cpp
@@ -233,7 +233,7 @@ gst_cvtracker_init (GstCVTracker * filter)
filter->y = DEFAULT_PROP_INITIAL_Y;
filter->width = DEFAULT_PROP_INITIAL_WIDTH;
filter->height = DEFAULT_PROP_INITIAL_HEIGHT;
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->tracker = cv::legacy::upgradeTrackingAPI(
cv::legacy::TrackerMedianFlow::create());
#else
@@ -283,40 +283,40 @@ create_cvtracker (GstCVTracker * filter)
{
switch (filter->algorithm) {
case GST_OPENCV_TRACKER_ALGORITHM_BOOSTING:
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->tracker = cv::legacy::upgradeTrackingAPI(
cv::legacy::TrackerBoosting::create());
#else
filter->tracker = cv::TrackerBoosting::create();
#endif
break;
case GST_OPENCV_TRACKER_ALGORITHM_CSRT:
filter->tracker = cv::TrackerCSRT::create ();
break;
case GST_OPENCV_TRACKER_ALGORITHM_KCF:
filter->tracker = cv::TrackerKCF::create ();
break;
case GST_OPENCV_TRACKER_ALGORITHM_MEDIANFLOW:
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->tracker = cv::legacy::upgradeTrackingAPI(
cv::legacy::TrackerMedianFlow::create());
#else
filter->tracker = cv::TrackerMedianFlow::create();
#endif
break;
case GST_OPENCV_TRACKER_ALGORITHM_MIL:
filter->tracker = cv::TrackerMIL::create ();
break;
case GST_OPENCV_TRACKER_ALGORITHM_MOSSE:
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->tracker = cv::legacy::upgradeTrackingAPI(
cv::legacy::TrackerMOSSE::create());
#else
filter->tracker = cv::TrackerMOSSE::create ();
#endif
break;
case GST_OPENCV_TRACKER_ALGORITHM_TLD:
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->tracker = cv::legacy::upgradeTrackingAPI(
cv::legacy::TrackerTLD::create());
#else
@@ -366,19 +366,19 @@ gst_cvtracker_transform_ip (GstOpencvVideoFilter * base,
GstMessage *msg;
if (filter->roi.empty ()) {
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
filter->roi = new (cv::Rect);
#else
filter->roi = new (cv::Rect2d);
#endif
filter->roi->x = filter->x;
filter->roi->y = filter->y;
filter->roi->width = filter->width;
filter->roi->height = filter->height;
create_cvtracker (filter);
filter->tracker->init (img, *filter->roi);
} else if (filter->tracker->update (img, *filter->roi)) {
-#if (!(CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1))
+#if !GST_OPENCV_CHECK_VERSION(4, 5, 1)
/* Round values to avoid inconsistencies depending on the OpenCV version. */
filter->roi->x = cvRound (filter->roi->x);
filter->roi->y = cvRound (filter->roi->y);
diff --git a/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.h b/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.h
index d3531efbc593..1a06111d8b03 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.h
+++ b/subprojects/gst-plugins-bad/ext/opencv/gstcvtracker.h
@@ -50,7 +50,14 @@
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/tracking.hpp>
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+
+#define GST_OPENCV_CHECK_VERSION(major,minor,revision) \
+ (CV_VERSION_MAJOR > (major) || \
+ (CV_VERSION_MAJOR == (major) && CV_VERSION_MINOR > (minor)) || \
+ (CV_VERSION_MAJOR == (major) && CV_VERSION_MINOR == (minor) && \
+ CV_VERSION_REVISION >= (revision)))
+
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
#include <opencv2/tracking/tracking_legacy.hpp>
#endif
@@ -84,7 +91,7 @@ struct _GstCVTracker
gboolean post_debug_info;
cv::Ptr<cv::Tracker> tracker;
-#if CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 5 && CV_VERSION_REVISION >= 1
+#if GST_OPENCV_CHECK_VERSION(4, 5, 1)
cv::Ptr<cv::Rect> roi;
#else
cv::Ptr<cv::Rect2d> roi;
diff --git a/subprojects/gst-plugins-bad/ext/opencv/meson.build b/subprojects/gst-plugins-bad/ext/opencv/meson.build
index 1d86b9092d9d..3962cff90a55 100644
--- a/subprojects/gst-plugins-bad/ext/opencv/meson.build
+++ b/subprojects/gst-plugins-bad/ext/opencv/meson.build
@@ -71,7 +71,7 @@ if opencv_found
endif
if not opencv_found
- opencv_dep = dependency('opencv4', version : ['>= 4.0.0', '< 4.6.0'], required : false)
+ opencv_dep = dependency('opencv4', version : ['>= 4.0.0', '< 4.7.0'], required : false)
opencv_found = opencv_dep.found()
if opencv_found
foreach h : libopencv4_headers