mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added CvMat#copy_make_border
This commit is contained in:
parent
7add8ec805
commit
53fd238569
5 changed files with 76 additions and 0 deletions
|
@ -330,6 +330,7 @@ void define_ruby_class()
|
|||
rb_define_method(rb_klass, "morphology", RUBY_METHOD_FUNC(rb_morphology), -1);
|
||||
|
||||
rb_define_method(rb_klass, "smooth", RUBY_METHOD_FUNC(rb_smooth), -1);
|
||||
rb_define_method(rb_klass, "copy_make_border", RUBY_METHOD_FUNC(rb_copy_make_border), -1);
|
||||
rb_define_method(rb_klass, "filter2d", RUBY_METHOD_FUNC(rb_filter2d), -1);
|
||||
rb_define_method(rb_klass, "integral", RUBY_METHOD_FUNC(rb_integral), -1);
|
||||
rb_define_method(rb_klass, "threshold", RUBY_METHOD_FUNC(rb_threshold), -1);
|
||||
|
@ -3723,6 +3724,45 @@ rb_filter2d(int argc, VALUE *argv, VALUE self)
|
|||
return _dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* copy_make_border(<i>border_type, size, offset[,value = CvScalar.new(0)]</i>)
|
||||
*
|
||||
* Copies image and makes border around it.
|
||||
* <i>border_type</i>:
|
||||
* - IPL_BORDER_CONSTANT, :constant
|
||||
* border is filled with the fixed value, passed as last parameter of the function.
|
||||
* - IPL_BORDER_REPLICATE, :replicate
|
||||
* the pixels from the top and bottom rows, the left-most and right-most columns are replicated to fill the border
|
||||
* <i>size</i>: The destination image size
|
||||
* <i>offset</i>: Coordinates of the top-left corner (or bottom-left in the case of images with bottom-left origin) of the destination image rectangle.
|
||||
* <i>value</i>: Value of the border pixels if bordertype is IPL_BORDER_CONSTANT or :constant.
|
||||
*/
|
||||
VALUE
|
||||
rb_copy_make_border(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
VALUE border_type, size, offset, value, dest;
|
||||
rb_scan_args(argc, argv, "31", &border_type, &size, &offset, &value);
|
||||
dest = new_mat_kind_object(VALUE_TO_CVSIZE(size), self);
|
||||
|
||||
int type = 0;
|
||||
if (SYMBOL_P(border_type)) {
|
||||
ID type_id = rb_to_id(border_type);
|
||||
if (type_id == rb_intern("constant"))
|
||||
type = IPL_BORDER_CONSTANT;
|
||||
else if (type_id == rb_intern("replicate"))
|
||||
type = IPL_BORDER_REPLICATE;
|
||||
else
|
||||
rb_raise(rb_eArgError, "Invalid border_type (should be :constant or :replicate)");
|
||||
}
|
||||
else
|
||||
type = NUM2INT(border_type);
|
||||
|
||||
cvCopyMakeBorder(CVARR(self), CVARR(dest), VALUE_TO_CVPOINT(offset), type,
|
||||
NIL_P(value) ? cvScalar(0) : VALUE_TO_CVSCALAR(value));
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* integral(<i>need_sqsum = false, need_tilted_sum = false</i>) -> [cvmat, cvmat or nil, cvmat or nil]
|
||||
|
|
|
@ -190,6 +190,7 @@ VALUE rb_dilate_bang(int argc, VALUE *argv, VALUE self);
|
|||
VALUE rb_morphology(int argc, VALUE *argv, VALUE self);
|
||||
|
||||
VALUE rb_smooth(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_copy_make_border(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_filter2d(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_integral(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_threshold(int argc, VALUE *argv, VALUE self);
|
||||
|
|
|
@ -215,6 +215,10 @@ define_ruby_module()
|
|||
rb_define_const(rb_module, "CV_THRESH_TOZERO_INV", INT2FIX(CV_THRESH_TOZERO_INV));
|
||||
rb_define_const(rb_module, "CV_THRESH_OTSU", INT2FIX(CV_THRESH_OTSU));
|
||||
|
||||
/* Border type */
|
||||
rb_define_const(rb_module, "IPL_BORDER_CONSTANT", INT2FIX(IPL_BORDER_CONSTANT));
|
||||
rb_define_const(rb_module, "IPL_BORDER_REPLICATE", INT2FIX(IPL_BORDER_REPLICATE));
|
||||
|
||||
/* Retrieval mode */
|
||||
rb_define_const(rb_module, "CV_RETR_EXTERNAL", INT2FIX(CV_RETR_EXTERNAL));
|
||||
rb_define_const(rb_module, "CV_RETR_LIST", INT2FIX(CV_RETR_LIST));
|
||||
|
|
|
@ -802,6 +802,33 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_copy_make_border
|
||||
mat0 = create_cvmat(32, 32, :cv8u, 1) { CvScalar.new(128) }
|
||||
|
||||
[IPL_BORDER_CONSTANT, :constant].each { |type|
|
||||
mat1 = mat0.copy_make_border(type, CvSize.new(64, 48), CvPoint.new(16, 8), 255)
|
||||
assert_equal('5e231f8ca051b8f93e4aaa42d193d095', hash_img(mat1))
|
||||
}
|
||||
|
||||
[IPL_BORDER_REPLICATE, :replicate].each { |type|
|
||||
mat2 = mat0.copy_make_border(type, CvSize.new(300, 300), CvPoint.new(30, 30))
|
||||
assert_equal('96940dc9e3abb6e2556ea51af1468031', hash_img(mat2))
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border(DUMMY_OBJ, CvSize.new(64, 48), CvPoint.new(16, 8))
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border(IPL_BORDER_CONSTANT, CvSize.new(64, 48), DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
mat0.copy_make_border(IPL_BORDER_CONSTANT, CvSize.new(64, 48), CvPoint.new(16, 8), DUMMY_OBJ)
|
||||
}
|
||||
assert_raise(ArgumentError) {
|
||||
mat0.copy_make_border(:dummy, CvSize.new(64, 48), CvPoint.new(16, 8), DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_integral
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
|
||||
|
|
|
@ -44,6 +44,10 @@ class TestOpenCV < OpenCVTestCase
|
|||
assert_equal(3, CV_MEDIAN)
|
||||
assert_equal(4, CV_BILATERAL)
|
||||
|
||||
# Border types
|
||||
assert_equal(0, IPL_BORDER_CONSTANT)
|
||||
assert_equal(1, IPL_BORDER_REPLICATE)
|
||||
|
||||
# Thresholding types
|
||||
assert_equal(0, CV_THRESH_BINARY)
|
||||
assert_equal(1, CV_THRESH_BINARY_INV)
|
||||
|
|
Loading…
Add table
Reference in a new issue