diff --git a/configure.ac b/configure.ac index 1bb19f082e..c43a1f096f 100644 --- a/configure.ac +++ b/configure.ac @@ -1846,7 +1846,7 @@ AG_GST_CHECK_FEATURE(OPENCV, [opencv plugins], opencv, [ dnl a new version and the no-backward-compatibility define. (There doesn't dnl seem to be a switch to suppress the warnings the cvcompat.h header dnl causes.) - PKG_CHECK_MODULES(OPENCV, opencv >= 3.0.0 opencv < 3.5.0 , [ + PKG_CHECK_MODULES([OPENCV], [opencv >= 3.0.0 opencv < 3.5.0] , [ AC_PROG_CXX AC_LANG([C++]) OLD_CPPFLAGS=$CPPFLAGS @@ -1865,6 +1865,35 @@ AG_GST_CHECK_FEATURE(OPENCV, [opencv plugins], opencv, [ CPPFLAGS=$OLD_CPPFLAGS AC_LANG([C]) + if test $something_not_found = "yes"; then + AC_MSG_RESULT([not all opencv2 headers were found]) + HAVE_OPENCV="no" + else + HAVE_OPENCV="yes" + fi + ], [ + PKG_CHECK_MODULES([OPENCV], [opencv4 >= 4.0.0 opencv4 < 4.1.0] , [ + AC_PROG_CXX + AC_LANG([C++]) + OLD_CPPFLAGS=$CPPFLAGS + CPPFLAGS=$OPENCV_CFLAGS + something_not_found=no + AC_CHECK_HEADERS([opencv2/bgsegm.hpp \ + opencv2/calib3d.hpp \ + opencv2/core.hpp \ + opencv2/imgcodecs/legacy/constants_c.h \ + opencv2/imgproc/imgproc_c.h \ + opencv2/core/types_c.h \ + opencv2/core/core_c.h \ + opencv2/imgproc.hpp \ + opencv2/objdetect.hpp \ + opencv2/opencv.hpp \ + opencv2/video.hpp \ + opencv2/bgsegm.hpp], [], [something_not_found=yes]) + + CPPFLAGS=$OLD_CPPFLAGS + AC_LANG([C]) + if test $something_not_found = "yes"; then AC_MSG_RESULT([not all opencv2 headers were found]) HAVE_OPENCV="no" @@ -1874,6 +1903,10 @@ AG_GST_CHECK_FEATURE(OPENCV, [opencv plugins], opencv, [ ], [ HAVE_OPENCV="no" ]) + ]) + OPENCV_PREFIX="`$PKG_CONFIG --variable=prefix opencv`" + AC_DEFINE_UNQUOTED(OPENCV_PREFIX, "$OPENCV_PREFIX", [opencv install prefix]) + AC_SUBST(OPENCV_PREFIX) OPENCV_PREFIX="`$PKG_CONFIG --variable=prefix opencv`" AC_DEFINE_UNQUOTED(OPENCV_PREFIX, "$OPENCV_PREFIX", [opencv install prefix]) AC_SUBST(OPENCV_PREFIX) diff --git a/ext/opencv/MotionCells.cpp b/ext/opencv/MotionCells.cpp index f26f9ec91c..4c11995fc1 100644 --- a/ext/opencv/MotionCells.cpp +++ b/ext/opencv/MotionCells.cpp @@ -49,6 +49,9 @@ #include #include "MotionCells.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif MotionCells::MotionCells () { diff --git a/ext/opencv/MotionCells.h b/ext/opencv/MotionCells.h index 6df49abb6a..0658a31ea5 100644 --- a/ext/opencv/MotionCells.h +++ b/ext/opencv/MotionCells.h @@ -46,6 +46,10 @@ #define MOTIONCELLS_H_ #include +#if (CV_MAJOR_VERSION >= 4) +#include +#include +#endif #include #include diff --git a/ext/opencv/camerautils.hpp b/ext/opencv/camerautils.hpp index 39e78912e9..968e9643a3 100644 --- a/ext/opencv/camerautils.hpp +++ b/ext/opencv/camerautils.hpp @@ -21,7 +21,7 @@ #define __GST_CAMERA_UTILS_H__ #include -#include +#include G_BEGIN_DECLS diff --git a/ext/opencv/gstcameracalibrate.cpp b/ext/opencv/gstcameracalibrate.cpp index 1ea7e5cd46..a84672b7fe 100644 --- a/ext/opencv/gstcameracalibrate.cpp +++ b/ext/opencv/gstcameracalibrate.cpp @@ -85,6 +85,9 @@ #include "gstcameracalibrate.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif #include #include diff --git a/ext/opencv/gstcameraundistort.cpp b/ext/opencv/gstcameraundistort.cpp index 1296551110..93934be3ab 100644 --- a/ext/opencv/gstcameraundistort.cpp +++ b/ext/opencv/gstcameraundistort.cpp @@ -78,6 +78,9 @@ #include "gstcameraundistort.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif #include #include diff --git a/ext/opencv/gstcvdilate.cpp b/ext/opencv/gstcvdilate.cpp index 673df6bd84..2d2df7e0bd 100644 --- a/ext/opencv/gstcvdilate.cpp +++ b/ext/opencv/gstcvdilate.cpp @@ -60,6 +60,9 @@ #include "gstcvdilate.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_cv_dilate_debug); #define GST_CAT_DEFAULT gst_cv_dilate_debug diff --git a/ext/opencv/gstcvequalizehist.cpp b/ext/opencv/gstcvequalizehist.cpp index 7f6327eb8e..3024bd9b7e 100644 --- a/ext/opencv/gstcvequalizehist.cpp +++ b/ext/opencv/gstcvequalizehist.cpp @@ -62,6 +62,9 @@ #include "gstcvequalizehist.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_cv_equalize_hist_debug); #define GST_CAT_DEFAULT gst_cv_equalize_hist_debug diff --git a/ext/opencv/gstcverode.cpp b/ext/opencv/gstcverode.cpp index 65e4a55d21..49ee4ba305 100644 --- a/ext/opencv/gstcverode.cpp +++ b/ext/opencv/gstcverode.cpp @@ -60,6 +60,9 @@ #include "gstcverode.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_cv_erode_debug); #define GST_CAT_DEFAULT gst_cv_erode_debug diff --git a/ext/opencv/gstcvlaplace.cpp b/ext/opencv/gstcvlaplace.cpp index a84372c6d4..49d6d5f81b 100644 --- a/ext/opencv/gstcvlaplace.cpp +++ b/ext/opencv/gstcvlaplace.cpp @@ -60,6 +60,11 @@ #include "gstcvlaplace.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#include +#endif + GST_DEBUG_CATEGORY_STATIC (gst_cv_laplace_debug); #define GST_CAT_DEFAULT gst_cv_laplace_debug diff --git a/ext/opencv/gstcvsmooth.cpp b/ext/opencv/gstcvsmooth.cpp index 5f1e9eaf4d..ac6f0f5f30 100644 --- a/ext/opencv/gstcvsmooth.cpp +++ b/ext/opencv/gstcvsmooth.cpp @@ -61,6 +61,9 @@ #include "gst/opencv/gstopencvutils.h" #include "gstcvsmooth.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_cv_smooth_debug); diff --git a/ext/opencv/gstcvsobel.cpp b/ext/opencv/gstcvsobel.cpp index 0f11c39f83..7601ba772c 100644 --- a/ext/opencv/gstcvsobel.cpp +++ b/ext/opencv/gstcvsobel.cpp @@ -60,6 +60,9 @@ #include "gstcvsobel.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_cv_sobel_debug); #define GST_CAT_DEFAULT gst_cv_sobel_debug diff --git a/ext/opencv/gstdewarp.h b/ext/opencv/gstdewarp.h index 3ef260ddd9..61b319b533 100644 --- a/ext/opencv/gstdewarp.h +++ b/ext/opencv/gstdewarp.h @@ -49,6 +49,9 @@ #include #include #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif G_BEGIN_DECLS /* #defines don't like whitespacey bits */ diff --git a/ext/opencv/gstdisparity.cpp b/ext/opencv/gstdisparity.cpp index 4d13fc2090..79a766053b 100644 --- a/ext/opencv/gstdisparity.cpp +++ b/ext/opencv/gstdisparity.cpp @@ -121,6 +121,9 @@ gst-launch-1.0 multifilesrc location=~/im3.png ! pngdec ! videoconvert ! di #include "gstdisparity.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_disparity_debug); #define GST_CAT_DEFAULT gst_disparity_debug diff --git a/ext/opencv/gstdisparity.h b/ext/opencv/gstdisparity.h index 863348e6a5..9bd2c525da 100644 --- a/ext/opencv/gstdisparity.h +++ b/ext/opencv/gstdisparity.h @@ -49,6 +49,9 @@ #include #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif G_BEGIN_DECLS /* #defines don't like whitespacey bits */ diff --git a/ext/opencv/gstedgedetect.cpp b/ext/opencv/gstedgedetect.cpp index 0ddf2510a1..22f754d20e 100644 --- a/ext/opencv/gstedgedetect.cpp +++ b/ext/opencv/gstedgedetect.cpp @@ -62,6 +62,9 @@ #include "gstedgedetect.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_edge_detect_debug); #define GST_CAT_DEFAULT gst_edge_detect_debug diff --git a/ext/opencv/gstfaceblur.cpp b/ext/opencv/gstfaceblur.cpp index f0084811b6..bfaf6f3c07 100644 --- a/ext/opencv/gstfaceblur.cpp +++ b/ext/opencv/gstfaceblur.cpp @@ -65,6 +65,9 @@ #include "gstfaceblur.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_face_blur_debug); #define GST_CAT_DEFAULT gst_face_blur_debug @@ -73,7 +76,11 @@ GST_DEBUG_CATEGORY_STATIC (gst_face_blur_debug); G_DIR_SEPARATOR_S OPENCV_PATH_NAME G_DIR_SEPARATOR_S "haarcascades" \ G_DIR_SEPARATOR_S "haarcascade_frontalface_default.xml" #define DEFAULT_SCALE_FACTOR 1.25 +#if (CV_MAJOR_VERSION >= 4) +#define DEFAULT_FLAGS CASCADE_DO_CANNY_PRUNING +#else #define DEFAULT_FLAGS CV_HAAR_DO_CANNY_PRUNING +#endif #define DEFAULT_MIN_NEIGHBORS 3 #define DEFAULT_MIN_SIZE_WIDTH 30 #define DEFAULT_MIN_SIZE_HEIGHT 30 diff --git a/ext/opencv/gstfacedetect.cpp b/ext/opencv/gstfacedetect.cpp index db6a1c4b58..3d7eea1b49 100644 --- a/ext/opencv/gstfacedetect.cpp +++ b/ext/opencv/gstfacedetect.cpp @@ -82,6 +82,9 @@ using namespace std; #include "gstfacedetect.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_face_detect_debug); #define GST_CAT_DEFAULT gst_face_detect_debug @@ -94,7 +97,11 @@ GST_DEBUG_CATEGORY_STATIC (gst_face_detect_debug); #define DEFAULT_MOUTH_PROFILE HAAR_CASCADES_DIR "haarcascade_mcs_mouth.xml" #define DEFAULT_EYES_PROFILE HAAR_CASCADES_DIR "haarcascade_mcs_eyepair_small.xml" #define DEFAULT_SCALE_FACTOR 1.25 +#if (CV_MAJOR_VERSION >= 4) +#define DEFAULT_FLAGS CASCADE_DO_CANNY_PRUNING +#else #define DEFAULT_FLAGS CV_HAAR_DO_CANNY_PRUNING +#endif #define DEFAULT_MIN_NEIGHBORS 3 #define DEFAULT_MIN_SIZE_WIDTH 30 #define DEFAULT_MIN_SIZE_HEIGHT 30 diff --git a/ext/opencv/gstgrabcut.cpp b/ext/opencv/gstgrabcut.cpp index 25d9fd2d5f..101d955576 100644 --- a/ext/opencv/gstgrabcut.cpp +++ b/ext/opencv/gstgrabcut.cpp @@ -86,6 +86,9 @@ #include "gstgrabcut.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_grabcut_debug); #define GST_CAT_DEFAULT gst_grabcut_debug diff --git a/ext/opencv/gstgrabcut.h b/ext/opencv/gstgrabcut.h index 03aacd165d..fb0d3dfcea 100644 --- a/ext/opencv/gstgrabcut.h +++ b/ext/opencv/gstgrabcut.h @@ -49,7 +49,9 @@ #include #include #include - +#if (CV_MAJOR_VERSION >= 4) +#include +#endif G_BEGIN_DECLS diff --git a/ext/opencv/gsthanddetect.cpp b/ext/opencv/gsthanddetect.cpp index 062f146e7e..d5b7ebbf4b 100644 --- a/ext/opencv/gsthanddetect.cpp +++ b/ext/opencv/gsthanddetect.cpp @@ -63,6 +63,9 @@ /* element header */ #include "gsthanddetect.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_handdetect_debug); #define GST_CAT_DEFAULT gst_handdetect_debug @@ -410,8 +413,13 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, Mat roi (image, Rect (filter->cvGray->origin, filter->cvGray->origin, filter->cvGray->width, filter->cvGray->height)); +#if (CV_MAJOR_VERSION >= 4) + filter->cvCascade_fist->detectMultiScale (roi, hands, 1.1, 2, + CASCADE_DO_CANNY_PRUNING, cvSize (24, 24), cvSize (0, 0)); +#else filter->cvCascade_fist->detectMultiScale (roi, hands, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize (24, 24), cvSize (0, 0)); +#endif /* if FIST gesture detected */ if (!hands.empty ()) { @@ -498,8 +506,13 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, } } else { /* if NO FIST gesture, detecting PALM gesture */ +#if (CV_MAJOR_VERSION >= 4) + filter->cvCascade_palm->detectMultiScale (roi, hands, 1.1, 2, + CASCADE_DO_CANNY_PRUNING, cvSize (24, 24), cvSize (0, 0)); +#else filter->cvCascade_palm->detectMultiScale (roi, hands, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize (24, 24), cvSize (0, 0)); +#endif /* if PALM detected */ if (!hands.empty ()) { int min_distance, distance; diff --git a/ext/opencv/gsthanddetect.h b/ext/opencv/gsthanddetect.h index 8fa0210e63..7869e9eddc 100644 --- a/ext/opencv/gsthanddetect.h +++ b/ext/opencv/gsthanddetect.h @@ -45,8 +45,6 @@ #ifndef __GST_HANDDETECT_H__ #define __GST_HANDDETECT_H__ -#include - #include /* opencv */ #include diff --git a/ext/opencv/gstretinex.cpp b/ext/opencv/gstretinex.cpp index 9ec03968f4..e2bdcbb313 100644 --- a/ext/opencv/gstretinex.cpp +++ b/ext/opencv/gstretinex.cpp @@ -64,6 +64,9 @@ #include "gstretinex.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_retinex_debug); #define GST_CAT_DEFAULT gst_retinex_debug diff --git a/ext/opencv/gstsegmentation.cpp b/ext/opencv/gstsegmentation.cpp index 17c5d2beb3..ba4c569cb1 100644 --- a/ext/opencv/gstsegmentation.cpp +++ b/ext/opencv/gstsegmentation.cpp @@ -92,6 +92,9 @@ #include "gstsegmentation.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_segmentation_debug); #define GST_CAT_DEFAULT gst_segmentation_debug diff --git a/ext/opencv/gstsegmentation.h b/ext/opencv/gstsegmentation.h index 733f23c545..918a079fd0 100644 --- a/ext/opencv/gstsegmentation.h +++ b/ext/opencv/gstsegmentation.h @@ -50,7 +50,9 @@ #include #include #include - +#if (CV_MAJOR_VERSION >= 4) +#include +#endif G_BEGIN_DECLS /* #defines don't like whitespacey bits */ diff --git a/ext/opencv/gstskindetect.cpp b/ext/opencv/gstskindetect.cpp index 4d31bc3e8f..e4e1cf276e 100644 --- a/ext/opencv/gstskindetect.cpp +++ b/ext/opencv/gstskindetect.cpp @@ -60,6 +60,9 @@ #include "gstskindetect.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_skin_detect_debug); #define GST_CAT_DEFAULT gst_skin_detect_debug diff --git a/ext/opencv/gsttemplatematch.cpp b/ext/opencv/gsttemplatematch.cpp index 8b4dcf925e..a41e69ee03 100644 --- a/ext/opencv/gsttemplatematch.cpp +++ b/ext/opencv/gsttemplatematch.cpp @@ -64,7 +64,13 @@ #include "../../gst-libs/gst/gst-i18n-plugin.h" #include "gsttemplatematch.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#include +#include +#else #include +#endif GST_DEBUG_CATEGORY_STATIC (gst_template_match_debug); #define GST_CAT_DEFAULT gst_template_match_debug @@ -179,7 +185,16 @@ gst_template_match_load_template (GstTemplateMatch * filter, gchar * templ) NULL; if (templ) { +#if (CV_MAJOR_VERSION >= 4) + cv::Mat mat = cv::imread (templ); + newTemplateImage = + cvCreateImage (cvSize (mat.cols, mat.rows), cvIplDepth (mat.flags), + mat.channels ()); + IplImage ipltemp = mat; + cvCopy (&ipltemp, newTemplateImage); +#else newTemplateImage = cvLoadImage (templ, CV_LOAD_IMAGE_COLOR); +#endif if (!newTemplateImage) { /* Unfortunately OpenCV doesn't seem to provide any way of finding out why the image load failed, so we can't be more specific than FAILED: */ diff --git a/ext/opencv/gsttextoverlay.h b/ext/opencv/gsttextoverlay.h index 080904ec94..c1cc299e9d 100644 --- a/ext/opencv/gsttextoverlay.h +++ b/ext/opencv/gsttextoverlay.h @@ -49,6 +49,9 @@ #include #include #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif G_BEGIN_DECLS diff --git a/ext/opencv/meson.build b/ext/opencv/meson.build index ff2fc98f20..a1a09b1ed7 100644 --- a/ext/opencv/meson.build +++ b/ext/opencv/meson.build @@ -39,6 +39,20 @@ libopencv_headers = [ 'opencv2/video.hpp', ] +libopencv4_headers = [ + 'opencv4/opencv2/bgsegm.hpp', + 'opencv4/opencv2/calib3d.hpp', + 'opencv4/opencv2/core.hpp', + 'opencv4/opencv2/imgcodecs/legacy/constants_c.h', + 'opencv4/opencv2/imgproc/imgproc_c.h', + 'opencv4/opencv2/core/types_c.h', + 'opencv4/opencv2/core/core_c.h', + 'opencv4/opencv2/imgproc.hpp', + 'opencv4/opencv2/objdetect.hpp', + 'opencv4/opencv2/opencv.hpp', + 'opencv4/opencv2/video.hpp', +] + gstopencv_cargs = ['-DGST_HAAR_CASCADES_DIR="@0@"'] opencv_dep = dependency('opencv', version : ['>= 3.0.0', '< 3.5.0'], required : false) @@ -51,6 +65,17 @@ if opencv_found opencv_found = false endif endforeach +else + opencv_dep = dependency('opencv4', version : ['>= 4.0.0', '< 4.1.0'], required : false) + opencv_found = opencv_dep.found() + if opencv_found + foreach h : libopencv4_headers + if not cxx.has_header(h) + message('Needed header "' + h + '" not found') + opencv_found = false + endif + endforeach + endif endif if opencv_found @@ -67,7 +92,12 @@ if opencv_found if r.returncode() == 0 gstopencv_cargs += '-DOPENCV_PATH_NAME="OpenCV"' else - error('Unable to detect OpenCV data directory') + r = run_command('test', '-d', opencv_prefix + '/share/opencv4') + if r.returncode() == 0 + gstopencv_cargs += '-DOPENCV_PATH_NAME="opencv4"' + else + error('Unable to detect OpenCV data directory') + endif endif endif gstopencv = library('gstopencv', diff --git a/gst-libs/gst/opencv/gstopencvutils.cpp b/gst-libs/gst/opencv/gstopencvutils.cpp index bb5eb94c29..9d90da73f6 100644 --- a/gst-libs/gst/opencv/gstopencvutils.cpp +++ b/gst-libs/gst/opencv/gstopencvutils.cpp @@ -25,6 +25,9 @@ #include "gstopencvutils.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif /* The various opencv image containers or headers store the following information: diff --git a/gst-libs/gst/opencv/gstopencvvideofilter.cpp b/gst-libs/gst/opencv/gstopencvvideofilter.cpp index 94f3b6d4ee..7232a0a68b 100644 --- a/gst-libs/gst/opencv/gstopencvvideofilter.cpp +++ b/gst-libs/gst/opencv/gstopencvvideofilter.cpp @@ -51,6 +51,9 @@ #include "gstopencvutils.h" #include +#if (CV_MAJOR_VERSION >= 4) +#include +#endif GST_DEBUG_CATEGORY_STATIC (gst_opencv_video_filter_debug); #define GST_CAT_DEFAULT gst_opencv_video_filter_debug diff --git a/gst-libs/gst/opencv/meson.build b/gst-libs/gst/opencv/meson.build index 2babdec85b..3fd472fda5 100644 --- a/gst-libs/gst/opencv/meson.build +++ b/gst-libs/gst/opencv/meson.build @@ -10,6 +10,9 @@ opencv_headers = [ ] opencv_dep = dependency('opencv', version : '>= 3.0.0', required : get_option('opencv')) +if not opencv_dep.found() + opencv_dep = dependency('opencv4', version : '>= 4.0.0', required : get_option('opencv')) +endif if opencv_dep.found() gstopencv = library('gstopencv-' + api_version, opencv_sources,