mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fixed MASK in cvmat.h, and modified some tests
This commit is contained in:
parent
411f8ba9da
commit
de8f4ffda0
4 changed files with 31 additions and 17 deletions
|
@ -275,7 +275,9 @@ MASK(VALUE object)
|
|||
{
|
||||
if(NIL_P(object))
|
||||
return NULL;
|
||||
else if(rb_obj_is_kind_of(object, cCvMat::rb_class()) && CV_MAT_CN(CVMAT(object)->type) == CV_8UC1)
|
||||
else if(rb_obj_is_kind_of(object, cCvMat::rb_class()) &&
|
||||
CV_MAT_DEPTH(CVMAT(object)->type) == CV_8UC1 &&
|
||||
CV_MAT_CN(CVMAT(object)->type) == 1)
|
||||
return CVMAT(object);
|
||||
else
|
||||
rb_raise(rb_eTypeError, "object is not mask.");
|
||||
|
|
|
@ -168,7 +168,6 @@ define_ruby_module()
|
|||
/* 6: 64bit floating-point */
|
||||
rb_define_const(rb_module, "CV_64F", INT2FIX(CV_64F));
|
||||
|
||||
|
||||
VALUE inversion_method = rb_hash_new();
|
||||
/* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
|
||||
rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
|
||||
|
|
|
@ -479,8 +479,7 @@ class TestCvMat < TestOpenCV
|
|||
|
||||
m1 = make_cvmat(5, 5)
|
||||
m0 = m1.clone
|
||||
flunk('FIXME: constant CV_8UC1 is not implemented yet (but CV_8U == CV_8UC1...?).')
|
||||
mask = CvMat.new(m.height, m.width, CV_8UC1)
|
||||
mask = CvMat.new(m1.height, m1.width, :cv8u, 1).clear
|
||||
2.times { |j|
|
||||
2.times { |i|
|
||||
mask[i, j] = CvScalar.new(1, 1, 1, 1)
|
||||
|
@ -492,15 +491,15 @@ class TestCvMat < TestOpenCV
|
|||
m2.height.times { |j|
|
||||
m2.width.times { |i|
|
||||
if i < 2 and j < 2
|
||||
assert(is_same_float_array([1, 1, 1, 1], m1[i, j]))
|
||||
assert(is_same_float_array([1, 1, 1, 1], m2[i, j]))
|
||||
assert(is_same_float_array([1, 2, 3, 4], m1[i, j]))
|
||||
assert(is_same_float_array([1, 2, 3, 4], m2[i, j]))
|
||||
else
|
||||
assert(is_same_float_array(m0[i, j], m1[i, j]))
|
||||
assert(is_same_float_array(m0[i, j], m2[i, j]))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Alias
|
||||
m1 = make_cvmat(2, 3)
|
||||
m2 = m1.set(CvScalar.new(1, 2, 3, 4))
|
||||
|
@ -514,8 +513,7 @@ class TestCvMat < TestOpenCV
|
|||
|
||||
m1 = make_cvmat(5, 5)
|
||||
m0 = m1.clone
|
||||
flunk('FIXME: constant CV_8UC1 is not implemented yet (but CV_8U == CV_8UC1...?).')
|
||||
mask = CvMat.new(m.height, m.width, CV_8UC1)
|
||||
mask = CvMat.new(m1.height, m1.width, CV_8U, 1).clear
|
||||
2.times { |j|
|
||||
2.times { |i|
|
||||
mask[i, j] = CvScalar.new(1, 1, 1, 1)
|
||||
|
@ -527,8 +525,8 @@ class TestCvMat < TestOpenCV
|
|||
m2.height.times { |j|
|
||||
m2.width.times { |i|
|
||||
if i < 2 and j < 2
|
||||
assert(is_same_float_array([1, 1, 1, 1], m1[i, j]))
|
||||
assert(is_same_float_array([1, 1, 1, 1], m2[i, j]))
|
||||
assert(is_same_float_array([1, 2, 3, 4], m1[i, j]))
|
||||
assert(is_same_float_array([1, 2, 3, 4], m2[i, j]))
|
||||
else
|
||||
assert(is_same_float_array(m0[i, j], m1[i, j]))
|
||||
assert(is_same_float_array(m0[i, j], m2[i, j]))
|
||||
|
@ -578,13 +576,12 @@ class TestCvMat < TestOpenCV
|
|||
end
|
||||
|
||||
def test_range
|
||||
m1 = CvMat.new(1, 10)
|
||||
flunk('FIXME: constant CV_32SC1 is not implemented yet (but CV_32S == CV_32UC1...?).')
|
||||
m2 = m1.range(0, m1.cols, CV_32SC1)
|
||||
m1.range!(0, m1.cols, CV_32SC1)
|
||||
m1 = CvMat.new(1, 10, CV_32S, 1)
|
||||
m2 = m1.range(0, m1.cols)
|
||||
m1.range!(0, m1.cols)
|
||||
m2.width.times { |i|
|
||||
assert(is_same_float_array([i, 0, 0, 0], m1[i, j].to_ary))
|
||||
assert(is_same_float_array([i, 0, 0, 0], m2[i, j].to_ary))
|
||||
assert(is_same_float_array([i, 0, 0, 0], m1[i, 0].to_ary))
|
||||
assert(is_same_float_array([i, 0, 0, 0], m2[i, 0].to_ary))
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -58,6 +58,22 @@ class TestCvScalar < TestOpenCV
|
|||
assert_in_delta(5.4, s[2], 0.01)
|
||||
assert_in_delta(7.2, s[3], 0.01)
|
||||
}
|
||||
|
||||
mat = CvMat.new(5, 5)
|
||||
mask = CvMat.new(5, 5, :cv8u, 1)
|
||||
mat.height.times { |j|
|
||||
mat.width.times { |i|
|
||||
mat[i, j] = CvScalar.new(1.5)
|
||||
mask[i, j] = (i < 2 and j < 3) ? 1 : 0
|
||||
}
|
||||
}
|
||||
mat = CvScalar.new(0.1).sub(mat, mask)
|
||||
|
||||
[CvMat.new(5, 5, :cv16u, 1), CvMat.new(5, 5, :cv8u, 3)].each { |mask|
|
||||
assert_raise(TypeError) {
|
||||
CvScalar.new.sub(mat, mask)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue