summaryrefslogtreecommitdiff
path: root/gst-libs
diff options
context:
space:
mode:
authorNicola Murino <nicola.murino@gmail.com>2018-12-01 22:48:53 +0100
committerNicolas Dufresne <nicolas@ndufresne.ca>2019-02-02 18:34:10 +0000
commit26cabf9b1f2251df52be9958592b03518832cd9a (patch)
tree620b9defeb59cd472f053da93cd508f1571275ca /gst-libs
parentf974246647cd6e895247cfa5b63b5532bbf40188 (diff)
downloadgstreamer-plugins-bad-26cabf9b1f2251df52be9958592b03518832cd9a.tar.gz
opencv: port to c++
Diffstat (limited to 'gst-libs')
-rw-r--r--gst-libs/gst/opencv/gstopencvutils.cpp25
-rw-r--r--gst-libs/gst/opencv/gstopencvutils.h13
-rw-r--r--gst-libs/gst/opencv/gstopencvvideofilter.cpp61
-rw-r--r--gst-libs/gst/opencv/gstopencvvideofilter.h18
4 files changed, 45 insertions, 72 deletions
diff --git a/gst-libs/gst/opencv/gstopencvutils.cpp b/gst-libs/gst/opencv/gstopencvutils.cpp
index 9d90da73f..e9fe5c827 100644
--- a/gst-libs/gst/opencv/gstopencvutils.cpp
+++ b/gst-libs/gst/opencv/gstopencvutils.cpp
@@ -1,5 +1,6 @@
/* GStreamer
* Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ * Copyright (C) <2018> Nicola Murino <nicola.murino@gmail.com>
*
* gstopencvutils.c: miscellaneous utility functions
*
@@ -25,9 +26,6 @@
#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:
@@ -78,9 +76,8 @@ Some have restrictions but if a format is supported then both BGR and RGB
layouts will be supported.
*/
-gboolean
-gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
- gint * height, gint * ipldepth, gint * channels, GError ** err)
+gboolean gst_opencv_parse_cv_mat_params_from_caps
+ (GstCaps * caps, gint * width, gint * height, int *cv_type, GError ** err)
{
GstVideoInfo info;
gchar *caps_str;
@@ -94,28 +91,24 @@ gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
return FALSE;
}
- return gst_opencv_iplimage_params_from_video_info (&info, width, height,
- ipldepth, channels, err);
+ return gst_opencv_cv_mat_params_from_video_info (&info, width, height,
+ cv_type, err);
}
-gboolean
-gst_opencv_iplimage_params_from_video_info (GstVideoInfo * info, gint * width,
- gint * height, gint * ipldepth, gint * channels, GError ** err)
+gboolean gst_opencv_cv_mat_params_from_video_info
+ (GstVideoInfo * info, gint * width, gint * height, int *cv_type,
+ GError ** err)
{
GstVideoFormat format;
- int cv_type;
format = GST_VIDEO_INFO_FORMAT (info);
- if (!gst_opencv_cv_image_type_from_video_format (format, &cv_type, err)) {
+ if (!gst_opencv_cv_image_type_from_video_format (format, cv_type, err)) {
return FALSE;
}
*width = GST_VIDEO_INFO_WIDTH (info);
*height = GST_VIDEO_INFO_HEIGHT (info);
- *ipldepth = cvIplDepth (cv_type);
- *channels = CV_MAT_CN (cv_type);
-
return TRUE;
}
diff --git a/gst-libs/gst/opencv/gstopencvutils.h b/gst-libs/gst/opencv/gstopencvutils.h
index 3b74cc970..5f03ea752 100644
--- a/gst-libs/gst/opencv/gstopencvutils.h
+++ b/gst-libs/gst/opencv/gstopencvutils.h
@@ -1,5 +1,6 @@
/* GStreamer
* Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ * Copyright (C) <2018> Nicola Murino <nicola.murino@gmail.com>
*
* gstopencvutils.h: miscellaneous utility functions
*
@@ -33,14 +34,14 @@
G_BEGIN_DECLS
GST_OPENCV_API
-gboolean gst_opencv_parse_iplimage_params_from_caps
- (GstCaps * caps, gint * width, gint * height, gint * depth,
- gint * channels, GError ** err);
+gboolean gst_opencv_parse_cv_mat_params_from_caps
+ (GstCaps * caps, gint * width, gint * height, int * cv_type,
+ GError ** err);
GST_OPENCV_API
-gboolean gst_opencv_iplimage_params_from_video_info
- (GstVideoInfo * info, gint * width, gint * height, gint * depth,
- gint * channels, GError ** err);
+gboolean gst_opencv_cv_mat_params_from_video_info
+ (GstVideoInfo * info, gint * width, gint * height, int *cv_type,
+ GError ** err);
GST_OPENCV_API
gboolean gst_opencv_cv_image_type_from_video_format (GstVideoFormat format,
diff --git a/gst-libs/gst/opencv/gstopencvvideofilter.cpp b/gst-libs/gst/opencv/gstopencvvideofilter.cpp
index 7232a0a68..4664534f6 100644
--- a/gst-libs/gst/opencv/gstopencvvideofilter.cpp
+++ b/gst-libs/gst/opencv/gstopencvvideofilter.cpp
@@ -1,6 +1,7 @@
/*
* GStreamer
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ * Copyright (C) 2018 Nicola Murino <nicola.murino@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -49,11 +50,7 @@
#include "gstopencvvideofilter.h"
#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
@@ -94,10 +91,8 @@ gst_opencv_video_filter_finalize (GObject * obj)
{
GstOpencvVideoFilter *transform = GST_OPENCV_VIDEO_FILTER (obj);
- if (transform->cvImage)
- cvReleaseImage (&transform->cvImage);
- if (transform->out_cvImage)
- cvReleaseImage (&transform->out_cvImage);
+ transform->cvImage.release ();
+ transform->out_cvImage.release ();
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
@@ -142,17 +137,11 @@ gst_opencv_video_filter_transform_frame (GstVideoFilter * trans,
fclass = GST_OPENCV_VIDEO_FILTER_GET_CLASS (transform);
g_return_val_if_fail (fclass->cv_trans_func != NULL, GST_FLOW_ERROR);
- g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
- g_return_val_if_fail (transform->out_cvImage != NULL, GST_FLOW_ERROR);
-
- transform->cvImage->imageData = (char *) inframe->data[0];
- transform->cvImage->imageSize = inframe->info.size;
- transform->cvImage->widthStep = inframe->info.stride[0];
-
- transform->out_cvImage->imageData = (char *) outframe->data[0];
- transform->out_cvImage->imageSize = outframe->info.size;
- transform->out_cvImage->widthStep = outframe->info.stride[0];
+ transform->cvImage.data = (unsigned char *) inframe->data[0];
+ transform->cvImage.datastart = (unsigned char *) inframe->data[0];
+ transform->out_cvImage.data = (unsigned char *) outframe->data[0];
+ transform->out_cvImage.datastart = (unsigned char *) outframe->data[0];
ret = fclass->cv_trans_func (transform, inframe->buffer, transform->cvImage,
outframe->buffer, transform->out_cvImage);
@@ -171,11 +160,9 @@ gst_opencv_video_filter_transform_frame_ip (GstVideoFilter * trans,
fclass = GST_OPENCV_VIDEO_FILTER_GET_CLASS (transform);
g_return_val_if_fail (fclass->cv_trans_ip_func != NULL, GST_FLOW_ERROR);
- g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
- transform->cvImage->imageData = (char *) frame->data[0];
- transform->cvImage->imageSize = frame->info.size;
- transform->cvImage->widthStep = frame->info.stride[0];
+ transform->cvImage.data = (unsigned char *) frame->data[0];
+ transform->cvImage.datastart = (unsigned char *) frame->data[0];
ret = fclass->cv_trans_ip_func (transform, frame->buffer, transform->cvImage);
@@ -190,22 +177,22 @@ gst_opencv_video_filter_set_info (GstVideoFilter * trans, GstCaps * incaps,
GstOpencvVideoFilterClass *klass =
GST_OPENCV_VIDEO_FILTER_GET_CLASS (transform);
gint in_width, in_height;
- gint in_depth, in_channels;
+ int in_cv_type;
gint out_width, out_height;
- gint out_depth, out_channels;
+ int out_cv_type;
GError *in_err = NULL;
GError *out_err = NULL;
- if (!gst_opencv_iplimage_params_from_video_info (in_info, &in_width,
- &in_height, &in_depth, &in_channels, &in_err)) {
+ if (!gst_opencv_cv_mat_params_from_video_info (in_info, &in_width,
+ &in_height, &in_cv_type, &in_err)) {
GST_WARNING_OBJECT (transform, "Failed to parse input caps: %s",
in_err->message);
g_error_free (in_err);
return FALSE;
}
- if (!gst_opencv_iplimage_params_from_video_info (out_info, &out_width,
- &out_height, &out_depth, &out_channels, &out_err)) {
+ if (!gst_opencv_cv_mat_params_from_video_info (out_info, &out_width,
+ &out_height, &out_cv_type, &out_err)) {
GST_WARNING_OBJECT (transform, "Failed to parse output caps: %s",
out_err->message);
g_error_free (out_err);
@@ -213,23 +200,13 @@ gst_opencv_video_filter_set_info (GstVideoFilter * trans, GstCaps * incaps,
}
if (klass->cv_set_caps) {
- if (!klass->cv_set_caps (transform, in_width, in_height, in_depth,
- in_channels, out_width, out_height, out_depth, out_channels))
+ if (!klass->cv_set_caps (transform, in_width, in_height, in_cv_type,
+ out_width, out_height, out_cv_type))
return FALSE;
}
- if (transform->cvImage) {
- cvReleaseImage (&transform->cvImage);
- }
- if (transform->out_cvImage) {
- cvReleaseImage (&transform->out_cvImage);
- }
-
- transform->cvImage =
- cvCreateImageHeader (cvSize (in_width, in_height), in_depth, in_channels);
- transform->out_cvImage =
- cvCreateImageHeader (cvSize (out_width, out_height), out_depth,
- out_channels);
+ transform->cvImage.create (cv::Size (in_width, in_height), in_cv_type);
+ transform->out_cvImage.create (cv::Size (out_width, out_height), out_cv_type);
gst_base_transform_set_in_place (GST_BASE_TRANSFORM (transform),
transform->in_place);
diff --git a/gst-libs/gst/opencv/gstopencvvideofilter.h b/gst-libs/gst/opencv/gstopencvvideofilter.h
index 58f1bda94..c599d5534 100644
--- a/gst-libs/gst/opencv/gstopencvvideofilter.h
+++ b/gst-libs/gst/opencv/gstopencvvideofilter.h
@@ -1,6 +1,7 @@
/*
* GStreamer
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
+ * Copyright (C) 2018 Nicola Murino <nicola.murino@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -47,11 +48,12 @@
#include <gst/gst.h>
#include <gst/video/gstvideofilter.h>
#include <gst/opencv/opencv-prelude.h>
+#include <opencv2/core.hpp>
G_BEGIN_DECLS
/* forward declare opencv type to avoid exposing them in this API */
-typedef struct _IplImage IplImage;
+//typedef struct _IplImage IplImage;
/* #defines don't like whitespacey bits */
#define GST_TYPE_OPENCV_VIDEO_FILTER \
@@ -72,15 +74,15 @@ typedef struct _GstOpencvVideoFilter GstOpencvVideoFilter;
typedef struct _GstOpencvVideoFilterClass GstOpencvVideoFilterClass;
typedef GstFlowReturn (*GstOpencvVideoFilterTransformIPFunc)
- (GstOpencvVideoFilter * transform, GstBuffer * buffer, IplImage * img);
+ (GstOpencvVideoFilter * transform, GstBuffer * buffer, cv::Mat img);
typedef GstFlowReturn (*GstOpencvVideoFilterTransformFunc)
- (GstOpencvVideoFilter * transform, GstBuffer * buffer, IplImage * img,
- GstBuffer * outbuf, IplImage * outimg);
+ (GstOpencvVideoFilter * transform, GstBuffer * buffer, cv::Mat img,
+ GstBuffer * outbuf, cv::Mat outimg);
typedef gboolean (*GstOpencvVideoFilterSetCaps)
(GstOpencvVideoFilter * transform, gint in_width, gint in_height,
- gint in_depth, gint in_channels, gint out_width, gint out_height,
- gint out_depth, gint out_channels);
+ int in_cv_type, gint out_width, gint out_height,
+ int out_cv_type);
struct _GstOpencvVideoFilter
{
@@ -88,8 +90,8 @@ struct _GstOpencvVideoFilter
gboolean in_place;
- IplImage *cvImage;
- IplImage *out_cvImage;
+ cv::Mat cvImage;
+ cv::Mat out_cvImage;
};
struct _GstOpencvVideoFilterClass