defe2d46423bc34861e6fecc552ac9a1d96cc95f
[platform/upstream/gstreamer.git] / ext / opencv / gstcvdilate.cpp
1 /*
2  * GStreamer
3  * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
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.
22  *
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
26  * mentioned above:
27  *
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.
32  *
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.
37  *
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.
42  */
43
44 /**
45  * SECTION:element-cvdilate
46  *
47  * Dilates the image with the cvDilate OpenCV function.
48  *
49  * ## Example launch line
50  *
51  * |[
52  * gst-launch-1.0 videotestsrc ! cvdilate ! videoconvert ! autovideosink
53  * ]|
54  */
55
56 #ifdef HAVE_CONFIG_H
57 #  include <config.h>
58 #endif
59
60 #include "gstcvdilate.h"
61 #include <opencv2/core.hpp>
62 #include <opencv2/imgproc.hpp>
63
64 GST_DEBUG_CATEGORY_STATIC (gst_cv_dilate_debug);
65 #define GST_CAT_DEFAULT gst_cv_dilate_debug
66
67 G_DEFINE_TYPE (GstCvDilate, gst_cv_dilate, GST_TYPE_CV_DILATE_ERODE);
68
69 static GstFlowReturn gst_cv_dilate_transform_ip (GstOpencvVideoFilter *
70     filter, GstBuffer * buf, cv::Mat img);
71
72 /* initialize the cvdilate's class */
73 static void
74 gst_cv_dilate_class_init (GstCvDilateClass * klass)
75 {
76   GstOpencvVideoFilterClass *gstopencvbasefilter_class;
77   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
78
79   gstopencvbasefilter_class = (GstOpencvVideoFilterClass *) klass;
80
81   gstopencvbasefilter_class->cv_trans_ip_func = gst_cv_dilate_transform_ip;
82   gst_element_class_set_static_metadata (element_class,
83       "cvdilate",
84       "Transform/Effect/Video",
85       "Applies cvDilate OpenCV function to the image",
86       "Thiago Santos<thiago.sousa.santos@collabora.co.uk>");
87 }
88
89 /* initialize the new element
90  * instantiate pads and add them to element
91  * set pad calback functions
92  * initialize instance structure
93  */
94 static void
95 gst_cv_dilate_init (GstCvDilate * filter)
96 {
97 }
98
99 static GstFlowReturn
100 gst_cv_dilate_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
101     cv::Mat img)
102 {
103   GstCvDilateErode *filter = GST_CV_DILATE_ERODE (base);
104
105   cv::dilate (img, img, cv::Mat (), cv::Point (-1, -1), filter->iterations);
106
107   return GST_FLOW_OK;
108 }
109
110 gboolean
111 gst_cv_dilate_plugin_init (GstPlugin * plugin)
112 {
113   GST_DEBUG_CATEGORY_INIT (gst_cv_dilate_debug, "cvdilate", 0, "cvdilate");
114
115   return gst_element_register (plugin, "cvdilate", GST_RANK_NONE,
116       GST_TYPE_CV_DILATE);
117 }