Skip to content

Conversation

hiroyuki-sato
Copy link
Contributor

@hiroyuki-sato hiroyuki-sato commented Feb 28, 2022

@kou Could you advise for me?

I created pamaters of CVImageFilteringOptions like the below.

  • I looked at this page (I don't remember it was 4.5.5) and pickup default parameters.(It is mean that I pickup param_name=defaultValue)
  • It result the below.
  • And I used those parameter as CVImageFilteringOptions.
bool normalize=false
bool normalize=true
const Scalar &borderValue=morphologyDefaultBorderValue()
const Size &dstsize=Size()
double delta=0
double psi=CV_PI *0.5
double scale=1
double sigmaY=0
int borderType=BORDER_CONSTANT
int borderType=BORDER_DEFAULT
int iterations=1
int ksize=1
int ksize=3
int ktype=CV_32F
int ktype=CV_64F
int maxLevel=1
Point anchor=Point(-1, -1)
Point anchor=Point(-1,-1)
TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5, 1)

break;
/*
case PROP_ANCHOR:
g_value_set_XXX(value, priv->anchor);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this part, I would like to implement the following.
Could you advise for that?
(Thank you for helping me. I'm not familiar with C++ pointers, by the way.)

options = CV::ImageFilteringOptions.new
options.anchor = CV::Point.new(-1,-1)
#...
options.anchor

/*
case PROP_ANCHOR:
priv->anchor = g_value_get_XXX(value);
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this part, I would like to implement the following.
Could you advise for that?
(Thank you for helping me. I'm not familiar with C++ pointers, by the way.)

options = CV::ImageFilteringOptions.new
options.anchor = CV::Point.new(-1,-1)
#...
options.anchor

@kou
Copy link
Member

kou commented Mar 1, 2022

diff --git a/opencv-glib/image.cpp b/opencv-glib/image.cpp
index adc30fd..0dbd2b8 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<GParamFlags>(G_PARAM_READWRITE));
+  g_object_class_install_property(gobject_class, PROP_ANCHOR, spec);
 }
 
 /**
@@ -1015,8 +1029,11 @@ 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);
   }

Note that you don't need to specify G_PARAM_CONSTRUCT for properties of this class.
If we specify G_PARAM_CONSTRUCT, the property can be set only when new:

CV::ImageFilteringOptions.new(anchor: ...)

We can't set them after new:

options = CV::ImageFilteringOptions.new
options.anchor = ... # NoMethodError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants