From ce53225ef286496e79a939c20a45f10410b56c87 Mon Sep 17 00:00:00 2001 From: Francois Deschenes Date: Fri, 27 Jul 2018 11:00:16 -0700 Subject: [PATCH] Improved documentation to show attributes as attributes. --- ext/opencv/dnn.cpp | 4 ++++ ext/opencv/dnn.hpp | 1 + ext/opencv/dnn_layer.cpp | 5 ++++ ext/opencv/dnn_net.cpp | 52 +++++++++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/ext/opencv/dnn.cpp b/ext/opencv/dnn.cpp index 59ce63c..3523d8f 100644 --- a/ext/opencv/dnn.cpp +++ b/ext/opencv/dnn.cpp @@ -15,6 +15,10 @@ namespace rubyopencv { namespace Dnn { VALUE rb_module = Qnil; + VALUE rb_module_dnn() { + return rb_module; + } + /* * Creates 4-dimensional blob from image. Optionally resizes and crops image from center, subtract mean values, scales values by scalefactor, swap Blue and Red channels. * diff --git a/ext/opencv/dnn.hpp b/ext/opencv/dnn.hpp index d01e476..806a816 100644 --- a/ext/opencv/dnn.hpp +++ b/ext/opencv/dnn.hpp @@ -7,6 +7,7 @@ namespace rubyopencv { namespace Dnn { void init(); + VALUE rb_module_dnn(); } } diff --git a/ext/opencv/dnn_layer.cpp b/ext/opencv/dnn_layer.cpp index 17ccc61..793d299 100644 --- a/ext/opencv/dnn_layer.cpp +++ b/ext/opencv/dnn_layer.cpp @@ -73,6 +73,11 @@ namespace rubyopencv { rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0); rb_define_method(rb_klass, "type", RUBY_METHOD_FUNC(rb_type), 0); + + #if 0 + rb_define_attr(rb_klass, "name", 1, 0); + rb_define_attr(rb_klass, "type", 1, 0); + #endif } } } diff --git a/ext/opencv/dnn_net.cpp b/ext/opencv/dnn_net.cpp index 2186a7c..5791b3a 100644 --- a/ext/opencv/dnn_net.cpp +++ b/ext/opencv/dnn_net.cpp @@ -78,20 +78,7 @@ namespace rubyopencv { return self; } - /* - * Sets the new input value for the network - * - * @overload input=(blob) - * @param blob [Mat] A blob of CV_32F or CV_8U depth - * @overload input(blob, name = nil) - * @param blob [Mat] A blob of CV_32F or CV_8U depth - * @param name [String] Name of an input layer - * @return [void] - */ - VALUE rb_set_input(int argc, VALUE *argv, VALUE self) { - VALUE blob, name; - rb_scan_args(argc, argv, "11", &blob, &name); - + void rb_set_input_internal(VALUE self, VALUE blob, VALUE name) { cv::dnn::Net* selfptr = obj2net(self); try { @@ -99,10 +86,35 @@ namespace rubyopencv { } catch(cv::Exception& e) { Error::raise(e); } + } + /* + * Sets the new input value for the network + * + * @overload input=(blob) + * @param blob [Mat] A blob of CV_32F or CV_8U depth + * @return [nil] + */ + VALUE rb_set_input_equals(VALUE self, VALUE blob) { + rb_set_input_internal(self, blob, Qnil); return Qnil; } + /* + * Sets the new input value for the network + * + * @overload input(blob, name = nil) + * @param blob [Mat] A blob of CV_32F or CV_8U depth + * @param name [String] Name of an input layer + * @return [Net] The current network + */ + VALUE rb_set_input(int argc, VALUE *argv, VALUE self) { + VALUE blob, name; + rb_scan_args(argc, argv, "11", &blob, &name); + rb_set_input_internal(self, blob, name); + return self; + } + /* * Runs forward pass * @@ -305,8 +317,8 @@ namespace rubyopencv { rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1); - rb_define_method(rb_klass, "input=", RUBY_METHOD_FUNC(rb_set_input), -1); - rb_define_alias(rb_klass, "input", "input="); + rb_define_method(rb_klass, "input=", RUBY_METHOD_FUNC(rb_set_input_equals), 1); + rb_define_method(rb_klass, "input", RUBY_METHOD_FUNC(rb_set_input), -1); rb_define_method(rb_klass, "fusion=", RUBY_METHOD_FUNC(rb_enable_fusion), 1); rb_define_method(rb_klass, "preferable_backend=", RUBY_METHOD_FUNC(rb_set_preferable_backend), 1); rb_define_method(rb_klass, "preferable_target=", RUBY_METHOD_FUNC(rb_set_preferable_target), 1); @@ -314,6 +326,14 @@ namespace rubyopencv { rb_define_method(rb_klass, "forward", RUBY_METHOD_FUNC(rb_forward), -1); rb_define_method(rb_klass, "empty?", RUBY_METHOD_FUNC(rb_empty), 0); rb_define_method(rb_klass, "layers", RUBY_METHOD_FUNC(rb_get_layers), 0); + + #if 0 + rb_define_attr(rb_klass, "layers", 1, 0); + rb_define_attr(rb_klass, "input", 0, 1); + rb_define_attr(rb_klass, "fusion", 0, 1); + rb_define_attr(rb_klass, "preferable_backend", 0, 1); + rb_define_attr(rb_klass, "preferable_target", 0, 1); + #endif } } }