3 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Alternatively, the contents of this file may be used under the
24 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
25 * which case the following provisions apply instead of the ones
28 * This library is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU Library General Public
30 * License as published by the Free Software Foundation; either
31 * version 2 of the License, or (at your option) any later version.
33 * This library is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 * Library General Public License for more details.
38 * You should have received a copy of the GNU Library General Public
39 * License along with this library; if not, write to the
40 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
41 * Boston, MA 02110-1301, USA.
45 * As cvdilate_erode and cverode are all the same, except for the transform function,
46 * we hope this base class should keep maintenance easier.
53 #include "gst/opencv/gstopencvutils.h"
54 #include "gstcvdilateerode.h"
56 #include <opencv2/core.hpp>
59 GST_DEBUG_CATEGORY_STATIC (gst_cv_dilate_erode_debug);
60 #define GST_CAT_DEFAULT gst_cv_dilate_erode_debug
64 /* Filter signals and args */
76 #define DEFAULT_ITERATIONS 1
78 static void gst_cv_dilate_erode_class_init (GstCvDilateErodeClass * klass);
79 static void gst_cv_dilate_erode_init (GstCvDilateErode * filter,
80 GstCvDilateErodeClass * gclass);
82 static void gst_cv_dilate_erode_set_property (GObject * object, guint prop_id,
83 const GValue * value, GParamSpec * pspec);
84 static void gst_cv_dilate_erode_get_property (GObject * object, guint prop_id,
85 GValue * value, GParamSpec * pspec);
88 gst_cv_dilate_erode_get_type (void)
90 static gsize opencv_dilate_erode_type = 0;
92 if (g_once_init_enter (&opencv_dilate_erode_type)) {
94 static const GTypeInfo opencv_dilate_erode_info = {
95 sizeof (GstCvDilateErodeClass),
98 (GClassInitFunc) gst_cv_dilate_erode_class_init,
101 sizeof (GstCvDilateErode),
103 (GInstanceInitFunc) gst_cv_dilate_erode_init,
106 _type = g_type_register_static (GST_TYPE_OPENCV_VIDEO_FILTER,
107 "GstCvDilateErode", &opencv_dilate_erode_info, G_TYPE_FLAG_ABSTRACT);
109 GST_DEBUG_CATEGORY_INIT (gst_cv_dilate_erode_debug, "cvdilateerode", 0,
112 g_once_init_leave (&opencv_dilate_erode_type, _type);
114 return opencv_dilate_erode_type;
117 /* initialize the cvdilate_erode's class */
119 gst_cv_dilate_erode_class_init (GstCvDilateErodeClass * klass)
121 GObjectClass *gobject_class;
122 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
124 GstPadTemplate *templ;
126 gobject_class = (GObjectClass *) klass;
128 gobject_class->set_property = gst_cv_dilate_erode_set_property;
129 gobject_class->get_property = gst_cv_dilate_erode_get_property;
131 g_object_class_install_property (gobject_class, PROP_ITERATIONS,
132 g_param_spec_int ("iterations", "iterations",
133 "Number of iterations to run the algorithm", 1, G_MAXINT,
135 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
137 /* add sink and source pad templates */
138 caps = gst_opencv_caps_from_cv_image_type (CV_16UC1);
139 gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC4));
140 gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC3));
141 gst_caps_append (caps, gst_opencv_caps_from_cv_image_type (CV_8UC1));
142 templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
143 gst_caps_ref (caps));
144 gst_element_class_add_pad_template (element_class, templ);
145 templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
146 gst_element_class_add_pad_template (element_class, templ);
147 gst_caps_unref (caps);
149 gst_type_mark_as_plugin_api (GST_TYPE_CV_DILATE_ERODE, (GstPluginAPIFlags) 0);
152 /* initialize the new element
153 * instantiate pads and add them to element
154 * set pad callback functions
155 * initialize instance structure
158 gst_cv_dilate_erode_init (GstCvDilateErode * filter,
159 GstCvDilateErodeClass * gclass)
161 filter->iterations = DEFAULT_ITERATIONS;
162 gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
167 gst_cv_dilate_erode_set_property (GObject * object, guint prop_id,
168 const GValue * value, GParamSpec * pspec)
170 GstCvDilateErode *filter = GST_CV_DILATE_ERODE (object);
173 case PROP_ITERATIONS:
174 filter->iterations = g_value_get_int (value);
177 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
183 gst_cv_dilate_erode_get_property (GObject * object, guint prop_id,
184 GValue * value, GParamSpec * pspec)
186 GstCvDilateErode *filter = GST_CV_DILATE_ERODE (object);
189 case PROP_ITERATIONS:
190 g_value_set_int (value, filter->iterations);
193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);