From: Nicola Murino Date: Sun, 25 Nov 2018 15:13:28 +0000 (+0100) Subject: opencv: make compatible with opencv 4 X-Git-Tag: 1.19.3~507^2~3784 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0773c6ea790862f014b468530a93cf89ae6f3d7;p=platform%2Fupstream%2Fgstreamer.git opencv: make compatible with opencv 4 Closed #826 --- diff --git a/configure.ac b/configure.ac index 1bb19f0..c43a1f0 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 @@ -1872,8 +1872,41 @@ AG_GST_CHECK_FEATURE(OPENCV, [opencv plugins], opencv, [ 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" + else + HAVE_OPENCV="yes" + fi + ], [ 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 f26f9ec..4c11995 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 6df49ab..0658a31 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 39e7891..968e964 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 1ea7e5c..a84672b 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 1296551..93934be 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 673df6b..2d2df7e 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 7f6327e..3024bd9 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 65e4a55..49ee4ba 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 a84372c..49d6d5f 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 5f1e9ea..ac6f0f5 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 0f11c39..7601ba7 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 3ef260d..61b319b 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 4d13fc2..79a7660 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 863348e..9bd2c52 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 0ddf251..22f754d 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 f008481..bfaf6f3 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 db6a1c4..3d7eea1 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 25d9fd2..101d955 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 03aacd1..fb0d3df 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 062f146..d5b7ebb 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 8fa0210..7869e9e 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 9ec0396..e2bdcbb 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 17c5d2b..ba4c569 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 733f23c..918a079 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 4d31bc3..e4e1cf2 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 8b4dcf9..a41e69e 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 080904e..c1cc299 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 ff2fc98..a1a09b1 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 bb5eb94..9d90da7 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 94f3b6d..7232a0a 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 2babdec..3fd472f 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,