1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

modified CvMoments#hu to return CvHuMoments

This commit is contained in:
ser1zw 2011-03-06 23:07:05 +09:00
parent 13ccfb5257
commit 72d9de3a65
2 changed files with 13 additions and 18 deletions

View file

@ -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));
}
/*

View file

@ -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