From 4ee338eccac70f1c7cd85bfdc57d0411216ae93e Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 13 Feb 2022 18:40:17 +0900 Subject: [PATCH 01/18] wip: implementing median_blur and split --- opencv-glib/image.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ opencv-glib/image.h | 4 +++ 2 files changed, 65 insertions(+) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 3373558..dcb358b 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -7,6 +7,7 @@ #include #include +#include G_BEGIN_DECLS @@ -658,6 +659,65 @@ gcv_image_abs_diff(GCVImage *image, return gcv_image_new_raw(&cv_output); } +/** + * gcv_image_split: + * @image: A #GCVImage. + * + * It splits image. The splitted image is returned as + * a new matrix. + * + * Returns: (element-type GCVImage) (transfer full): + * The list of #GCVImage + * + * Since: 1.0.4 + */ +GList * +gcv_image_split(GCVImage *image) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + std::vector planes; + GList *values = NULL; + int i; + + cv::split(*cv_image,planes); + + // TODO. get number of channels instead of 3 + for( i = 0 ; i < 3 ; i++ ){ + values = g_list_prepend(values,&planes[i]); + } + values = g_list_prepend(values, NULL); + + return g_list_reverse(values); +/* + cv::imwrite("/tmp/b.jpg",planes[0]); + cv::imwrite("/tmp/g.jpg",planes[1]); + cv::imwrite("/tmp/r.jpg",planes[2]); +*/ +} + +/** + * gcv_image_median_blur: + * @image: A #GCVImage. + * + * It effects median blur image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_median_blur(GCVImage *image) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_converted_image = std::make_shared(); + + // TODO: * Use the arguments instead of static number. + // * Change blur instead of medianBlur. + cv::medianBlur(*cv_image, *cv_converted_image, 3); + + return gcv_image_new_raw(&cv_converted_image); +} + G_END_DECLS GCVImage * @@ -668,3 +728,4 @@ gcv_image_new_raw(std::shared_ptr *cv_matrix) NULL); return GCV_IMAGE(matrix); } + diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 614a7af..a4499f9 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -229,4 +229,8 @@ GCVImage * gcv_image_abs_diff(GCVImage *image, GCVImage *other_image); +GList *gcv_image_split(GCVImage *image); + +GCVImage *gcv_image_median_blur(GCVImage *image); + G_END_DECLS From d0ecaef5d56046366214b2d990bdab1161657430 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 20 Feb 2022 21:31:50 +0900 Subject: [PATCH 02/18] Apply kou review --- opencv-glib/image.cpp | 19 ++++++------------- test/test-image.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index dcb358b..1be0d0b 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -675,24 +675,17 @@ GList * gcv_image_split(GCVImage *image) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); - std::vector planes; + std::vector cv_splitted_images; GList *values = NULL; - int i; - cv::split(*cv_image,planes); - - // TODO. get number of channels instead of 3 - for( i = 0 ; i < 3 ; i++ ){ - values = g_list_prepend(values,&planes[i]); + cv::split(*cv_image, cv_splitted_images); + for (const auto &cv_splitted_image : cv_splitted_images) { + auto cv_shared_splitted_image = std::make_shared(cv_splitted_image); + auto splitted_image = gcv_image_new_raw(&cv_shared_splitted_image); + values = g_list_prepend(values, splitted_image); } - values = g_list_prepend(values, NULL); return g_list_reverse(values); -/* - cv::imwrite("/tmp/b.jpg",planes[0]); - cv::imwrite("/tmp/g.jpg",planes[1]); - cv::imwrite("/tmp/r.jpg",planes[2]); -*/ } /** diff --git a/test/test-image.rb b/test/test-image.rb index 3f5ac4f..f37e49d 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -323,5 +323,21 @@ def test_abs_diff assert_equal(expected.bytes.to_s, @image.abs_diff(lined_image).bytes.to_s) end + + def test_split + spliited_data = @image.bytes.to_s.each_char.group_by.with_index do |_, i| + i % 4 + end + splitted_image_data = @image.split.collect do |splitted_image| + splitted_image.bytes.to_s + end + assert_equal([ + spliited_data[0].join(""), + spliited_data[1].join(""), + spliited_data[2].join(""), + spliited_data[3].join(""), + ], + splitted_image_data) + end end end From c4e7a0684f670c1ff50ffef74f9baf367926a692 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 26 Feb 2022 01:09:01 +0900 Subject: [PATCH 03/18] Implement median_blur --- opencv-glib/image-error.h | 1 + opencv-glib/image.cpp | 18 ++++++++++++++---- opencv-glib/image.h | 4 +++- test/test-image.rb | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/opencv-glib/image-error.h b/opencv-glib/image-error.h index cd1e306..2aab625 100644 --- a/opencv-glib/image-error.h +++ b/opencv-glib/image-error.h @@ -18,6 +18,7 @@ typedef enum { GCV_IMAGE_ERROR_READ, GCV_IMAGE_ERROR_WRITE, GCV_IMAGE_ERROR_UNKNOWN, + GCV_IMAGE_ERROR_FILTER, } GCVImageError; #define GCV_IMAGE_ERROR (gcv_image_error_quark()) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 1be0d0b..00ad700 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -691,6 +691,8 @@ gcv_image_split(GCVImage *image) /** * gcv_image_median_blur: * @image: A #GCVImage. + * @ksize: Aperture linear size; it must be odd and greater than 1 + * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects median blur image. The converted image is returned as * a new image. @@ -699,14 +701,22 @@ gcv_image_split(GCVImage *image) * * Since: 1.0.4 */ -GCVImage *gcv_image_median_blur(GCVImage *image) +GCVImage *gcv_image_median_blur(GCVImage *image, + gint ksize, + GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); auto cv_converted_image = std::make_shared(); - // TODO: * Use the arguments instead of static number. - // * Change blur instead of medianBlur. - cv::medianBlur(*cv_image, *cv_converted_image, 3); + if (ksize % 2 == 0 || ksize < 1) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "ksize must be odd and greater than 1"); + return NULL; + } + + cv::medianBlur(*cv_image, *cv_converted_image, ksize); return gcv_image_new_raw(&cv_converted_image); } diff --git a/opencv-glib/image.h b/opencv-glib/image.h index a4499f9..3bf6957 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -231,6 +231,8 @@ gcv_image_abs_diff(GCVImage *image, GList *gcv_image_split(GCVImage *image); -GCVImage *gcv_image_median_blur(GCVImage *image); +GCVImage *gcv_image_median_blur(GCVImage *image, + gint ksize, + GError **error); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index f37e49d..537a36d 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -339,5 +339,20 @@ def test_split ], splitted_image_data) end + + def test_median_blur + blur_image = @image.median_blur(7) + assert_not_equal(@image.bytes.to_s, + blur_image.bytes.to_s) + end + + def test_median_blur_invalid_argument + # ksize must be odd and greater than 1 + [-1,0,2].each do |n| + assert_raise(CV::ImageError::Filter) do + @image.median_blur(n) + end + end + end end end From 20e303e5128a6fc20ef297a113eae394d351170a Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 26 Feb 2022 10:17:21 +0900 Subject: [PATCH 04/18] Add GCV_IMAGE_FILTER comment --- opencv-glib/image-error.h | 1 + 1 file changed, 1 insertion(+) diff --git a/opencv-glib/image-error.h b/opencv-glib/image-error.h index 2aab625..c3e79d6 100644 --- a/opencv-glib/image-error.h +++ b/opencv-glib/image-error.h @@ -9,6 +9,7 @@ G_BEGIN_DECLS * @GCV_IMAGE_ERROR_READ: Read error. * @GCV_IMAGE_ERROR_WRITE: Write error. * @GCV_IMAGE_ERROR_UNKNOWN: Unknown error. + * @GCV_IMAGE_ERROR_FILTER: Filter error. * * Image related errors. * From 7eb9c43a3d59d0f7305611cd006ee9ba1bcfbef9 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 26 Feb 2022 10:17:26 +0900 Subject: [PATCH 05/18] Check image filter error message --- opencv-glib/image.cpp | 3 ++- test/test-image.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 00ad700..68ed77f 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -712,7 +712,8 @@ GCVImage *gcv_image_median_blur(GCVImage *image, g_set_error(error, GCV_IMAGE_ERROR, GCV_IMAGE_ERROR_FILTER, - "ksize must be odd and greater than 1"); + "ksize must be odd and greater than 1: <%d>", + ksize); return NULL; } diff --git a/test/test-image.rb b/test/test-image.rb index 537a36d..b9e8073 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -346,12 +346,12 @@ def test_median_blur blur_image.bytes.to_s) end - def test_median_blur_invalid_argument - # ksize must be odd and greater than 1 - [-1,0,2].each do |n| - assert_raise(CV::ImageError::Filter) do - @image.median_blur(n) - end + data(:ksize, [-1, 0, 2]) + def test_median_blur_invalid_argument(data) + ksize = data[:ksize] + message = "ksize must be odd and greater than 1: <#{ksize}>" + assert_raise(CV::ImageError::Filter.new(message)) do + @image.median_blur(ksize) end end end From 488b12645859024ac80482bba86e2efa8ff7eb9f Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 26 Feb 2022 10:22:00 +0900 Subject: [PATCH 06/18] Remove unrelated blank line --- opencv-glib/image.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 68ed77f..1a9b66e 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -732,4 +732,3 @@ gcv_image_new_raw(std::shared_ptr *cv_matrix) NULL); return GCV_IMAGE(matrix); } - From c2a0815a158789da448c741efb3e2d06dcd2e39a Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 27 Feb 2022 01:37:52 +0900 Subject: [PATCH 07/18] Add image_filtering_options --- opencv-glib/image.cpp | 268 ++++++++++++++++++++++++++++++++++++++++++ opencv-glib/image.h | 56 ++++++++- test/test-image.rb | 10 ++ 3 files changed, 333 insertions(+), 1 deletion(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 1a9b66e..4d9848f 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -201,6 +201,274 @@ gcv_drawing_options_new(void) return GCV_DRAWING_OPTIONS(g_object_new(GCV_TYPE_DRAWING_OPTIONS, NULL)); } +/*************************************/ + +typedef struct { + gboolean normalize; +// const Scalar &borderValue=morphologyDefaultBorderValue() +// const Size &dstsize=Size() + gdouble delta; + gdouble psi; + gdouble scale; + gdouble sigma_y; + gint border_type; + gint iterations; + gint ksize; +// gint ktype; + gint max_level; + GCVPoint anchor; +// TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) +} GCVImageFilteringOptionsPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE(GCVImageFilteringOptions, + gcv_image_filtering_options, + G_TYPE_OBJECT) + +#define GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object) \ + static_cast( \ + gcv_image_filtering_options_get_instance_private( \ + GCV_IMAGE_FILTERING_OPTIONS(object))) + +// TODO +enum { + PROP_NORMALIZE = 1, + PROP_BORDER_VALUE, + PROP_DSTSIZE, + PROP_DELTA, + PROP_PSI, + PROP_SCALE, + PROP_SIGMA_Y, + PROP_BORDER_TYPE, + PROP_ITERATIONS, + PROP_KSIZE, + PROP_KTYPE, + PROP_MAX_LEVEL, + PROP_ANCHOR, +}; + +static void +gcv_image_filtering_options_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_NORMALIZE: + g_value_set_boolean(value, priv->normalize); + break; +/* TODO + case PROP_BORDER_VALUE: + g_value_set_XXX(value, priv->border_value); + break; + case PROP_DSTSIZE: + g_value_set_XXX(value, priv->dstsize); + break; +*/ + case PROP_DELTA: + g_value_set_double(value, priv->delta); + break; + case PROP_PSI: + g_value_set_double(value, priv->psi); + break; + case PROP_SCALE: + g_value_set_double(value, priv->scale); + break; + case PROP_SIGMA_Y: + g_value_set_double(value, priv->sigma_y); + break; + case PROP_BORDER_TYPE: + g_value_set_enum(value, priv->border_type); + break; + case PROP_ITERATIONS: + g_value_set_int(value, priv->iterations); + break; + case PROP_KSIZE: + g_value_set_int(value, priv->ksize); + break; +/* + case PROP_KTYPE: + g_value_set_int(value, priv->ktype); + break; +*/ + case PROP_MAX_LEVEL: + g_value_set_int(value, priv->max_level); + break; +/* + case PROP_ANCHOR: + g_value_set_XXX(value, priv->anchor); + break; +*/ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + +} + +static void +gcv_image_filtering_options_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_NORMALIZE: + priv->normalize = g_value_get_boolean(value); + break; +/* TODO + case PROP_BORDER_VALUE: + priv->border_value = g_value_get_XXX(value); + break; + case PROP_DSTSIZE: + priv->dstsize = g_value_get_XXX(value); + break; +*/ + case PROP_DELTA: + priv->delta = g_value_get_double(value); + break; + case PROP_PSI: + priv->psi = g_value_get_double(value); + break; + case PROP_SCALE: + priv->scale = g_value_get_double(value); + break; + case PROP_SIGMA_Y: + priv->sigma_y = g_value_get_double(value); + break; + case PROP_BORDER_TYPE: + priv->border_type = static_cast(g_value_get_enum(value)); + break; + case PROP_ITERATIONS: + priv->iterations = g_value_get_int(value); + break; + case PROP_KSIZE: + priv->ksize = g_value_get_int(value); + break; +/* + case PROP_KTYPE: + priv->ktype = g_value_get_int(value); + break; +*/ + case PROP_MAX_LEVEL: + priv->max_level = g_value_get_int(value); + break; +/* + case PROP_ANCHOR: + priv->anchor = g_value_get_XXX(value); + break; +*/ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + + +static void +gcv_image_filtering_options_init(GCVImageFilteringOptions *object) +{ +} + +static void +gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) +{ + GParamSpec *spec; + + auto gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = gcv_image_filtering_options_get_property; + gobject_class->set_property = gcv_image_filtering_options_set_property; + + spec = g_param_spec_double("delta", + "Delta", + "Delta TODO", + 0, G_MAXDOUBLE, 0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_DELTA, spec); + +/* + spec = g_param_spec_double("psi", + "Psi", + "PSI TODO", + 0, G_MAXDOUBLE, cv::CV_PI * 0.5, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_PSI, spec); +*/ + + spec = g_param_spec_double("scale", + "Scale", + "Scale TODO", + 0, G_MAXDOUBLE, 1.0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_SCALE, spec); + + spec = g_param_spec_double("sigmaY", + "Sigma Y", + "sigmaY TODO", + 0, G_MAXDOUBLE, 0.0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_SIGMA_Y, spec); + + spec = g_param_spec_enum("border-type", + "Border type", + "The type of border to be filter", + GCV_TYPE_BORDER_TYPE, + GCV_BORDER_TYPE_BORDER_DEFAULT, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_BORDER_TYPE, spec); + + spec = g_param_spec_int("iterations", + "Iterations", + "The number of iterations", + 0, G_MAXINT, 1, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_ITERATIONS, spec); + + spec = g_param_spec_int("ksize", + "Ksize", + "KSize", // TODO + 0, G_MAXINT, 1, // TODO + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_KSIZE, spec); + + spec = g_param_spec_int("max-level", + "Max Level", + "Max Level", // TODO + 0, G_MAXINT, 1, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_MAX_LEVEL, spec); + + +} + +/** + * gcv_image_filtering_options_new: + * + * Returns a newly created #GCVImageFilteringOptions. + * + * Since: 1.0.2 + */ +GCVImageFilteringOptions * +gcv_image_filtering_options_new(void) +{ + return GCV_IMAGE_FILTERING_OPTIONS(g_object_new(GCV_TYPE_IMAGE_FILTERING_OPTIONS, + NULL)); +} + +/***************************** end *******************/ + G_DEFINE_TYPE(GCVImage, gcv_image, GCV_TYPE_MATRIX) static void diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 3bf6957..18825a3 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -110,6 +110,60 @@ struct _GCVDrawingOptionsClass GCVDrawingOptions *gcv_drawing_options_new(void); +/**********************************************/ + +/** + * GCVBorderTypes: + * @GCV_BORDER_TYPE_BORDER_CONSTANT: See `cv::BorderTypes::BORDER_CONSTANT`. + * @GCV_BORDER_TYPE_BORDER_REPLICATE : See `cv::BorderTypes::BORDER_REPLICATE `. + * @GCV_BORDER_TYPE_BORDER_REFLECT : See `cv::BorderTypes::BORDER_REFLECT `. + * @GCV_BORDER_TYPE_BORDER_WRAP : See `cv::BorderTypes::BORDER_WRAP `. + * @GCV_BORDER_TYPE_BORDER_REFLECT_101 : See `cv::BorderTypes::BORDER_REFLECT_101 `. + * @GCV_BORDER_TYPE_BORDER_TRANSPARENT : See `cv::BorderTypes::BORDER_TRANSPARENT `. + * @GCV_BORDER_TYPE_BORDER_REFLECT101 : See `cv::BorderTypes::BORDER_REFLECT101 `. + * @GCV_BORDER_TYPE_BORDER_DEFAULT : See `cv::BorderTypes::BORDER_DEFAULT `. + * @GCV_BORDER_TYPE_BORDER_ISOLATED : See `cv::BorderTypes::BORDER_ISOLATED `. + * + * Line type for drawing functions corresponding to `cv::BorderTypes`. + * + * See also [OpenCV documents](https://docs.opencv.org/). + * + * We don't have a link to the latest `cv::border_types` document. + * But we can link to a specific version: + * [OpenCV `cv::border_types`](). + * + * Since 1.0.2 + */ +typedef enum { + GCV_BORDER_TYPE_BORDER_CONSTANT = 0, + GCV_BORDER_TYPE_BORDER_REPLICATE = 1, + GCV_BORDER_TYPE_BORDER_REFLECT = 2, + GCV_BORDER_TYPE_BORDER_WRAP = 3, + GCV_BORDER_TYPE_BORDER_REFLECT_101 = 4, + GCV_BORDER_TYPE_BORDER_TRANSPARENT = 5, + GCV_BORDER_TYPE_BORDER_REFLECT101 = 6, + GCV_BORDER_TYPE_BORDER_DEFAULT = 7, + GCV_BORDER_TYPE_BORDER_ISOLATED = 8 +} GCVBorderType; + +#define GCV_TYPE_IMAGE_FILTERING_OPTIONS (gcv_image_filtering_options_get_type()) +G_DECLARE_DERIVABLE_TYPE(GCVImageFilteringOptions, + gcv_image_filtering_options, + GCV, + IMAGE_FILTERING_OPTIONS, + GObject) + +struct _GCVImageFilteringOptionsClass +{ + GObjectClass parent_class; +}; + +GCVImageFilteringOptions *gcv_image_filtering_options_new(void); + + +/**********************************************/ + + /** * GCVImageReadFlags: * @GCV_IMAGE_READ_FLAG_UNCHANGED: See `cv::IMREAD_UNCHANGED`. @@ -143,7 +197,7 @@ GCVDrawingOptions *gcv_drawing_options_new(void); * But we can link to a specific version: * [OpenCV 3.4.1's `cv::ImreadModes`](https://docs.opencv.org/3.4.1/d4/da8/group__imgcodecs.html#ga61d9b0126a3e57d9277ac48327799c80). * - * Since: 1.0.0 + * Since: 1.0.4 */ typedef enum { /*< flags >*/ GCV_IMAGE_READ_FLAG_UNCHANGED = -1, diff --git a/test/test-image.rb b/test/test-image.rb index b9e8073..d117f56 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -353,6 +353,16 @@ def test_median_blur_invalid_argument(data) assert_raise(CV::ImageError::Filter.new(message)) do @image.median_blur(ksize) end + + end + def test_image_filtering_options + options = CV::ImageFilteringOptions.new + options.delta + options.scale + options.iterations + options.max_level +# options.sigma_y +p options.border_type end end end From b686f185f8d183b83511f67ce5ca03b4c1429a51 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 27 Feb 2022 23:31:14 +0900 Subject: [PATCH 08/18] wip --- opencv-glib/image.cpp | 34 ++++++++++++++++++++++++++++++++++ opencv-glib/image.h | 4 ++++ test/test-image.rb | 8 ++++++++ 3 files changed, 46 insertions(+) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 4d9848f..31e24bf 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -990,6 +990,40 @@ GCVImage *gcv_image_median_blur(GCVImage *image, return gcv_image_new_raw(&cv_converted_image); } +/** + * gcv_image_blur: + * @image: A #GCVImage. + * @ksize: A #GCVSize blurring kernel size. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * It effects blur image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_blur(GCVImage *image, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_ksize = gcv_size_get_raw(ksize); + auto cv_converted_image = std::make_shared(); + + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + + cv::blur(*cv_image, *cv_converted_image, *cv_ksize, NULL, options_priv->border_type); + } else { + cv::blur(*cv_image, *cv_converted_image, *cv_ksize); + } + + return gcv_image_new_raw(&cv_converted_image); +} + G_END_DECLS GCVImage * diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 18825a3..da23918 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -289,4 +289,8 @@ GCVImage *gcv_image_median_blur(GCVImage *image, gint ksize, GError **error); +GCVImage *gcv_image_blur(GCVImage *image, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index d117f56..0ebff56 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -364,5 +364,13 @@ def test_image_filtering_options # options.sigma_y p options.border_type end + + def test_blur + size = CV::Size.new(10, 8) + blur_image = @image.blur(size) + blur_image = @image.blur(size,CV::ImageFilteringOptions.new) + assert_not_equal(@image.bytes.to_s, + blur_image.bytes.to_s) + end end end From 527222102d9728690e2db88fed54f6a4b4e74104 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 27 Feb 2022 01:37:52 +0900 Subject: [PATCH 09/18] Add image_filtering_options --- opencv-glib/image.cpp | 268 ++++++++++++++++++++++++++++++++++++++++++ opencv-glib/image.h | 56 ++++++++- test/test-image.rb | 10 ++ 3 files changed, 333 insertions(+), 1 deletion(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 1a9b66e..4d9848f 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -201,6 +201,274 @@ gcv_drawing_options_new(void) return GCV_DRAWING_OPTIONS(g_object_new(GCV_TYPE_DRAWING_OPTIONS, NULL)); } +/*************************************/ + +typedef struct { + gboolean normalize; +// const Scalar &borderValue=morphologyDefaultBorderValue() +// const Size &dstsize=Size() + gdouble delta; + gdouble psi; + gdouble scale; + gdouble sigma_y; + gint border_type; + gint iterations; + gint ksize; +// gint ktype; + gint max_level; + GCVPoint anchor; +// TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) +} GCVImageFilteringOptionsPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE(GCVImageFilteringOptions, + gcv_image_filtering_options, + G_TYPE_OBJECT) + +#define GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object) \ + static_cast( \ + gcv_image_filtering_options_get_instance_private( \ + GCV_IMAGE_FILTERING_OPTIONS(object))) + +// TODO +enum { + PROP_NORMALIZE = 1, + PROP_BORDER_VALUE, + PROP_DSTSIZE, + PROP_DELTA, + PROP_PSI, + PROP_SCALE, + PROP_SIGMA_Y, + PROP_BORDER_TYPE, + PROP_ITERATIONS, + PROP_KSIZE, + PROP_KTYPE, + PROP_MAX_LEVEL, + PROP_ANCHOR, +}; + +static void +gcv_image_filtering_options_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_NORMALIZE: + g_value_set_boolean(value, priv->normalize); + break; +/* TODO + case PROP_BORDER_VALUE: + g_value_set_XXX(value, priv->border_value); + break; + case PROP_DSTSIZE: + g_value_set_XXX(value, priv->dstsize); + break; +*/ + case PROP_DELTA: + g_value_set_double(value, priv->delta); + break; + case PROP_PSI: + g_value_set_double(value, priv->psi); + break; + case PROP_SCALE: + g_value_set_double(value, priv->scale); + break; + case PROP_SIGMA_Y: + g_value_set_double(value, priv->sigma_y); + break; + case PROP_BORDER_TYPE: + g_value_set_enum(value, priv->border_type); + break; + case PROP_ITERATIONS: + g_value_set_int(value, priv->iterations); + break; + case PROP_KSIZE: + g_value_set_int(value, priv->ksize); + break; +/* + case PROP_KTYPE: + g_value_set_int(value, priv->ktype); + break; +*/ + case PROP_MAX_LEVEL: + g_value_set_int(value, priv->max_level); + break; +/* + case PROP_ANCHOR: + g_value_set_XXX(value, priv->anchor); + break; +*/ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + +} + +static void +gcv_image_filtering_options_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_NORMALIZE: + priv->normalize = g_value_get_boolean(value); + break; +/* TODO + case PROP_BORDER_VALUE: + priv->border_value = g_value_get_XXX(value); + break; + case PROP_DSTSIZE: + priv->dstsize = g_value_get_XXX(value); + break; +*/ + case PROP_DELTA: + priv->delta = g_value_get_double(value); + break; + case PROP_PSI: + priv->psi = g_value_get_double(value); + break; + case PROP_SCALE: + priv->scale = g_value_get_double(value); + break; + case PROP_SIGMA_Y: + priv->sigma_y = g_value_get_double(value); + break; + case PROP_BORDER_TYPE: + priv->border_type = static_cast(g_value_get_enum(value)); + break; + case PROP_ITERATIONS: + priv->iterations = g_value_get_int(value); + break; + case PROP_KSIZE: + priv->ksize = g_value_get_int(value); + break; +/* + case PROP_KTYPE: + priv->ktype = g_value_get_int(value); + break; +*/ + case PROP_MAX_LEVEL: + priv->max_level = g_value_get_int(value); + break; +/* + case PROP_ANCHOR: + priv->anchor = g_value_get_XXX(value); + break; +*/ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + + +static void +gcv_image_filtering_options_init(GCVImageFilteringOptions *object) +{ +} + +static void +gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) +{ + GParamSpec *spec; + + auto gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = gcv_image_filtering_options_get_property; + gobject_class->set_property = gcv_image_filtering_options_set_property; + + spec = g_param_spec_double("delta", + "Delta", + "Delta TODO", + 0, G_MAXDOUBLE, 0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_DELTA, spec); + +/* + spec = g_param_spec_double("psi", + "Psi", + "PSI TODO", + 0, G_MAXDOUBLE, cv::CV_PI * 0.5, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_PSI, spec); +*/ + + spec = g_param_spec_double("scale", + "Scale", + "Scale TODO", + 0, G_MAXDOUBLE, 1.0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_SCALE, spec); + + spec = g_param_spec_double("sigmaY", + "Sigma Y", + "sigmaY TODO", + 0, G_MAXDOUBLE, 0.0, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_SIGMA_Y, spec); + + spec = g_param_spec_enum("border-type", + "Border type", + "The type of border to be filter", + GCV_TYPE_BORDER_TYPE, + GCV_BORDER_TYPE_BORDER_DEFAULT, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_BORDER_TYPE, spec); + + spec = g_param_spec_int("iterations", + "Iterations", + "The number of iterations", + 0, G_MAXINT, 1, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_ITERATIONS, spec); + + spec = g_param_spec_int("ksize", + "Ksize", + "KSize", // TODO + 0, G_MAXINT, 1, // TODO + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_KSIZE, spec); + + spec = g_param_spec_int("max-level", + "Max Level", + "Max Level", // TODO + 0, G_MAXINT, 1, + static_cast(G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + g_object_class_install_property(gobject_class, PROP_MAX_LEVEL, spec); + + +} + +/** + * gcv_image_filtering_options_new: + * + * Returns a newly created #GCVImageFilteringOptions. + * + * Since: 1.0.2 + */ +GCVImageFilteringOptions * +gcv_image_filtering_options_new(void) +{ + return GCV_IMAGE_FILTERING_OPTIONS(g_object_new(GCV_TYPE_IMAGE_FILTERING_OPTIONS, + NULL)); +} + +/***************************** end *******************/ + G_DEFINE_TYPE(GCVImage, gcv_image, GCV_TYPE_MATRIX) static void diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 3bf6957..18825a3 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -110,6 +110,60 @@ struct _GCVDrawingOptionsClass GCVDrawingOptions *gcv_drawing_options_new(void); +/**********************************************/ + +/** + * GCVBorderTypes: + * @GCV_BORDER_TYPE_BORDER_CONSTANT: See `cv::BorderTypes::BORDER_CONSTANT`. + * @GCV_BORDER_TYPE_BORDER_REPLICATE : See `cv::BorderTypes::BORDER_REPLICATE `. + * @GCV_BORDER_TYPE_BORDER_REFLECT : See `cv::BorderTypes::BORDER_REFLECT `. + * @GCV_BORDER_TYPE_BORDER_WRAP : See `cv::BorderTypes::BORDER_WRAP `. + * @GCV_BORDER_TYPE_BORDER_REFLECT_101 : See `cv::BorderTypes::BORDER_REFLECT_101 `. + * @GCV_BORDER_TYPE_BORDER_TRANSPARENT : See `cv::BorderTypes::BORDER_TRANSPARENT `. + * @GCV_BORDER_TYPE_BORDER_REFLECT101 : See `cv::BorderTypes::BORDER_REFLECT101 `. + * @GCV_BORDER_TYPE_BORDER_DEFAULT : See `cv::BorderTypes::BORDER_DEFAULT `. + * @GCV_BORDER_TYPE_BORDER_ISOLATED : See `cv::BorderTypes::BORDER_ISOLATED `. + * + * Line type for drawing functions corresponding to `cv::BorderTypes`. + * + * See also [OpenCV documents](https://docs.opencv.org/). + * + * We don't have a link to the latest `cv::border_types` document. + * But we can link to a specific version: + * [OpenCV `cv::border_types`](). + * + * Since 1.0.2 + */ +typedef enum { + GCV_BORDER_TYPE_BORDER_CONSTANT = 0, + GCV_BORDER_TYPE_BORDER_REPLICATE = 1, + GCV_BORDER_TYPE_BORDER_REFLECT = 2, + GCV_BORDER_TYPE_BORDER_WRAP = 3, + GCV_BORDER_TYPE_BORDER_REFLECT_101 = 4, + GCV_BORDER_TYPE_BORDER_TRANSPARENT = 5, + GCV_BORDER_TYPE_BORDER_REFLECT101 = 6, + GCV_BORDER_TYPE_BORDER_DEFAULT = 7, + GCV_BORDER_TYPE_BORDER_ISOLATED = 8 +} GCVBorderType; + +#define GCV_TYPE_IMAGE_FILTERING_OPTIONS (gcv_image_filtering_options_get_type()) +G_DECLARE_DERIVABLE_TYPE(GCVImageFilteringOptions, + gcv_image_filtering_options, + GCV, + IMAGE_FILTERING_OPTIONS, + GObject) + +struct _GCVImageFilteringOptionsClass +{ + GObjectClass parent_class; +}; + +GCVImageFilteringOptions *gcv_image_filtering_options_new(void); + + +/**********************************************/ + + /** * GCVImageReadFlags: * @GCV_IMAGE_READ_FLAG_UNCHANGED: See `cv::IMREAD_UNCHANGED`. @@ -143,7 +197,7 @@ GCVDrawingOptions *gcv_drawing_options_new(void); * But we can link to a specific version: * [OpenCV 3.4.1's `cv::ImreadModes`](https://docs.opencv.org/3.4.1/d4/da8/group__imgcodecs.html#ga61d9b0126a3e57d9277ac48327799c80). * - * Since: 1.0.0 + * Since: 1.0.4 */ typedef enum { /*< flags >*/ GCV_IMAGE_READ_FLAG_UNCHANGED = -1, diff --git a/test/test-image.rb b/test/test-image.rb index b9e8073..d117f56 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -353,6 +353,16 @@ def test_median_blur_invalid_argument(data) assert_raise(CV::ImageError::Filter.new(message)) do @image.median_blur(ksize) end + + end + def test_image_filtering_options + options = CV::ImageFilteringOptions.new + options.delta + options.scale + options.iterations + options.max_level +# options.sigma_y +p options.border_type end end end From 5ca4cfa1d23bc1c83e1468da884bc3483ec0dd8c Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 27 Feb 2022 23:31:14 +0900 Subject: [PATCH 10/18] wip --- opencv-glib/image.cpp | 34 ++++++++++++++++++++++++++++++++++ opencv-glib/image.h | 4 ++++ test/test-image.rb | 8 ++++++++ 3 files changed, 46 insertions(+) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 4d9848f..adc30fd 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -990,6 +990,40 @@ GCVImage *gcv_image_median_blur(GCVImage *image, return gcv_image_new_raw(&cv_converted_image); } +/** + * gcv_image_blur: + * @image: A #GCVImage. + * @ksize: A #GCVSize blurring kernel size. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * It effects blur image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_blur(GCVImage *image, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_ksize = gcv_size_get_raw(ksize); + auto cv_converted_image = std::make_shared(); + + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + + cv::blur(*cv_image, *cv_converted_image, *cv_ksize, NULL, options_priv->border_type); + } else { + cv::blur(*cv_image, *cv_converted_image, *cv_ksize); + } + + return gcv_image_new_raw(&cv_converted_image); +} + G_END_DECLS GCVImage * diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 18825a3..da23918 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -289,4 +289,8 @@ GCVImage *gcv_image_median_blur(GCVImage *image, gint ksize, GError **error); +GCVImage *gcv_image_blur(GCVImage *image, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index d117f56..0ebff56 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -364,5 +364,13 @@ def test_image_filtering_options # options.sigma_y p options.border_type end + + def test_blur + size = CV::Size.new(10, 8) + blur_image = @image.blur(size) + blur_image = @image.blur(size,CV::ImageFilteringOptions.new) + assert_not_equal(@image.bytes.to_s, + blur_image.bytes.to_s) + end end end From 1942609320e32f2ea4e3763023b6251aaca5b4cb Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Thu, 3 Mar 2022 00:35:35 +0900 Subject: [PATCH 11/18] Apply kou's review --- opencv-glib/image.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 31e24bf..6dfd8bc 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -216,7 +216,7 @@ typedef struct { gint ksize; // gint ktype; gint max_level; - GCVPoint anchor; + GCVPoint *anchor; // TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) } GCVImageFilteringOptionsPrivate; @@ -295,11 +295,9 @@ gcv_image_filtering_options_get_property(GObject *object, case PROP_MAX_LEVEL: g_value_set_int(value, priv->max_level); break; -/* case PROP_ANCHOR: - g_value_set_XXX(value, priv->anchor); + g_value_set_object(value, priv->anchor); break; -*/ default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -356,11 +354,22 @@ gcv_image_filtering_options_set_property(GObject *object, case PROP_MAX_LEVEL: priv->max_level = g_value_get_int(value); break; -/* case PROP_ANCHOR: - priv->anchor = g_value_get_XXX(value); + { + auto anchor = g_value_get_object(value); + if (priv->anchor && priv->anchor == anchor) { + break; + } + if (priv->anchor) { + g_object_unref(priv->anchor); + } + if (anchor) { + priv->anchor = GCV_POINT(g_object_ref(anchor)); + } else { + priv->anchor = NULL; + } + } break; -*/ default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -450,7 +459,12 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) G_PARAM_CONSTRUCT)); g_object_class_install_property(gobject_class, PROP_MAX_LEVEL, spec); - + spec = g_param_spec_object("anchor", + "Anchor", + "Anchor", // TODO + GCV_TYPE_POINT, + static_cast(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_ANCHOR, spec); } /** @@ -1016,7 +1030,12 @@ GCVImage *gcv_image_blur(GCVImage *image, if ( options != NULL ) { auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); - cv::blur(*cv_image, *cv_converted_image, *cv_ksize, NULL, options_priv->border_type); + auto anchor = cv::Point(-1, -1); + if (options_priv->anchor) { + anchor = *gcv_point_get_raw(options_priv->anchor); + } + cv::blur(*cv_image, *cv_converted_image, *cv_ksize, anchor, options_priv->border_type); + } else { cv::blur(*cv_image, *cv_converted_image, *cv_ksize); } From 67f3703cf30825132dc4d2d516d1aba4b7f888a6 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Thu, 3 Mar 2022 00:45:06 +0900 Subject: [PATCH 12/18] wip --- opencv-glib/image.cpp | 65 ++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 6dfd8bc..f4e7777 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -394,10 +394,9 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) spec = g_param_spec_double("delta", "Delta", - "Delta TODO", + "added to the filtered pixels before storing them in dst.", 0, G_MAXDOUBLE, 0, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_DELTA, spec); /* @@ -405,8 +404,7 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) "Psi", "PSI TODO", 0, G_MAXDOUBLE, cv::CV_PI * 0.5, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_PSI, spec); */ @@ -414,16 +412,14 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) "Scale", "Scale TODO", 0, G_MAXDOUBLE, 1.0, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_SCALE, spec); spec = g_param_spec_double("sigmaY", "Sigma Y", "sigmaY TODO", 0, G_MAXDOUBLE, 0.0, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_SIGMA_Y, spec); spec = g_param_spec_enum("border-type", @@ -431,32 +427,28 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) "The type of border to be filter", GCV_TYPE_BORDER_TYPE, GCV_BORDER_TYPE_BORDER_DEFAULT, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_BORDER_TYPE, spec); spec = g_param_spec_int("iterations", "Iterations", "The number of iterations", 0, G_MAXINT, 1, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_ITERATIONS, spec); spec = g_param_spec_int("ksize", "Ksize", "KSize", // TODO 0, G_MAXINT, 1, // TODO - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_KSIZE, spec); spec = g_param_spec_int("max-level", "Max Level", "Max Level", // TODO 0, G_MAXINT, 1, - static_cast(G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_MAX_LEVEL, spec); spec = g_param_spec_object("anchor", @@ -1043,6 +1035,45 @@ GCVImage *gcv_image_blur(GCVImage *image, return gcv_image_new_raw(&cv_converted_image); } +/** + * gcv_image_laplacian: + * @image: A #GCVImage. + * @ddepth: Desired depth of the destination image. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * It effects laplacian image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_laplacian(GCVImage *image, + int *ddepth, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_ksize = gcv_size_get_raw(ksize); + auto cv_converted_image = std::make_shared(); + + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + + auto anchor = cv::Point(-1, -1); + if (options_priv->anchor) { + anchor = *gcv_point_get_raw(options_priv->anchor); + } + cv::blur(*cv_image, *cv_converted_image, *cv_ksize, anchor, options_priv->border_type); + + } else { + cv::blur(*cv_image, *cv_converted_image, *cv_ksize); + } + + return gcv_image_new_raw(&cv_converted_image); +} + G_END_DECLS GCVImage * From 3a50f21ece219277104561050f96b140906103d0 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Fri, 4 Mar 2022 01:27:27 +0900 Subject: [PATCH 13/18] Laplacian --- opencv-glib/image.cpp | 23 ++++++++++------------- opencv-glib/image.h | 4 ++++ test/test-image.rb | 11 +++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index f4e7777..351c8f6 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -1021,7 +1021,7 @@ GCVImage *gcv_image_blur(GCVImage *image, if ( options != NULL ) { auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); - + auto anchor = cv::Point(-1, -1); if (options_priv->anchor) { anchor = *gcv_point_get_raw(options_priv->anchor); @@ -1040,7 +1040,6 @@ GCVImage *gcv_image_blur(GCVImage *image, * @image: A #GCVImage. * @ddepth: Desired depth of the destination image. * @options: (nullable): A #GCVImageFilteringOptions; - * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects laplacian image. The converted image is returned as * a new image. @@ -1050,25 +1049,23 @@ GCVImage *gcv_image_blur(GCVImage *image, * Since: 1.0.4 */ GCVImage *gcv_image_laplacian(GCVImage *image, - int *ddepth, - GCVImageFilteringOptions *options, - GError **error) + int ddepth, + GCVImageFilteringOptions *options) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); - auto cv_ksize = gcv_size_get_raw(ksize); auto cv_converted_image = std::make_shared(); if ( options != NULL ) { auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); - - auto anchor = cv::Point(-1, -1); - if (options_priv->anchor) { - anchor = *gcv_point_get_raw(options_priv->anchor); - } - cv::blur(*cv_image, *cv_converted_image, *cv_ksize, anchor, options_priv->border_type); + int ksize = options_priv->ksize; + double scale = options_priv->scale; + double delta = options_priv->delta; + int border_type = options_priv->border_type; + cv::Laplacian(*cv_image, *cv_converted_image, + ddepth, ksize, scale, delta, border_type); } else { - cv::blur(*cv_image, *cv_converted_image, *cv_ksize); + cv::Laplacian(*cv_image, *cv_converted_image, ddepth); } return gcv_image_new_raw(&cv_converted_image); diff --git a/opencv-glib/image.h b/opencv-glib/image.h index da23918..322bf28 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -293,4 +293,8 @@ GCVImage *gcv_image_blur(GCVImage *image, GCVSize *ksize, GCVImageFilteringOptions *options, GError **error); + +GCVImage *gcv_image_laplacian(GCVImage *image, + int ddepth, + GCVImageFilteringOptions *options); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index 0ebff56..428dfe8 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -372,5 +372,16 @@ def test_blur assert_not_equal(@image.bytes.to_s, blur_image.bytes.to_s) end + + def test_laplacian + ddepth = 5 + filtered_image = @image.laplacian(ddepth) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + + filtered_image = @image.blur(size,CV::ImageFilteringOptions.new) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + end end end From 4c729507c40969a5cd3f6fbd17b98f8da492dbff Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 6 Mar 2022 01:13:58 +0900 Subject: [PATCH 14/18] Add more filters --- opencv-glib/image.cpp | 340 ++++++++++++++++++++++++++++++++++++++++-- opencv-glib/image.h | 34 ++++- test/test-image.rb | 34 ++++- 3 files changed, 395 insertions(+), 13 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 351c8f6..03da523 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -962,6 +962,56 @@ gcv_image_split(GCVImage *image) return g_list_reverse(values); } +/** + * gcv_image_bilateral_filter: + * @image: A #GCVImage. + * @d: Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace. + * @sigma_color: Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting in larger areas of semi-equal color. + * @sigma_space: Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is proportional to sigmaSpace. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * It effects bilateral filter image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_bilateral_filter(GCVImage *image, + int d, + double sigma_color, + double sigma_space, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int border_type = options_priv->border_type; + + cv::bilateralFilter(*cv_image, *cv_converted_image, + d, sigma_color, sigma_space, border_type); + } else { + cv::bilateralFilter(*cv_image, *cv_converted_image, + d, sigma_color, sigma_space); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + + return gcv_image_new_raw(&cv_converted_image); +} + /** * gcv_image_median_blur: * @image: A #GCVImage. @@ -1035,11 +1085,217 @@ GCVImage *gcv_image_blur(GCVImage *image, return gcv_image_new_raw(&cv_converted_image); } +/** + * gcv_image_box_filter: + * @image: A #GCVImage. + * @ddepth: the output image depth + * @ksize: blurring kernel size. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * HOGE + * It effects box filter image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_box_filter(GCVImage *image, + int ddepth, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_ksize = gcv_size_get_raw(ksize); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + bool normalize = true; + int border_type = options_priv->border_type; + auto anchor = cv::Point(-1,-1); + if (options_priv->anchor) { + anchor = *gcv_point_get_raw(options_priv->anchor); + } + cv::boxFilter(*cv_image, *cv_converted_image, ddepth, + *cv_ksize, anchor, normalize, border_type); + } else { + cv::boxFilter(*cv_image, *cv_converted_image, ddepth, *cv_ksize); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + return gcv_image_new_raw(&cv_converted_image); +} + +/** + * gcv_image_build_pyramid: + * @image: A #GCVImage. + * @max_level: 0-based index of the last (the smallest) pyramid layer. It must be non-negative. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * Constructs the Gaussian pyramid for an image + * The converted image is returned as a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_build_pyramid(GCVImage *image, + int max_level, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int border_type = options_priv->border_type; + + cv::buildPyramid(*cv_image, *cv_converted_image, + max_level, border_type); + } else { + cv::buildPyramid(*cv_image, *cv_converted_image,max_level); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + + return gcv_image_new_raw(&cv_converted_image); +} + + +/** + * gcv_image_dilate: + * @image: A #GCVImage. + * @kernel: structuring element used for dilation. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * Constructs the dilate filter for an image + * The converted image is returned as a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +/* +GCVImage *gcv_image_dilate(GCVImage *image, + GCVMatrix *kernel, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_kernel = gcv_matrix_get_raw(GCV_MATRIX(kernel)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int iteration = options_priv->iteration; + int border_type = options_priv->border_type; + + auto anchor = cv::Point(-1,-1); + if (options_priv->anchor) { + anchor = *gcv_point_get_raw(options_priv->anchor); + } + + cv::dilate(*cv_image, *cv_converted_image, *cv_kernel, + anchor, iteration, border_type); + } else { + cv::dilate(*cv_image, *cv_converted_image, *cv_kernel); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + + return gcv_image_new_raw(&cv_converted_image); +} +*/ + +/** + * gcv_image_filter2d: + * @image: A #GCVImage. + * @ddepth: desired depth of the destination image, see combinations. + * @kernel: convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using split and process them individually. + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * Constructs the dilate filter for an image + * The converted image is returned as a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_filter2d(GCVImage *image, + int ddepth, + GCVMatrix *kernel, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_kernel = gcv_matrix_get_raw(GCV_MATRIX(kernel)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int delta = options_priv->delta; + int border_type = options_priv->border_type; + auto anchor = cv::Point(-1,-1); + + if (options_priv->anchor) { + anchor = *gcv_point_get_raw(options_priv->anchor); + } + + cv::filter2D(*cv_image, *cv_converted_image, ddepth, *cv_kernel, + anchor, delta, border_type); + } else { + cv::filter2D(*cv_image, *cv_converted_image, ddepth, *cv_kernel); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + return gcv_image_new_raw(&cv_converted_image); +} + /** * gcv_image_laplacian: * @image: A #GCVImage. * @ddepth: Desired depth of the destination image. * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects laplacian image. The converted image is returned as * a new image. @@ -1050,22 +1306,84 @@ GCVImage *gcv_image_blur(GCVImage *image, */ GCVImage *gcv_image_laplacian(GCVImage *image, int ddepth, - GCVImageFilteringOptions *options) + GCVImageFilteringOptions *options, + GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); auto cv_converted_image = std::make_shared(); - if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); - int ksize = options_priv->ksize; - double scale = options_priv->scale; - double delta = options_priv->delta; - int border_type = options_priv->border_type; - cv::Laplacian(*cv_image, *cv_converted_image, - ddepth, ksize, scale, delta, border_type); + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int ksize = options_priv->ksize; + double scale = options_priv->scale; + double delta = options_priv->delta; + int border_type = options_priv->border_type; + + cv::Laplacian(*cv_image, *cv_converted_image, + ddepth, ksize, scale, delta, border_type); + } else { + cv::Laplacian(*cv_image, *cv_converted_image, ddepth); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } - } else { - cv::Laplacian(*cv_image, *cv_converted_image, ddepth); + return gcv_image_new_raw(&cv_converted_image); +} + +/** + * gcv_image_sobel: + * @image: A #GCVImage. + * @ddepth: Desired depth of the destination image. + * @intx: Order of the derivative x + * @inty: Order of the derivative y + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * It effects sobel image. The converted image is returned as + * a new image. + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_sobel(GCVImage *image, + int ddepth, + int intx, + int inty, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + int ksize = options_priv->ksize; + double scale = options_priv->scale; + double delta = options_priv->delta; + int border_type = options_priv->border_type; + + cv::Sobel(*cv_image, *cv_converted_image, + ddepth, intx, inty, ksize, scale, delta, border_type); + + } else { + cv::Sobel(*cv_image, *cv_converted_image, ddepth, intx, inty); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; } return gcv_image_new_raw(&cv_converted_image); diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 322bf28..0cda97a 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -285,6 +285,25 @@ gcv_image_abs_diff(GCVImage *image, GList *gcv_image_split(GCVImage *image); +GCVImage *gcv_image_bilateral_filter(GCVImage *image, + int d, + double sigma_color, + double sigma_space, + GCVImageFilteringOptions *options, + GError **error); + +GCVImage *gcv_image_box_filter(GCVImage *image, + int ddepth, + GCVSize *ksize, + GCVImageFilteringOptions *options, + GError **error); + +GCVImage *gcv_image_filter2d(GCVImage *image, + int ddepth, + GCVMatrix *kernel, + GCVImageFilteringOptions *options, + GError **error); + GCVImage *gcv_image_median_blur(GCVImage *image, gint ksize, GError **error); @@ -294,7 +313,20 @@ GCVImage *gcv_image_blur(GCVImage *image, GCVImageFilteringOptions *options, GError **error); +GCVImage *gcv_image_build_pyramid(GCVImage *image, + int max_level, + GCVImageFilteringOptions *options, + GError **error); + GCVImage *gcv_image_laplacian(GCVImage *image, int ddepth, - GCVImageFilteringOptions *options); + GCVImageFilteringOptions *options, + GError **error); + +GCVImage *gcv_image_sobel(GCVImage *image, + int ddepth, + int intx, + int inty, + GCVImageFilteringOptions *options, + GError **error); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index 428dfe8..93758a5 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -379,9 +379,41 @@ def test_laplacian assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) - filtered_image = @image.blur(size,CV::ImageFilteringOptions.new) + options = CV::ImageFilteringOptions.new + options.ksize = 1 +# options.ksize = 0 + filtered_image = @image.laplacian(ddepth,options) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + end + + def test_filter2d + ddepth = -1 + filtered_image = @image.filter2d(ddepth,@image) assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) + + options = CV::ImageFilteringOptions.new + options.ksize = 1 +# options.ksize = 0 + filtered_image = @image.filter2d(ddepth,@image,options) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + end + + def test_sobel + ddepth = 5 + filtered_image = @image.sobel(ddepth,1,1) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + + options = CV::ImageFilteringOptions.new + # + options.ksize = 3 + filtered_image = @image.sobel(ddepth,1,1,options) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + end end end From f7ced6a25edd5a5a2ae060c2271ce653f54f2749 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 13 Mar 2022 19:41:55 +0900 Subject: [PATCH 15/18] Fix BorderType value --- opencv-glib/image.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 0cda97a..2031f21 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -141,9 +141,9 @@ typedef enum { GCV_BORDER_TYPE_BORDER_WRAP = 3, GCV_BORDER_TYPE_BORDER_REFLECT_101 = 4, GCV_BORDER_TYPE_BORDER_TRANSPARENT = 5, - GCV_BORDER_TYPE_BORDER_REFLECT101 = 6, - GCV_BORDER_TYPE_BORDER_DEFAULT = 7, - GCV_BORDER_TYPE_BORDER_ISOLATED = 8 + GCV_BORDER_TYPE_BORDER_REFLECT101 = GCV_BORDER_TYPE_BORDER_REFLECT_101, + GCV_BORDER_TYPE_BORDER_DEFAULT = GCV_BORDER_TYPE_BORDER_REFLECT_101, + GCV_BORDER_TYPE_BORDER_ISOLATED = 16 } GCVBorderType; #define GCV_TYPE_IMAGE_FILTERING_OPTIONS (gcv_image_filtering_options_get_type()) From e66cc937b5b39a1833090082171f31d764d43d55 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Mon, 14 Mar 2022 00:24:02 +0900 Subject: [PATCH 16/18] Add getDerivKernels --- opencv-glib/image.cpp | 74 +++++++++++++++++++++++++++++++++++++++---- opencv-glib/image.h | 29 +++++++++++++++++ test/test-image.rb | 20 ++++++++++++ 3 files changed, 116 insertions(+), 7 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 03da523..9a20e57 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -214,7 +214,8 @@ typedef struct { gint border_type; gint iterations; gint ksize; -// gint ktype; + GCVKType ktype; + //gint ktype; gint max_level; GCVPoint *anchor; // TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) @@ -287,11 +288,9 @@ gcv_image_filtering_options_get_property(GObject *object, case PROP_KSIZE: g_value_set_int(value, priv->ksize); break; -/* case PROP_KTYPE: - g_value_set_int(value, priv->ktype); + g_value_set_enum(value, priv->ktype); break; -*/ case PROP_MAX_LEVEL: g_value_set_int(value, priv->max_level); break; @@ -346,11 +345,9 @@ gcv_image_filtering_options_set_property(GObject *object, case PROP_KSIZE: priv->ksize = g_value_get_int(value); break; -/* case PROP_KTYPE: - priv->ktype = g_value_get_int(value); + priv->ktype = static_cast(g_value_get_enum(value)); break; -*/ case PROP_MAX_LEVEL: priv->max_level = g_value_get_int(value); break; @@ -392,6 +389,13 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) gobject_class->get_property = gcv_image_filtering_options_get_property; gobject_class->set_property = gcv_image_filtering_options_set_property; + spec = g_param_spec_boolean("normalize", + "Normalize", + "normalize", // TODO + FALSE, + static_cast(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_NORMALIZE, spec); + spec = g_param_spec_double("delta", "Delta", "added to the filtered pixels before storing them in dst.", @@ -444,6 +448,13 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) static_cast(G_PARAM_READWRITE)); g_object_class_install_property(gobject_class, PROP_KSIZE, spec); + spec = g_param_spec_enum("ktype", + "Ktype", + "KType", // TODO + GCV_TYPE_KTYPE, GCV_KTYPE_CV32F, // TODO + static_cast(G_PARAM_READWRITE)); + g_object_class_install_property(gobject_class, PROP_KTYPE, spec); + spec = g_param_spec_int("max-level", "Max Level", "Max Level", // TODO @@ -1290,6 +1301,55 @@ GCVImage *gcv_image_filter2d(GCVImage *image, return gcv_image_new_raw(&cv_converted_image); } +/** + * gcv_image_get_deriv_kernels: + * @image: A #GCVImage. + * @dx: TODO + * @dy: TODO + * @ksize: TODO + * @options: (nullable): A #GCVImageFilteringOptions; + * @error: (nullable): Return locatipcn for a #GError or %NULL. + * + * TODO + * + * Returns: (transfer full): A converted #GCVImage. + * + * Since: 1.0.4 + */ +GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, + int dx, + int dy, + int ksize, + GCVImageFilteringOptions *options, + GError **error) +{ + auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); + auto cv_converted_image = std::make_shared(); + + try { + if ( options != NULL ) { + auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + GCVKType ktype = options_priv->ktype; + gboolean normalize = options_priv->normalize; +printf("ktype: %d\n",ktype); + + cv::getDerivKernels(*cv_image, *cv_converted_image, dx, dy, ksize, + normalize, ktype); + } else { + cv::getDerivKernels(*cv_image, *cv_converted_image, dx, dy, ksize); + } + } catch (const cv::Exception &exception) { + g_set_error(error, + GCV_IMAGE_ERROR, + GCV_IMAGE_ERROR_FILTER, + "Failed to filter image: %s", + exception.what()); + return NULL; + } + + return gcv_image_new_raw(&cv_converted_image); +} + /** * gcv_image_laplacian: * @image: A #GCVImage. diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 2031f21..8670f31 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -160,6 +160,28 @@ struct _GCVImageFilteringOptionsClass GCVImageFilteringOptions *gcv_image_filtering_options_new(void); +/** + * GCVKrType: + * @GCV_KTYPE_CV_8U: TODO + * @GCV_KTYPE_CV_8S: TODO + * @GCV_KTYPE_CV_16U: TODO + * @GCV_KTYPE_CV_16S: TODO + * @GCV_KTYPE_CV_32S: TODO + * @GCV_KTYPE_CV_32F: TODO + * @GCV_KTYPE_CV_64F: TODO + * @GCV_KTYPE_CV_16F: TODO + * + */ +typedef enum { + GCV_KTYPE_CV8U = 0, + GCV_KTYPE_CV8S = 1, + GCV_KTYPE_CV16U = 2, + GCV_KTYPE_CV16S = 3, + GCV_KTYPE_CV32S = 4, + GCV_KTYPE_CV32F = 5, + GCV_KTYPE_CV64F = 6, + GCV_KTYPE_CV16F = 7 +} GCVKType; /**********************************************/ @@ -318,6 +340,13 @@ GCVImage *gcv_image_build_pyramid(GCVImage *image, GCVImageFilteringOptions *options, GError **error); +GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, + int dx, + int dy, + int ksize, + GCVImageFilteringOptions *options, + GError **error); + GCVImage *gcv_image_laplacian(GCVImage *image, int ddepth, GCVImageFilteringOptions *options, diff --git a/test/test-image.rb b/test/test-image.rb index 93758a5..3490c5d 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -363,6 +363,8 @@ def test_image_filtering_options options.max_level # options.sigma_y p options.border_type + options.ktype + #options.normalize end def test_blur @@ -373,6 +375,24 @@ def test_blur blur_image.bytes.to_s) end +=begin + def test_get_deriv_kernels + dx = 2 + dy = 2 + ksize = 3 + filtered_image = @image.get_deriv_kernels(dx,dy,ksize) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + + options = CV::ImageFilteringOptions.new + options.ktype = 6 + options.normalize = true + filtered_image = @image.get_deriv_kernels(dx,dy,ksize,options) + assert_not_equal(@image.bytes.to_s, + filtered_image.bytes.to_s) + end +=end + def test_laplacian ddepth = 5 filtered_image = @image.laplacian(ddepth) From 9783a6cde2b2c270f7055e178b14276426ea0ead Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Tue, 15 Mar 2022 01:01:15 +0900 Subject: [PATCH 17/18] Fix normalize test --- opencv-glib/image.cpp | 1 - test/test-image.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 9a20e57..92f640f 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -1331,7 +1331,6 @@ GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); GCVKType ktype = options_priv->ktype; gboolean normalize = options_priv->normalize; -printf("ktype: %d\n",ktype); cv::getDerivKernels(*cv_image, *cv_converted_image, dx, dy, ksize, normalize, ktype); diff --git a/test/test-image.rb b/test/test-image.rb index 3490c5d..c04894d 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -362,9 +362,9 @@ def test_image_filtering_options options.iterations options.max_level # options.sigma_y -p options.border_type + options.border_type options.ktype - #options.normalize + options.normalize? end def test_blur From fe1ff7086a3027ff88156770358dd28d833da777 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 23 Apr 2022 17:50:15 +0900 Subject: [PATCH 18/18] Rename image_filtering -> image_filter --- opencv-glib/image.cpp | 94 +++++++++++++++++++++---------------------- opencv-glib/image.h | 28 ++++++------- test/test-image.rb | 14 +++---- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp index 92f640f..9d6f1c5 100644 --- a/opencv-glib/image.cpp +++ b/opencv-glib/image.cpp @@ -219,16 +219,16 @@ typedef struct { gint max_level; GCVPoint *anchor; // TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1) -} GCVImageFilteringOptionsPrivate; +} GCVImageFilterOptionsPrivate; -G_DEFINE_TYPE_WITH_PRIVATE(GCVImageFilteringOptions, - gcv_image_filtering_options, +G_DEFINE_TYPE_WITH_PRIVATE(GCVImageFilterOptions, + gcv_image_filter_options, G_TYPE_OBJECT) -#define GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object) \ - static_cast( \ - gcv_image_filtering_options_get_instance_private( \ - GCV_IMAGE_FILTERING_OPTIONS(object))) +#define GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(object) \ + static_cast( \ + gcv_image_filter_options_get_instance_private( \ + GCV_IMAGE_FILTER_OPTIONS(object))) // TODO enum { @@ -248,12 +248,12 @@ enum { }; static void -gcv_image_filtering_options_get_property(GObject *object, +gcv_image_filter_options_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + auto priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(object); switch (prop_id) { case PROP_NORMALIZE: @@ -305,12 +305,12 @@ gcv_image_filtering_options_get_property(GObject *object, } static void -gcv_image_filtering_options_set_property(GObject *object, +gcv_image_filter_options_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - auto priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(object); + auto priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(object); switch (prop_id) { case PROP_NORMALIZE: @@ -375,19 +375,19 @@ gcv_image_filtering_options_set_property(GObject *object, static void -gcv_image_filtering_options_init(GCVImageFilteringOptions *object) +gcv_image_filter_options_init(GCVImageFilterOptions *object) { } static void -gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) +gcv_image_filter_options_class_init(GCVImageFilterOptionsClass *klass) { GParamSpec *spec; auto gobject_class = G_OBJECT_CLASS(klass); - gobject_class->get_property = gcv_image_filtering_options_get_property; - gobject_class->set_property = gcv_image_filtering_options_set_property; + gobject_class->get_property = gcv_image_filter_options_get_property; + gobject_class->set_property = gcv_image_filter_options_set_property; spec = g_param_spec_boolean("normalize", "Normalize", @@ -471,16 +471,16 @@ gcv_image_filtering_options_class_init(GCVImageFilteringOptionsClass *klass) } /** - * gcv_image_filtering_options_new: + * gcv_image_filter_options_new: * - * Returns a newly created #GCVImageFilteringOptions. + * Returns a newly created #GCVImageFilterOptions. * * Since: 1.0.2 */ -GCVImageFilteringOptions * -gcv_image_filtering_options_new(void) +GCVImageFilterOptions * +gcv_image_filter_options_new(void) { - return GCV_IMAGE_FILTERING_OPTIONS(g_object_new(GCV_TYPE_IMAGE_FILTERING_OPTIONS, + return GCV_IMAGE_FILTER_OPTIONS(g_object_new(GCV_TYPE_IMAGE_FILTER_OPTIONS, NULL)); } @@ -979,7 +979,7 @@ gcv_image_split(GCVImage *image) * @d: Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace. * @sigma_color: Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting in larger areas of semi-equal color. * @sigma_space: Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is proportional to sigmaSpace. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects bilateral filter image. The converted image is returned as @@ -993,7 +993,7 @@ GCVImage *gcv_image_bilateral_filter(GCVImage *image, int d, double sigma_color, double sigma_space, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1001,7 +1001,7 @@ GCVImage *gcv_image_bilateral_filter(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int border_type = options_priv->border_type; cv::bilateralFilter(*cv_image, *cv_converted_image, @@ -1061,7 +1061,7 @@ GCVImage *gcv_image_median_blur(GCVImage *image, * gcv_image_blur: * @image: A #GCVImage. * @ksize: A #GCVSize blurring kernel size. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects blur image. The converted image is returned as @@ -1073,7 +1073,7 @@ GCVImage *gcv_image_median_blur(GCVImage *image, */ GCVImage *gcv_image_blur(GCVImage *image, GCVSize *ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1081,7 +1081,7 @@ GCVImage *gcv_image_blur(GCVImage *image, auto cv_converted_image = std::make_shared(); if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); auto anchor = cv::Point(-1, -1); if (options_priv->anchor) { @@ -1101,7 +1101,7 @@ GCVImage *gcv_image_blur(GCVImage *image, * @image: A #GCVImage. * @ddepth: the output image depth * @ksize: blurring kernel size. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * HOGE @@ -1115,7 +1115,7 @@ GCVImage *gcv_image_blur(GCVImage *image, GCVImage *gcv_image_box_filter(GCVImage *image, int ddepth, GCVSize *ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1124,7 +1124,7 @@ GCVImage *gcv_image_box_filter(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); bool normalize = true; int border_type = options_priv->border_type; auto anchor = cv::Point(-1,-1); @@ -1152,7 +1152,7 @@ GCVImage *gcv_image_box_filter(GCVImage *image, * gcv_image_build_pyramid: * @image: A #GCVImage. * @max_level: 0-based index of the last (the smallest) pyramid layer. It must be non-negative. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * Constructs the Gaussian pyramid for an image @@ -1164,7 +1164,7 @@ GCVImage *gcv_image_box_filter(GCVImage *image, */ GCVImage *gcv_image_build_pyramid(GCVImage *image, int max_level, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1172,7 +1172,7 @@ GCVImage *gcv_image_build_pyramid(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int border_type = options_priv->border_type; cv::buildPyramid(*cv_image, *cv_converted_image, @@ -1198,7 +1198,7 @@ GCVImage *gcv_image_build_pyramid(GCVImage *image, * gcv_image_dilate: * @image: A #GCVImage. * @kernel: structuring element used for dilation. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * Constructs the dilate filter for an image @@ -1211,7 +1211,7 @@ GCVImage *gcv_image_build_pyramid(GCVImage *image, /* GCVImage *gcv_image_dilate(GCVImage *image, GCVMatrix *kernel, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1220,7 +1220,7 @@ GCVImage *gcv_image_dilate(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int iteration = options_priv->iteration; int border_type = options_priv->border_type; @@ -1253,7 +1253,7 @@ GCVImage *gcv_image_dilate(GCVImage *image, * @image: A #GCVImage. * @ddepth: desired depth of the destination image, see combinations. * @kernel: convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using split and process them individually. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * Constructs the dilate filter for an image @@ -1266,7 +1266,7 @@ GCVImage *gcv_image_dilate(GCVImage *image, GCVImage *gcv_image_filter2d(GCVImage *image, int ddepth, GCVMatrix *kernel, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1275,7 +1275,7 @@ GCVImage *gcv_image_filter2d(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int delta = options_priv->delta; int border_type = options_priv->border_type; auto anchor = cv::Point(-1,-1); @@ -1307,7 +1307,7 @@ GCVImage *gcv_image_filter2d(GCVImage *image, * @dx: TODO * @dy: TODO * @ksize: TODO - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * TODO @@ -1320,7 +1320,7 @@ GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, int dx, int dy, int ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1328,7 +1328,7 @@ GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); GCVKType ktype = options_priv->ktype; gboolean normalize = options_priv->normalize; @@ -1353,7 +1353,7 @@ GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, * gcv_image_laplacian: * @image: A #GCVImage. * @ddepth: Desired depth of the destination image. - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects laplacian image. The converted image is returned as @@ -1365,7 +1365,7 @@ GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, */ GCVImage *gcv_image_laplacian(GCVImage *image, int ddepth, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1373,7 +1373,7 @@ GCVImage *gcv_image_laplacian(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int ksize = options_priv->ksize; double scale = options_priv->scale; double delta = options_priv->delta; @@ -1402,7 +1402,7 @@ GCVImage *gcv_image_laplacian(GCVImage *image, * @ddepth: Desired depth of the destination image. * @intx: Order of the derivative x * @inty: Order of the derivative y - * @options: (nullable): A #GCVImageFilteringOptions; + * @options: (nullable): A #GCVImageFilterOptions; * @error: (nullable): Return locatipcn for a #GError or %NULL. * * It effects sobel image. The converted image is returned as @@ -1416,7 +1416,7 @@ GCVImage *gcv_image_sobel(GCVImage *image, int ddepth, int intx, int inty, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error) { auto cv_image = gcv_matrix_get_raw(GCV_MATRIX(image)); @@ -1424,7 +1424,7 @@ GCVImage *gcv_image_sobel(GCVImage *image, try { if ( options != NULL ) { - auto options_priv = GCV_IMAGE_FILTERING_OPTIONS_GET_PRIVATE(options); + auto options_priv = GCV_IMAGE_FILTER_OPTIONS_GET_PRIVATE(options); int ksize = options_priv->ksize; double scale = options_priv->scale; double delta = options_priv->delta; diff --git a/opencv-glib/image.h b/opencv-glib/image.h index 8670f31..a1bcd5d 100644 --- a/opencv-glib/image.h +++ b/opencv-glib/image.h @@ -146,19 +146,19 @@ typedef enum { GCV_BORDER_TYPE_BORDER_ISOLATED = 16 } GCVBorderType; -#define GCV_TYPE_IMAGE_FILTERING_OPTIONS (gcv_image_filtering_options_get_type()) -G_DECLARE_DERIVABLE_TYPE(GCVImageFilteringOptions, - gcv_image_filtering_options, +#define GCV_TYPE_IMAGE_FILTER_OPTIONS (gcv_image_filter_options_get_type()) +G_DECLARE_DERIVABLE_TYPE(GCVImageFilterOptions, + gcv_image_filter_options, GCV, - IMAGE_FILTERING_OPTIONS, + IMAGE_FILTER_OPTIONS, GObject) -struct _GCVImageFilteringOptionsClass +struct _GCVImageFilterOptionsClass { GObjectClass parent_class; }; -GCVImageFilteringOptions *gcv_image_filtering_options_new(void); +GCVImageFilterOptions *gcv_image_filter_options_new(void); /** * GCVKrType: @@ -311,19 +311,19 @@ GCVImage *gcv_image_bilateral_filter(GCVImage *image, int d, double sigma_color, double sigma_space, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_box_filter(GCVImage *image, int ddepth, GCVSize *ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_filter2d(GCVImage *image, int ddepth, GCVMatrix *kernel, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_median_blur(GCVImage *image, @@ -332,30 +332,30 @@ GCVImage *gcv_image_median_blur(GCVImage *image, GCVImage *gcv_image_blur(GCVImage *image, GCVSize *ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_build_pyramid(GCVImage *image, int max_level, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_get_deriv_kernels(GCVImage *image, int dx, int dy, int ksize, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_laplacian(GCVImage *image, int ddepth, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); GCVImage *gcv_image_sobel(GCVImage *image, int ddepth, int intx, int inty, - GCVImageFilteringOptions *options, + GCVImageFilterOptions *options, GError **error); G_END_DECLS diff --git a/test/test-image.rb b/test/test-image.rb index c04894d..6a5167b 100644 --- a/test/test-image.rb +++ b/test/test-image.rb @@ -355,8 +355,8 @@ def test_median_blur_invalid_argument(data) end end - def test_image_filtering_options - options = CV::ImageFilteringOptions.new + def test_image_filter_options + options = CV::ImageFilterOptions.new options.delta options.scale options.iterations @@ -370,7 +370,7 @@ def test_image_filtering_options def test_blur size = CV::Size.new(10, 8) blur_image = @image.blur(size) - blur_image = @image.blur(size,CV::ImageFilteringOptions.new) + blur_image = @image.blur(size,CV::ImageFilterOptions.new) assert_not_equal(@image.bytes.to_s, blur_image.bytes.to_s) end @@ -384,7 +384,7 @@ def test_get_deriv_kernels assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) - options = CV::ImageFilteringOptions.new + options = CV::ImageFilterOptions.new options.ktype = 6 options.normalize = true filtered_image = @image.get_deriv_kernels(dx,dy,ksize,options) @@ -399,7 +399,7 @@ def test_laplacian assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) - options = CV::ImageFilteringOptions.new + options = CV::ImageFilterOptions.new options.ksize = 1 # options.ksize = 0 filtered_image = @image.laplacian(ddepth,options) @@ -413,7 +413,7 @@ def test_filter2d assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) - options = CV::ImageFilteringOptions.new + options = CV::ImageFilterOptions.new options.ksize = 1 # options.ksize = 0 filtered_image = @image.filter2d(ddepth,@image,options) @@ -427,7 +427,7 @@ def test_sobel assert_not_equal(@image.bytes.to_s, filtered_image.bytes.to_s) - options = CV::ImageFilteringOptions.new + options = CV::ImageFilterOptions.new # options.ksize = 3 filtered_image = @image.sobel(ddepth,1,1,options)