mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added some tests
This commit is contained in:
parent
fcae1a1d44
commit
82613bd2d8
3 changed files with 74 additions and 23 deletions
|
@ -247,17 +247,11 @@ void define_ruby_class()
|
|||
rb_define_method(rb_klass, "not", RUBY_METHOD_FUNC(rb_not), 0);
|
||||
rb_define_method(rb_klass, "not!", RUBY_METHOD_FUNC(rb_not_bang), 0);
|
||||
rb_define_method(rb_klass, "eq", RUBY_METHOD_FUNC(rb_eq), 1);
|
||||
// rb_define_alias(rb_klass, "==", "eq");
|
||||
rb_define_method(rb_klass, "gt", RUBY_METHOD_FUNC(rb_gt), 1);
|
||||
// rb_define_alias(rb_klass, ">", "gt");
|
||||
rb_define_method(rb_klass, "ge", RUBY_METHOD_FUNC(rb_ge), 1);
|
||||
// rb_define_alias(rb_klass, ">=", "ge");
|
||||
rb_define_method(rb_klass, "lt", RUBY_METHOD_FUNC(rb_lt), 1);
|
||||
// rb_define_alias(rb_klass, "<", "lt");
|
||||
rb_define_method(rb_klass, "le", RUBY_METHOD_FUNC(rb_le), 1);
|
||||
// rb_define_alias(rb_klass, "<=", "le");
|
||||
rb_define_method(rb_klass, "ne", RUBY_METHOD_FUNC(rb_ne), 1);
|
||||
// rb_define_alias(rb_klass, "!=", "ne");
|
||||
rb_define_method(rb_klass, "in_range", RUBY_METHOD_FUNC(rb_in_range), 2);
|
||||
rb_define_method(rb_klass, "abs_diff", RUBY_METHOD_FUNC(rb_abs_diff), 1);
|
||||
rb_define_method(rb_klass, "count_non_zero", RUBY_METHOD_FUNC(rb_count_non_zero), 0);
|
||||
|
@ -1189,13 +1183,6 @@ rb_aref(VALUE self, VALUE args)
|
|||
case 2:
|
||||
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[0], index[1], index[2]);
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
scalar = cvGetND(CVARR(self), index);
|
||||
}
|
||||
|
@ -1225,13 +1212,6 @@ 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);
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
cvSetND(CVARR(self), index, scalar);
|
||||
}
|
||||
|
@ -3340,7 +3320,7 @@ rb_resize(int argc, VALUE *argv, VALUE self)
|
|||
rb_scan_args(argc, argv, "11", &size, &interpolation);
|
||||
VALUE dest = new_object(VALUE_TO_CVSIZE(size), cvGetElemType(CVARR(self)));
|
||||
cvResize(CVARR(self), CVARR(dest), CVMETHOD("INTERPOLATION_METHOD", interpolation, CV_INTER_LINEAR));
|
||||
return self;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -127,7 +127,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_find_corner_sub_pix
|
||||
flunk('FIXME: CvMat#corner_min_eigen_val is not implemented yet.')
|
||||
flunk('FIXME: CvMat#find_corner_sub_pix is not implemented yet.')
|
||||
end
|
||||
|
||||
def test_good_features_to_track
|
||||
|
@ -229,5 +229,20 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
assert_equal('f170c05fa50c3ac2a762d7b3f5c4ae2f', hash_img(mat2))
|
||||
assert_equal('4d949d5083405381ad9ea09dcd95e5a2', hash_img(mat3))
|
||||
end
|
||||
|
||||
def test_resize
|
||||
mat0 = CvMat.load(FILENAME_LENA256x256, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
|
||||
mat1 = mat0.resize(CvSize.new(512, 512))
|
||||
mat2 = mat0.resize(CvSize.new(512, 512), :linear)
|
||||
mat3 = mat0.resize(CvSize.new(512, 512), :nn)
|
||||
mat4 = mat0.resize(CvSize.new(128, 128), :area)
|
||||
mat5 = mat0.resize(CvSize.new(128, 128), :cubic)
|
||||
|
||||
assert_equal('b2203ccca2c17b042a90b79704c0f535', hash_img(mat1))
|
||||
assert_equal('b2203ccca2c17b042a90b79704c0f535', hash_img(mat2))
|
||||
assert_equal('ba8f2dee2329aaa6309de4770fc8fa55', hash_img(mat3))
|
||||
assert_equal('8a28a2748b0cfc87205d65c625187867', hash_img(mat4))
|
||||
assert_equal('de5c30fcd9e817aa282ab05388de995b', hash_img(mat5))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -87,7 +87,63 @@ class TestOpenCV < OpenCVTestCase
|
|||
end
|
||||
|
||||
def test_cvt_color_funcs
|
||||
flunk('FIXME: cvtColor functions are not tested yet.')
|
||||
mat_1ch = CvMat.new(1, 1, :cv8u, 1)
|
||||
mat_1ch[0] = CvScalar.new(10)
|
||||
|
||||
mat_3ch = CvMat.new(1, 1, :cv8u, 3)
|
||||
mat_3ch[0] = CvScalar.new(10, 20, 30)
|
||||
|
||||
mat_4ch = CvMat.new(1, 1, :cv8u, 4)
|
||||
mat_4ch[0] = CvScalar.new(10, 20, 30, 40)
|
||||
|
||||
gray_rgb = (0.299 * mat_3ch[0][0] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][2]).round
|
||||
gray_bgr = (0.299 * mat_3ch[0][2] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][0]).round
|
||||
|
||||
# RGB(A) <=> RGB(A)
|
||||
[mat_3ch.BGR2BGRA, mat_3ch.RGB2RGBA].each { |m|
|
||||
assert_equal(4, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(10, 20, 30, 255), m[0])
|
||||
}
|
||||
[mat_3ch.BGR2RGBA, mat_3ch.RGB2BGRA].each { |m|
|
||||
assert_equal(4, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 255), m[0])
|
||||
}
|
||||
[mat_4ch.BGRA2BGR, mat_4ch.RGBA2RGB].each { |m|
|
||||
assert_equal(3, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(10, 20, 30, 0), m[0])
|
||||
}
|
||||
[mat_4ch.RGBA2BGR, mat_4ch.BGRA2RGB].each { |m|
|
||||
assert_equal(3, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
|
||||
}
|
||||
[mat_3ch.BGR2RGB, mat_3ch.RGB2BGR].each { |m|
|
||||
assert_equal(3, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
|
||||
}
|
||||
[mat_4ch.BGRA2RGBA, mat_4ch.RGBA2BGRA].each { |m|
|
||||
assert_equal(4, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(30, 20, 10, 40), m[0])
|
||||
}
|
||||
|
||||
# RGB <=> GRAY
|
||||
[mat_3ch.BGR2GRAY, mat_4ch.BGRA2GRAY].each { |m|
|
||||
assert_equal(1, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(gray_bgr, 0, 0, 0), m[0])
|
||||
}
|
||||
[mat_3ch.RGB2GRAY, mat_4ch.RGBA2GRAY].each { |m|
|
||||
assert_equal(1, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(gray_rgb, 0, 0, 0), m[0])
|
||||
}
|
||||
[mat_1ch.GRAY2BGR, mat_1ch.GRAY2RGB].each { |m|
|
||||
assert_equal(3, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(10, 10, 10, 0), m[0])
|
||||
}
|
||||
[mat_1ch.GRAY2BGRA, mat_1ch.GRAY2RGBA].each { |m|
|
||||
assert_equal(4, m.channel)
|
||||
assert_cvscalar_equal(CvScalar.new(10, 10, 10, 255), m[0])
|
||||
}
|
||||
|
||||
flunk('FIXME: Most cvtColor functions are not tested yet.')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue