diff --git a/ext/cvmoments.cpp b/ext/cvmoments.cpp index 49ee93e..ba4d2c8 100644 --- a/ext/cvmoments.cpp +++ b/ext/cvmoments.cpp @@ -173,7 +173,7 @@ rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order) /* * call-seq: - * hu -> [hu1, hu2, ... ,hu7] + * hu -> cvhumoments * * Calculates seven Hu invariants. * @@ -190,16 +190,7 @@ rb_normalized_central(VALUE self, VALUE x_order, VALUE y_order) VALUE rb_hu(VALUE self) { - CvHuMoments hu_moments; - cvGetHuMoments(CVMOMENTS(self), &hu_moments); - return rb_ary_new3(7, - rb_float_new(hu_moments.hu1), - rb_float_new(hu_moments.hu2), - rb_float_new(hu_moments.hu3), - rb_float_new(hu_moments.hu4), - rb_float_new(hu_moments.hu5), - rb_float_new(hu_moments.hu6), - rb_float_new(hu_moments.hu7)); + return cCvHuMoments::new_object(CVMOMENTS(self)); } /* diff --git a/test/test_cvmoments.rb b/test/test_cvmoments.rb index 3cdc052..30734c8 100755 --- a/test/test_cvmoments.rb +++ b/test/test_cvmoments.rb @@ -58,25 +58,29 @@ class TestCvMoments < OpenCVTestCase def test_hu hu_moments = @moment1.hu - hu_moments.each { |hu| + assert_equal(CvHuMoments, hu_moments.class) + hu_moments.to_a.each { |hu| assert_in_delta(0.0, hu, 0.000001) } hu_moments = @moment2.hu - hu_moments.each { |hu| + assert_equal(CvHuMoments, hu_moments.class) + hu_moments.to_a.each { |hu| assert_in_delta(0.0, hu, 0.000001) } hu_moments = @moment3.hu - assert_in_delta(0.001771, hu_moments[0], 0.000001) - hu_moments[1..7].each { |hu| + assert_equal(CvHuMoments, hu_moments.class) + assert_in_delta(0.001771, hu_moments.hu1, 0.000001) + hu_moments.to_a[1..7].each { |hu| assert_in_delta(0.0, hu, 0.000001) } hu_moments = @moment4.hu - assert_in_delta(0.361650, hu_moments[0], 0.000001) - assert_in_delta(0.000625, hu_moments[1], 0.000001) - hu_moments[2..7].each { |hu| + assert_equal(CvHuMoments, hu_moments.class) + assert_in_delta(0.361650, hu_moments.hu1, 0.000001) + assert_in_delta(0.000625, hu_moments.hu2, 0.000001) + hu_moments.to_a[2..7].each { |hu| assert_in_delta(0.0, hu, 0.000001) } end