mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat#cross
This commit is contained in:
parent
e40051c2b5
commit
c21f32d356
2 changed files with 47 additions and 0 deletions
|
|
@ -772,6 +772,32 @@ namespace rubyopencv {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Computes a cross-product of two 3-element vectors.
|
||||||
|
*
|
||||||
|
* @overload cross(value)
|
||||||
|
* @param value [Mat] Another cross-product operand.
|
||||||
|
* @return [Mat] Cross product
|
||||||
|
* @opencv_func cv::Mat::cross
|
||||||
|
*/
|
||||||
|
VALUE rb_cross(VALUE self, VALUE other) {
|
||||||
|
cv::Mat* selfptr = obj2mat(self);
|
||||||
|
cv::Mat* retptr = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
retptr = new cv::Mat();
|
||||||
|
cv::Mat* mat = obj2mat(other);
|
||||||
|
cv::Mat tmp = selfptr->cross(*mat);
|
||||||
|
tmp.copyTo(*retptr);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
delete retptr;
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mat2obj(retptr, CLASS_OF(self));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets all or some of the array elements to the specified value.
|
* Sets all or some of the array elements to the specified value.
|
||||||
*
|
*
|
||||||
|
|
@ -916,6 +942,7 @@ namespace rubyopencv {
|
||||||
rb_define_method(rb_klass, "/", RUBY_METHOD_FUNC(rb_div), 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, "diag", RUBY_METHOD_FUNC(rb_diag), -1);
|
||||||
rb_define_method(rb_klass, "dot", RUBY_METHOD_FUNC(rb_dot), 1);
|
rb_define_method(rb_klass, "dot", RUBY_METHOD_FUNC(rb_dot), 1);
|
||||||
|
rb_define_method(rb_klass, "cross", RUBY_METHOD_FUNC(rb_cross), 1);
|
||||||
|
|
||||||
rb_define_method(rb_klass, "clone", RUBY_METHOD_FUNC(rb_clone), 0);
|
rb_define_method(rb_klass, "clone", RUBY_METHOD_FUNC(rb_clone), 0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -369,6 +369,26 @@ class TestMat < OpenCVTestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cross
|
||||||
|
m0 = Mat.new(3, 1, CV_32F)
|
||||||
|
m0[0, 0] = Scalar.new(1)
|
||||||
|
m0[1, 0] = Scalar.new(2)
|
||||||
|
m0[2, 0] = Scalar.new(0)
|
||||||
|
|
||||||
|
m1 = Mat.new(3, 1, CV_32F)
|
||||||
|
m1[0, 0] = Scalar.new(0)
|
||||||
|
m1[1, 0] = Scalar.new(1)
|
||||||
|
m1[2, 0] = Scalar.new(-1)
|
||||||
|
|
||||||
|
m = m0.cross(m1)
|
||||||
|
elems = m.to_s.scan(/(\[[^\]]+\])/m).flatten[0]
|
||||||
|
assert_equal("[-2;\n 1;\n 1]", elems)
|
||||||
|
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.cross(DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_cvt_color
|
def test_cvt_color
|
||||||
m = Mat.new(1, 1, CV_32FC3)
|
m = Mat.new(1, 1, CV_32FC3)
|
||||||
m[0, 0] = Scalar.new(1.0, 2.0, 3.0)
|
m[0, 0] = Scalar.new(1.0, 2.0, 3.0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue