mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
opencv: add blur and bilateral support in cvsmooth
Adding the support for the two other OpenCV linear filters to smooth images. The new API does support spatial sigma in the bilateral filter, hence bringing that property back. Adding reference to new documentation.
This commit is contained in:
parent
10ed707b60
commit
98784aa72c
2 changed files with 25 additions and 3 deletions
|
@ -161,7 +161,9 @@ gst_cv_smooth_class_init (GstCvSmoothClass * klass)
|
||||||
g_object_class_install_property (gobject_class, PROP_WIDTH,
|
g_object_class_install_property (gobject_class, PROP_WIDTH,
|
||||||
g_param_spec_int ("width", "width (kernel width)",
|
g_param_spec_int ("width", "width (kernel width)",
|
||||||
"The gaussian kernel width (must be positive and odd)."
|
"The gaussian kernel width (must be positive and odd)."
|
||||||
"If type is median, this means the aperture linear size.",
|
"If type is median, this means the aperture linear size."
|
||||||
|
"Check OpenCV docs: http://docs.opencv.org"
|
||||||
|
"/2.4/modules/imgproc/doc/filtering.htm",
|
||||||
1, G_MAXINT, DEFAULT_WIDTH,
|
1, G_MAXINT, DEFAULT_WIDTH,
|
||||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||||
g_object_class_install_property (gobject_class, PROP_HEIGHT,
|
g_object_class_install_property (gobject_class, PROP_HEIGHT,
|
||||||
|
@ -172,12 +174,14 @@ gst_cv_smooth_class_init (GstCvSmoothClass * klass)
|
||||||
g_object_class_install_property (gobject_class, PROP_COLORSIGMA,
|
g_object_class_install_property (gobject_class, PROP_COLORSIGMA,
|
||||||
g_param_spec_double ("color", "color (gaussian standard deviation or "
|
g_param_spec_double ("color", "color (gaussian standard deviation or "
|
||||||
"color sigma",
|
"color sigma",
|
||||||
"Gaussian kernel standard deviation in X and Y direction",
|
"If type is gaussian, this means the standard deviation."
|
||||||
|
"If type is bilateral, this means the color-sigma. If zero, "
|
||||||
|
"Default values are used.",
|
||||||
0, G_MAXDOUBLE, DEFAULT_COLORSIGMA,
|
0, G_MAXDOUBLE, DEFAULT_COLORSIGMA,
|
||||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||||
g_object_class_install_property (gobject_class, PROP_SPATIALSIGMA,
|
g_object_class_install_property (gobject_class, PROP_SPATIALSIGMA,
|
||||||
g_param_spec_double ("spatial", "spatial (spatial sigma, bilateral only)",
|
g_param_spec_double ("spatial", "spatial (spatial sigma, bilateral only)",
|
||||||
"(DEPRECATED: value not used anymore)",
|
"Only used in bilateral type, means the spatial-sigma.",
|
||||||
0, G_MAXDOUBLE, DEFAULT_SPATIALSIGMA,
|
0, G_MAXDOUBLE, DEFAULT_SPATIALSIGMA,
|
||||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||||
|
|
||||||
|
@ -209,6 +213,7 @@ gst_cv_smooth_init (GstCvSmooth * filter)
|
||||||
filter->width = DEFAULT_WIDTH;
|
filter->width = DEFAULT_WIDTH;
|
||||||
filter->height = DEFAULT_HEIGHT;
|
filter->height = DEFAULT_HEIGHT;
|
||||||
filter->colorsigma = DEFAULT_COLORSIGMA;
|
filter->colorsigma = DEFAULT_COLORSIGMA;
|
||||||
|
filter->spatialsigma = DEFAULT_SPATIALSIGMA;
|
||||||
|
|
||||||
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
|
gst_opencv_video_filter_set_in_place (GST_OPENCV_VIDEO_FILTER_CAST (filter),
|
||||||
FALSE);
|
FALSE);
|
||||||
|
@ -271,6 +276,7 @@ gst_cv_smooth_set_property (GObject * object, guint prop_id,
|
||||||
filter->colorsigma = g_value_get_double (value);
|
filter->colorsigma = g_value_get_double (value);
|
||||||
break;
|
break;
|
||||||
case PROP_SPATIALSIGMA:
|
case PROP_SPATIALSIGMA:
|
||||||
|
filter->spatialsigma = g_value_get_double (value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
@ -298,6 +304,7 @@ gst_cv_smooth_get_property (GObject * object, guint prop_id,
|
||||||
g_value_set_double (value, filter->colorsigma);
|
g_value_set_double (value, filter->colorsigma);
|
||||||
break;
|
break;
|
||||||
case PROP_SPATIALSIGMA:
|
case PROP_SPATIALSIGMA:
|
||||||
|
g_value_set_double (value, filter->spatialsigma);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
@ -312,6 +319,10 @@ gst_cv_smooth_transform (GstOpencvVideoFilter * base, GstBuffer * buf,
|
||||||
GstCvSmooth *filter = GST_CV_SMOOTH (base);
|
GstCvSmooth *filter = GST_CV_SMOOTH (base);
|
||||||
|
|
||||||
switch (filter->type) {
|
switch (filter->type) {
|
||||||
|
case CV_BLUR:
|
||||||
|
blur (Mat (img), Mat (outimg), Size (filter->width, filter->height),
|
||||||
|
Point (-1, -1));
|
||||||
|
break;
|
||||||
case CV_GAUSSIAN:
|
case CV_GAUSSIAN:
|
||||||
GaussianBlur (Mat (img), Mat (outimg), Size (filter->width,
|
GaussianBlur (Mat (img), Mat (outimg), Size (filter->width,
|
||||||
filter->height), filter->colorsigma, filter->colorsigma);
|
filter->height), filter->colorsigma, filter->colorsigma);
|
||||||
|
@ -319,6 +330,9 @@ gst_cv_smooth_transform (GstOpencvVideoFilter * base, GstBuffer * buf,
|
||||||
case CV_MEDIAN:
|
case CV_MEDIAN:
|
||||||
medianBlur (Mat (img), Mat (outimg), filter->width);
|
medianBlur (Mat (img), Mat (outimg), filter->width);
|
||||||
break;
|
break;
|
||||||
|
case CV_BILATERAL:
|
||||||
|
bilateralFilter (Mat (img), Mat (outimg), -1, filter->colorsigma, 0.0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -333,6 +347,10 @@ gst_cv_smooth_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
|
||||||
GstCvSmooth *filter = GST_CV_SMOOTH (base);
|
GstCvSmooth *filter = GST_CV_SMOOTH (base);
|
||||||
|
|
||||||
switch (filter->type) {
|
switch (filter->type) {
|
||||||
|
case CV_BLUR:
|
||||||
|
blur (Mat (img), Mat (img), Size (filter->width, filter->height),
|
||||||
|
Point (-1, -1));
|
||||||
|
break;
|
||||||
case CV_GAUSSIAN:
|
case CV_GAUSSIAN:
|
||||||
GaussianBlur (Mat (img), Mat (img), Size (filter->width, filter->height),
|
GaussianBlur (Mat (img), Mat (img), Size (filter->width, filter->height),
|
||||||
filter->colorsigma, filter->colorsigma);
|
filter->colorsigma, filter->colorsigma);
|
||||||
|
@ -340,6 +358,9 @@ gst_cv_smooth_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
|
||||||
case CV_MEDIAN:
|
case CV_MEDIAN:
|
||||||
medianBlur (Mat (img), Mat (img), filter->width);
|
medianBlur (Mat (img), Mat (img), filter->width);
|
||||||
break;
|
break;
|
||||||
|
case CV_BILATERAL:
|
||||||
|
bilateralFilter (Mat (img), Mat (img), -1, filter->colorsigma, 0.0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ struct _GstCvSmooth
|
||||||
gint width;
|
gint width;
|
||||||
gint height;
|
gint height;
|
||||||
gdouble colorsigma;
|
gdouble colorsigma;
|
||||||
|
gdouble spatialsigma;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstCvSmoothClass
|
struct _GstCvSmoothClass
|
||||||
|
|
Loading…
Reference in a new issue