From 2d416857a91a086a15e96a77387f145fb196fcff Mon Sep 17 00:00:00 2001 From: ser1zw Date: Thu, 6 Jan 2011 01:57:33 +0900 Subject: [PATCH] modified CvMat, and added some tests --- ext/cvmat.cpp | 12 +++++++++--- test/test_cvmat.rb | 11 ++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/cvmat.cpp b/ext/cvmat.cpp index d3874ae..130e9ad 100644 --- a/ext/cvmat.cpp +++ b/ext/cvmat.cpp @@ -1147,13 +1147,15 @@ rb_aref(VALUE self, VALUE args) scalar = cvGet1D(CVARR(self), index[0]); break; case 2: - // scalar = cvGet2D(CVARR(self), index[1], index[0]); scalar = cvGet2D(CVARR(self), index[0], index[1]); break; + /* + // cvGet3D should not be used in this method. + // "self" is always an instance of CvMat, and its data are 1D or 2D array. case 3: - // scalar = cvGet3D(CVARR(self), index[2], index[1], index[0]); scalar = cvGet3D(CVARR(self), index[0], index[1], index[2]); break; + */ default: scalar = cvGetND(CVARR(self), index); } @@ -1182,9 +1184,13 @@ rb_aset(VALUE self, VALUE args) case 2: cvSet2D(CVARR(self), index[0], index[1], scalar); break; + // cvGet3D should not be used in this method. + // "self" is always an instance of CvMat, and its data are 1D or 2D array. + /* case 3: - cvSet3D(CVARR(self), index[0], index[1], index[2], scalar); + cvSet3D(CVARR(self), index[0], index[1], index[2], scalar); break; + */ default: cvSetND(CVARR(self), index, scalar); } diff --git a/test/test_cvmat.rb b/test/test_cvmat.rb index 514cc5d..5843993 100755 --- a/test/test_cvmat.rb +++ b/test/test_cvmat.rb @@ -458,22 +458,23 @@ class TestCvMat < OpenCVTestCase assert_cvscalar_equal(CvScalar.new(5, 5, 5, 5), m[4]) assert_cvscalar_equal(CvScalar.new(2, 2, 2, 2), m[0, 1]) assert_cvscalar_equal(CvScalar.new(4, 4, 4, 4), m[1, 0]) + assert_cvscalar_equal(CvScalar.new(2, 2, 2, 2), m[0, 1, 2]) + assert_cvscalar_equal(CvScalar.new(4, 4, 4, 4), m[1, 0, 3, 4]) # Alias assert_cvscalar_equal(CvScalar.new(1, 1, 1, 1), m.at(0)) - - flunk('FIXME: cvGetND cases do not seem to work well') end def test_aset m = create_cvmat(2, 3) m[0] = CvScalar.new(10, 10, 10, 10) assert_cvscalar_equal(CvScalar.new(10, 10, 10, 10), m[0]) - m[1, 0] = CvScalar.new(20, 20, 20, 20) assert_cvscalar_equal(CvScalar.new(20, 20, 20, 20), m[1, 0]) - - flunk('FIXME: cvSetND cases do not seem to work well') + m[1, 0, 2] = CvScalar.new(4, 4, 4, 4) + assert_cvscalar_equal(CvScalar.new(4, 4, 4, 4), m[1, 0]) + m[1, 0, 2, 4] = CvScalar.new(5, 5, 5, 5) + assert_cvscalar_equal(CvScalar.new(5, 5, 5, 5), m[1, 0]) end def test_fill