opencv: switch remaining to C++

Switch remaining C files to C++ for consistency with other OpeCV elements,
and support of the new 2.4.11 API.

https://bugzilla.gnome.org/show_bug.cgi?id=754148
This commit is contained in:
Luis de Bethencourt 2015-10-14 15:30:05 +01:00
parent 1f7156d478
commit f58cd983b6
4 changed files with 71 additions and 80 deletions

View file

@ -2,8 +2,8 @@ plugin_LTLIBRARIES = libgstopencv.la
# sources used to compile this plug-in
libgstopencv_la_SOURCES = gstopencv.cpp \
gstopencvvideofilter.c \
gstopencvutils.c \
gstopencvvideofilter.cpp \
gstopencvutils.cpp \
gstcvdilate.cpp \
gstcvdilateerode.cpp \
gstcvequalizehist.cpp \
@ -15,7 +15,7 @@ libgstopencv_la_SOURCES = gstopencv.cpp \
gstfaceblur.cpp \
gsthanddetect.cpp \
gstpyramidsegment.cpp \
gsttemplatematch.c \
gsttemplatematch.cpp \
gsttextoverlay.cpp \
gstmotioncells.cpp \
gstskindetect.cpp \

View file

@ -32,7 +32,8 @@ gst_opencv_get_ipl_depth_and_channels (GstStructure * structure,
{
GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
const GstVideoFormatInfo *info;
gint depth = 0, i;
gint depth = 0;
guint i;
const gchar *s;
if (gst_structure_has_name (structure, "video/x-raw")) {
@ -97,7 +98,8 @@ gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
gint * height, gint * ipldepth, gint * channels, GError ** err)
{
GstVideoInfo info;
gint i, depth = 0;
gint depth = 0;
guint i;
if (!gst_video_info_from_caps (&info, caps)) {
GST_ERROR ("Failed to get the videoinfo from caps");

View file

@ -1,7 +1,7 @@
/*
* GStreamer
* Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
@ -135,7 +135,7 @@ gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass * klass)
gobject_class = (GObjectClass *) klass;
basetrans_class = (GstBaseTransformClass *) klass;
parent_class = g_type_class_peek_parent (klass);
parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
GST_DEBUG_CATEGORY_INIT (gst_opencv_video_filter_debug,
"opencvbasetransform", 0, "opencvbasetransform element");
@ -217,7 +217,7 @@ gst_opencv_video_filter_transform_ip (GstBaseTransform * trans,
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);
if (!gst_buffer_map (buffer, &info, GST_MAP_READWRITE))
if (!gst_buffer_map (buffer, &info, (GstMapFlags) (GST_MAP_READWRITE)))
goto map_failed;
transform->cvImage->imageData = (char *) info.data;

View file

@ -4,7 +4,7 @@
* Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
* Copyright (C) 2009 Noam Lewis <jones.noamle@gmail.com>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
@ -115,13 +115,6 @@ static gboolean gst_template_match_handle_sink_event (GstPad * pad,
static GstFlowReturn gst_template_match_chain (GstPad * pad, GstObject * parent,
GstBuffer * buf);
static void gst_template_match_load_template (GstTemplateMatch * filter,
gchar * template);
static void gst_template_match_match (IplImage * input, IplImage * template,
IplImage * dist_image, double *best_res, CvPoint * best_pos, int method);
/* initialize the templatematch's class */
static void
gst_template_match_class_init (GstTemplateMatchClass * klass)
@ -138,14 +131,14 @@ gst_template_match_class_init (GstTemplateMatchClass * klass)
g_object_class_install_property (gobject_class, PROP_METHOD,
g_param_spec_int ("method", "Method",
"Specifies the way the template must be compared with image regions. 0=SQDIFF, 1=SQDIFF_NORMED, 2=CCOR, 3=CCOR_NORMED, 4=CCOEFF, 5=CCOEFF_NORMED.",
0, 5, DEFAULT_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
0, 5, DEFAULT_METHOD, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_TEMPLATE,
g_param_spec_string ("template", "Template", "Filename of template image",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
NULL, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_DISPLAY,
g_param_spec_boolean ("display", "Display",
"Sets whether the detected template should be highlighted in the output",
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
TRUE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
gst_element_class_set_static_metadata (element_class,
"templatematch",
@ -187,6 +180,42 @@ gst_template_match_init (GstTemplateMatch * filter)
filter->method = DEFAULT_METHOD;
}
/* We take ownership of template here */
static void
gst_template_match_load_template (GstTemplateMatch * filter, gchar * templ)
{
gchar *oldTemplateFilename = NULL;
IplImage *oldTemplateImage = NULL, *newTemplateImage = NULL, *oldDistImage =
NULL;
if (templ) {
newTemplateImage = cvLoadImage (templ, CV_LOAD_IMAGE_COLOR);
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: */
GST_ELEMENT_WARNING (filter, RESOURCE, FAILED,
(_("OpenCV failed to load template image")),
("While attempting to load template '%s'", templ));
g_free (templ);
templ = NULL;
}
}
GST_OBJECT_LOCK (filter);
oldTemplateFilename = filter->templ;
filter->templ = templ;
oldTemplateImage = filter->cvTemplateImage;
filter->cvTemplateImage = newTemplateImage;
oldDistImage = filter->cvDistImage;
/* This will be recreated in the chain function as required: */
filter->cvDistImage = NULL;
GST_OBJECT_UNLOCK (filter);
cvReleaseImage (&oldDistImage);
cvReleaseImage (&oldTemplateImage);
g_free (oldTemplateFilename);
}
static void
gst_template_match_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
@ -312,6 +341,26 @@ gst_template_match_finalize (GObject * object)
G_OBJECT_CLASS (gst_template_match_parent_class)->finalize (object);
}
static void
gst_template_match_match (IplImage * input, IplImage * templ,
IplImage * dist_image, double *best_res, CvPoint * best_pos, int method)
{
double dist_min = 0, dist_max = 0;
CvPoint min_pos, max_pos;
cvMatchTemplate (input, templ, dist_image, method);
cvMinMaxLoc (dist_image, &dist_min, &dist_max, &min_pos, &max_pos, NULL);
if ((CV_TM_SQDIFF_NORMED == method) || (CV_TM_SQDIFF == method)) {
*best_res = dist_min;
*best_pos = min_pos;
if (CV_TM_SQDIFF_NORMED == method) {
*best_res = 1 - *best_res;
}
} else {
*best_res = dist_max;
*best_pos = max_pos;
}
}
/* chain function
* this function does the actual processing
*/
@ -332,7 +381,7 @@ gst_template_match_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
GST_LOG_OBJECT (filter, "Buffer size %u", (guint) gst_buffer_get_size (buf));
buf = gst_buffer_make_writable (buf);
gst_buffer_map (buf, &info, GST_MAP_READWRITE);
gst_buffer_map (buf, &info, (GstMapFlags) (GST_MAP_READWRITE));
filter->cvImage->imageData = (char *) info.data;
GST_OBJECT_LOCK (filter);
@ -402,66 +451,6 @@ gst_template_match_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
return gst_pad_push (filter->srcpad, buf);
}
static void
gst_template_match_match (IplImage * input, IplImage * templ,
IplImage * dist_image, double *best_res, CvPoint * best_pos, int method)
{
double dist_min = 0, dist_max = 0;
CvPoint min_pos, max_pos;
cvMatchTemplate (input, templ, dist_image, method);
cvMinMaxLoc (dist_image, &dist_min, &dist_max, &min_pos, &max_pos, NULL);
if ((CV_TM_SQDIFF_NORMED == method) || (CV_TM_SQDIFF == method)) {
*best_res = dist_min;
*best_pos = min_pos;
if (CV_TM_SQDIFF_NORMED == method) {
*best_res = 1 - *best_res;
}
} else {
*best_res = dist_max;
*best_pos = max_pos;
}
}
/* We take ownership of template here */
static void
gst_template_match_load_template (GstTemplateMatch * filter, gchar * templ)
{
gchar *oldTemplateFilename = NULL;
IplImage *oldTemplateImage = NULL, *newTemplateImage = NULL, *oldDistImage =
NULL;
if (templ) {
newTemplateImage = cvLoadImage (templ, CV_LOAD_IMAGE_COLOR);
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: */
GST_ELEMENT_WARNING (filter, RESOURCE, FAILED,
(_("OpenCV failed to load template image")),
("While attempting to load template '%s'", templ));
g_free (templ);
templ = NULL;
}
}
GST_OBJECT_LOCK (filter);
oldTemplateFilename = filter->templ;
filter->templ = templ;
oldTemplateImage = filter->cvTemplateImage;
filter->cvTemplateImage = newTemplateImage;
oldDistImage = filter->cvDistImage;
/* This will be recreated in the chain function as required: */
filter->cvDistImage = NULL;
GST_OBJECT_UNLOCK (filter);
cvReleaseImage (&oldDistImage);
cvReleaseImage (&oldTemplateImage);
g_free (oldTemplateFilename);
}
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and other features