opencv: make compatible with opencv 4

Closed #826
This commit is contained in:
Nicola Murino 2018-11-25 16:13:28 +01:00 committed by Nicolas Dufresne
parent 890dbb560f
commit b0773c6ea7
32 changed files with 183 additions and 7 deletions

View file

@ -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)

View file

@ -49,6 +49,9 @@
#include <errno.h>
#include "MotionCells.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
MotionCells::MotionCells ()
{

View file

@ -46,6 +46,10 @@
#define MOTIONCELLS_H_
#include <opencv2/core.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/types_c.h>
#include <opencv2/core/core_c.h>
#endif
#include <fstream>
#include <vector>

View file

@ -21,7 +21,7 @@
#define __GST_CAMERA_UTILS_H__
#include <gst/gst.h>
#include <cv.h>
#include <opencv2/core.hpp>
G_BEGIN_DECLS

View file

@ -85,6 +85,9 @@
#include "gstcameracalibrate.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
#include <opencv2/calib3d.hpp>
#include <gst/opencv/gstopencvutils.h>

View file

@ -78,6 +78,9 @@
#include "gstcameraundistort.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
#include <opencv2/calib3d.hpp>
#include <gst/opencv/gstopencvutils.h>

View file

@ -60,6 +60,9 @@
#include "gstcvdilate.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_dilate_debug);
#define GST_CAT_DEFAULT gst_cv_dilate_debug

View file

@ -62,6 +62,9 @@
#include "gstcvequalizehist.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_equalize_hist_debug);
#define GST_CAT_DEFAULT gst_cv_equalize_hist_debug

View file

@ -60,6 +60,9 @@
#include "gstcverode.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_erode_debug);
#define GST_CAT_DEFAULT gst_cv_erode_debug

View file

@ -60,6 +60,11 @@
#include "gstcvlaplace.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_laplace_debug);
#define GST_CAT_DEFAULT gst_cv_laplace_debug

View file

@ -61,6 +61,9 @@
#include "gst/opencv/gstopencvutils.h"
#include "gstcvsmooth.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_smooth_debug);

View file

@ -60,6 +60,9 @@
#include "gstcvsobel.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_cv_sobel_debug);
#define GST_CAT_DEFAULT gst_cv_sobel_debug

View file

@ -49,6 +49,9 @@
#include <gst/opencv/gstopencvvideofilter.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */

View file

@ -121,6 +121,9 @@ gst-launch-1.0 multifilesrc location=~/im3.png ! pngdec ! videoconvert ! di
#include "gstdisparity.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_disparity_debug);
#define GST_CAT_DEFAULT gst_disparity_debug

View file

@ -49,6 +49,9 @@
#include <opencv2/core.hpp>
#include <opencv2/calib3d.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/types_c.h>
#endif
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */

View file

@ -62,6 +62,9 @@
#include "gstedgedetect.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_edge_detect_debug);
#define GST_CAT_DEFAULT gst_edge_detect_debug

View file

@ -65,6 +65,9 @@
#include "gstfaceblur.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#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

View file

@ -82,6 +82,9 @@ using namespace std;
#include "gstfacedetect.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#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

View file

@ -86,6 +86,9 @@
#include "gstgrabcut.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_grabcut_debug);
#define GST_CAT_DEFAULT gst_grabcut_debug

View file

@ -49,7 +49,9 @@
#include <gst/video/gstvideofilter.h>
#include <gst/opencv/gstopencvvideofilter.h>
#include <opencv2/core.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/types_c.h>
#endif
G_BEGIN_DECLS

View file

@ -63,6 +63,9 @@
/* element header */
#include "gsthanddetect.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#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;

View file

@ -45,8 +45,6 @@
#ifndef __GST_HANDDETECT_H__
#define __GST_HANDDETECT_H__
#include <cv.h>
#include <gst/opencv/gstopencvvideofilter.h>
/* opencv */
#include <opencv2/core.hpp>

View file

@ -64,6 +64,9 @@
#include "gstretinex.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_retinex_debug);
#define GST_CAT_DEFAULT gst_retinex_debug

View file

@ -92,6 +92,9 @@
#include "gstsegmentation.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_segmentation_debug);
#define GST_CAT_DEFAULT gst_segmentation_debug

View file

@ -50,7 +50,9 @@
#include <opencv2/video.hpp>
#include <opencv2/core.hpp>
#include <opencv2/bgsegm.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/types_c.h>
#endif
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */

View file

@ -60,6 +60,9 @@
#include "gstskindetect.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_skin_detect_debug);
#define GST_CAT_DEFAULT gst_skin_detect_debug

View file

@ -64,7 +64,13 @@
#include "../../gst-libs/gst/gst-i18n-plugin.h"
#include "gsttemplatematch.h"
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgcodecs/legacy/constants_c.h>
#else
#include <opencv2/imgcodecs/imgcodecs_c.h>
#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: */

View file

@ -49,6 +49,9 @@
#include <gst/opencv/gstopencvvideofilter.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/imgproc/imgproc_c.h>
#endif
G_BEGIN_DECLS

View file

@ -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',

View file

@ -25,6 +25,9 @@
#include "gstopencvutils.h"
#include <opencv2/core.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/types_c.h>
#endif
/*
The various opencv image containers or headers store the following information:

View file

@ -51,6 +51,9 @@
#include "gstopencvutils.h"
#include <opencv2/core.hpp>
#if (CV_MAJOR_VERSION >= 4)
#include <opencv2/core/core_c.h>
#endif
GST_DEBUG_CATEGORY_STATIC (gst_opencv_video_filter_debug);
#define GST_CAT_DEFAULT gst_opencv_video_filter_debug

View file

@ -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,