From de8f4ffda00c54cdd53e00f7b6c063f7f8e636d6 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sat, 1 Jan 2011 21:08:01 +0900 Subject: [PATCH] fixed MASK in cvmat.h, and modified some tests --- ext/cvmat.h | 4 +++- ext/opencv.cpp | 1 - test/test_cvmat.rb | 27 ++++++++++++--------------- test/test_cvscalar.rb | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ext/cvmat.h b/ext/cvmat.h index 45fa680..02c865f 100644 --- a/ext/cvmat.h +++ b/ext/cvmat.h @@ -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."); diff --git a/ext/opencv.cpp b/ext/opencv.cpp index 05b1d22..88cb0d4 100644 --- a/ext/opencv.cpp +++ b/ext/opencv.cpp @@ -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); diff --git a/test/test_cvmat.rb b/test/test_cvmat.rb index 167c7a8..eda0aea 100755 --- a/test/test_cvmat.rb +++ b/test/test_cvmat.rb @@ -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 diff --git a/test/test_cvscalar.rb b/test/test_cvscalar.rb index dc8ca2f..8e342da 100755 --- a/test/test_cvscalar.rb +++ b/test/test_cvscalar.rb @@ -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