diff --git a/ext/cvmat.cpp b/ext/cvmat.cpp index 879d417..750acba 100644 --- a/ext/cvmat.cpp +++ b/ext/cvmat.cpp @@ -675,7 +675,7 @@ rb_clone(VALUE self) VALUE rb_copy(int argc, VALUE *argv, VALUE self) { - VALUE value, copied; + VALUE value, copied, tmp; CvMat *src = CVMAT(self); rb_scan_args(argc, argv, "01", &value); if (argc == 0) { @@ -692,7 +692,9 @@ rb_copy(int argc, VALUE *argv, VALUE self) if (n > 0) { copied = rb_ary_new2(n); for (int i = 0; i < n; i++) { - rb_ary_store(copied, i, new_object(src->rows, src->cols, cvGetElemType(src))); + tmp = new_object(src->rows, src->cols, cvGetElemType(src)); + cvCopy(src, CVMAT(tmp)); + rb_ary_store(copied, i, tmp); } return copied; }else{ diff --git a/test/test_cvmat.rb b/test/test_cvmat.rb index 39684df..3836d75 100755 --- a/test/test_cvmat.rb +++ b/test/test_cvmat.rb @@ -145,7 +145,10 @@ class TestCvMat < OpenCVTestCase a = m1.copy(2) assert_equal(2, a.size) + a.each { |m| + assert_equal(m1.height, m.height) + assert_equal(m1.width, m.width) m1.height.times { |j| m1.width.times { |i| assert_cvscalar_equal(m1[i, j], m[i, j])