mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat#dot
This commit is contained in:
parent
a354bc3625
commit
3618e2ebf7
2 changed files with 40 additions and 0 deletions
|
@ -736,6 +736,29 @@ namespace rubyopencv {
|
|||
return mat2obj(retptr, CLASS_OF(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* Computes a dot-product of two vectors.
|
||||
*
|
||||
* @overload dot(value)
|
||||
* @param value [Mat] Another dot-product operand.
|
||||
* @return [Number] Dot product
|
||||
* @opencv_func cv::Mat::dot
|
||||
*/
|
||||
VALUE rb_dot(VALUE self, VALUE other) {
|
||||
cv::Mat* selfptr = obj2mat(self);
|
||||
VALUE ret = Qnil;
|
||||
|
||||
try {
|
||||
cv::Mat* mat = obj2mat(other);
|
||||
ret = DBL2NUM(selfptr->dot(*mat));
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
Error::raise(e);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets all or some of the array elements to the specified value.
|
||||
*
|
||||
|
@ -879,6 +902,7 @@ namespace rubyopencv {
|
|||
rb_define_method(rb_klass, "*", RUBY_METHOD_FUNC(rb_mul), 1);
|
||||
rb_define_method(rb_klass, "/", RUBY_METHOD_FUNC(rb_div), 1);
|
||||
rb_define_method(rb_klass, "diag", RUBY_METHOD_FUNC(rb_diag), -1);
|
||||
rb_define_method(rb_klass, "dot", RUBY_METHOD_FUNC(rb_dot), 1);
|
||||
|
||||
rb_define_method(rb_klass, "clone", RUBY_METHOD_FUNC(rb_clone), 0);
|
||||
|
||||
|
|
|
@ -353,6 +353,22 @@ class TestMat < OpenCVTestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_dot
|
||||
m0 = Mat.new(2, 1, CV_8U);
|
||||
m0[0, 0] = Scalar.new(1)
|
||||
m0[1, 0] = Scalar.new(2)
|
||||
m1 = Mat.new(2, 1, CV_8U);
|
||||
m1[0, 0] = Scalar.new(3)
|
||||
m1[1, 0] = Scalar.new(4)
|
||||
|
||||
a = m0.dot(m1)
|
||||
assert_in_delta(11.0, a, 0.01)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.dot(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_cvt_color
|
||||
m = Mat.new(1, 1, CV_32FC3)
|
||||
m[0, 0] = Scalar.new(1.0, 2.0, 3.0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue