mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Updated to support 3.3.1+.
This commit is contained in:
parent
fe3493f47c
commit
256df73e7b
4 changed files with 33 additions and 18 deletions
|
@ -3,7 +3,7 @@
|
||||||
An OpenCV wrapper for Ruby.
|
An OpenCV wrapper for Ruby.
|
||||||
|
|
||||||
* Web site: <https://github.com/ruby-opencv/ruby-opencv>
|
* Web site: <https://github.com/ruby-opencv/ruby-opencv>
|
||||||
* Ruby 2.x and OpenCV 3.2.0 are supported.
|
* Ruby 2.x and OpenCV 3.3.1 are supported.
|
||||||
|
|
||||||
## Requirement
|
## Requirement
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,10 @@ namespace rubyopencv {
|
||||||
|
|
||||||
// Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String());
|
// Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String());
|
||||||
VALUE rb_read_net_from_caffe(VALUE self, VALUE prototxt, VALUE caffe_model) {
|
VALUE rb_read_net_from_caffe(VALUE self, VALUE prototxt, VALUE caffe_model) {
|
||||||
cv::dnn::experimental_dnn_v1::Net *net = NULL;
|
cv::dnn::Net *net = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
net = new cv::dnn::experimental_dnn_v1::Net(cv::dnn::readNetFromCaffe(StringValueCStr(prototxt), StringValueCStr(caffe_model)));
|
net = new cv::dnn::Net(cv::dnn::readNetFromCaffe(StringValueCStr(prototxt), StringValueCStr(caffe_model)));
|
||||||
} catch(cv::Exception& e) {
|
} catch(cv::Exception& e) {
|
||||||
delete net;
|
delete net;
|
||||||
Error::raise(e);
|
Error::raise(e);
|
||||||
|
@ -62,10 +62,10 @@ namespace rubyopencv {
|
||||||
|
|
||||||
// Net readNetFromTorch(const String &model, bool isBinary)
|
// Net readNetFromTorch(const String &model, bool isBinary)
|
||||||
VALUE rb_read_net_from_tensorflow(VALUE self, VALUE model) {
|
VALUE rb_read_net_from_tensorflow(VALUE self, VALUE model) {
|
||||||
cv::dnn::experimental_dnn_v1::Net *net = NULL;
|
cv::dnn::Net *net = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
net = new cv::dnn::experimental_dnn_v1::Net(cv::dnn::readNetFromTensorflow(StringValueCStr(model)));
|
net = new cv::dnn::Net(cv::dnn::readNetFromTensorflow(StringValueCStr(model)));
|
||||||
} catch(cv::Exception& e) {
|
} catch(cv::Exception& e) {
|
||||||
delete net;
|
delete net;
|
||||||
Error::raise(e);
|
Error::raise(e);
|
||||||
|
@ -76,10 +76,24 @@ namespace rubyopencv {
|
||||||
|
|
||||||
// Net readNetFromTorch(const String &model, bool isBinary)
|
// Net readNetFromTorch(const String &model, bool isBinary)
|
||||||
VALUE rb_read_net_from_torch(VALUE self, VALUE model) {
|
VALUE rb_read_net_from_torch(VALUE self, VALUE model) {
|
||||||
cv::dnn::experimental_dnn_v1::Net *net = NULL;
|
cv::dnn::Net *net = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
net = new cv::dnn::experimental_dnn_v1::Net(cv::dnn::readNetFromTorch(StringValueCStr(model)));
|
net = new cv::dnn::Net(cv::dnn::readNetFromTorch(StringValueCStr(model)));
|
||||||
|
} catch(cv::Exception& e) {
|
||||||
|
delete net;
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Dnn::Net::net2obj(net);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Net readNetFromDarknet(const String &cfgFile, const String &darknetModel /*= String()*/)
|
||||||
|
VALUE rb_read_net_from_darknet(VALUE self, VALUE cfg_file, VALUE darknet_model) {
|
||||||
|
cv::dnn::Net *net = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
net = new cv::dnn::Net(cv::dnn::readNetFromDarknet(StringValueCStr(cfg_file), StringValueCStr(darknet_model)));
|
||||||
} catch(cv::Exception& e) {
|
} catch(cv::Exception& e) {
|
||||||
delete net;
|
delete net;
|
||||||
Error::raise(e);
|
Error::raise(e);
|
||||||
|
@ -97,6 +111,7 @@ namespace rubyopencv {
|
||||||
rb_define_singleton_method(rb_module, "read_net_from_caffe", RUBY_METHOD_FUNC(rb_read_net_from_caffe), 2);
|
rb_define_singleton_method(rb_module, "read_net_from_caffe", RUBY_METHOD_FUNC(rb_read_net_from_caffe), 2);
|
||||||
rb_define_singleton_method(rb_module, "read_net_from_tensorflow", RUBY_METHOD_FUNC(rb_read_net_from_tensorflow), 1);
|
rb_define_singleton_method(rb_module, "read_net_from_tensorflow", RUBY_METHOD_FUNC(rb_read_net_from_tensorflow), 1);
|
||||||
rb_define_singleton_method(rb_module, "read_net_from_torch", RUBY_METHOD_FUNC(rb_read_net_from_torch), 1);
|
rb_define_singleton_method(rb_module, "read_net_from_torch", RUBY_METHOD_FUNC(rb_read_net_from_torch), 1);
|
||||||
|
rb_define_singleton_method(rb_module, "read_net_from_darknet", RUBY_METHOD_FUNC(rb_read_net_from_darknet), 2);
|
||||||
|
|
||||||
Dnn::Net::init(rb_module);
|
Dnn::Net::init(rb_module);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,29 +10,29 @@ namespace rubyopencv {
|
||||||
VALUE rb_klass = Qnil;
|
VALUE rb_klass = Qnil;
|
||||||
|
|
||||||
void free_net(void* ptr) {
|
void free_net(void* ptr) {
|
||||||
delete (cv::dnn::experimental_dnn_v1::Net*)ptr;
|
delete (cv::dnn::Net*)ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t memsize_net(const void* ptr) {
|
size_t memsize_net(const void* ptr) {
|
||||||
return sizeof(cv::dnn::experimental_dnn_v1::Net);
|
return sizeof(cv::dnn::Net);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_data_type_t opencv_net_type = {
|
rb_data_type_t opencv_net_type = {
|
||||||
"Dnn::Net", { 0, free_net, memsize_net, }, 0, 0, 0
|
"Dnn::Net", { 0, free_net, memsize_net, }, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
VALUE net2obj(cv::dnn::experimental_dnn_v1::Net* ptr) {
|
VALUE net2obj(cv::dnn::Net* ptr) {
|
||||||
return TypedData_Wrap_Struct(rb_klass, &opencv_net_type, ptr);
|
return TypedData_Wrap_Struct(rb_klass, &opencv_net_type, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::dnn::experimental_dnn_v1::Net* obj2net(VALUE obj) {
|
cv::dnn::Net* obj2net(VALUE obj) {
|
||||||
cv::dnn::experimental_dnn_v1::Net* ptr = NULL;
|
cv::dnn::Net* ptr = NULL;
|
||||||
TypedData_Get_Struct(obj, cv::dnn::experimental_dnn_v1::Net, &opencv_net_type, ptr);
|
TypedData_Get_Struct(obj, cv::dnn::Net, &opencv_net_type, ptr);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE rb_allocate(VALUE klass) {
|
VALUE rb_allocate(VALUE klass) {
|
||||||
cv::dnn::experimental_dnn_v1::Net* ptr = new cv::dnn::experimental_dnn_v1::Net();
|
cv::dnn::Net* ptr = new cv::dnn::Net();
|
||||||
return TypedData_Wrap_Struct(klass, &opencv_net_type, ptr);
|
return TypedData_Wrap_Struct(klass, &opencv_net_type, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ namespace rubyopencv {
|
||||||
VALUE blob, name;
|
VALUE blob, name;
|
||||||
rb_scan_args(argc, argv, "11", &blob, &name);
|
rb_scan_args(argc, argv, "11", &blob, &name);
|
||||||
|
|
||||||
cv::dnn::experimental_dnn_v1::Net* selfptr = obj2net(self);
|
cv::dnn::Net* selfptr = obj2net(self);
|
||||||
|
|
||||||
cv::Mat *m = Mat::obj2mat(blob);
|
cv::Mat *m = Mat::obj2mat(blob);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace rubyopencv {
|
||||||
VALUE output_name;
|
VALUE output_name;
|
||||||
rb_scan_args(argc, argv, "01", &output_name);
|
rb_scan_args(argc, argv, "01", &output_name);
|
||||||
|
|
||||||
cv::dnn::experimental_dnn_v1::Net* selfptr = obj2net(self);
|
cv::dnn::Net* selfptr = obj2net(self);
|
||||||
|
|
||||||
cv::Mat* m = NULL;
|
cv::Mat* m = NULL;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ namespace rubyopencv {
|
||||||
|
|
||||||
// bool empty() const
|
// bool empty() const
|
||||||
VALUE rb_empty(VALUE self) {
|
VALUE rb_empty(VALUE self) {
|
||||||
cv::dnn::experimental_dnn_v1::Net* selfptr = obj2net(self);
|
cv::dnn::Net* selfptr = obj2net(self);
|
||||||
return selfptr->empty() ? Qtrue : Qfalse;
|
return selfptr->empty() ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace rubyopencv {
|
||||||
namespace Dnn {
|
namespace Dnn {
|
||||||
namespace Net {
|
namespace Net {
|
||||||
void init(VALUE rb_module);
|
void init(VALUE rb_module);
|
||||||
VALUE net2obj(cv::dnn::experimental_dnn_v1::Net* ptr);
|
VALUE net2obj(cv::dnn::Net* ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue