mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat#blur!
This commit is contained in:
parent
30b9449115
commit
1d258996ba
4 changed files with 72 additions and 10 deletions
|
@ -1252,6 +1252,7 @@ namespace rubyopencv {
|
||||||
rb_define_method(rb_klass, "cvt_color", RUBY_METHOD_FUNC(rb_cvt_color), -1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "cvt_color", RUBY_METHOD_FUNC(rb_cvt_color), -1); // in ext/opencv/mat_imgproc.cpp
|
||||||
rb_define_method(rb_klass, "cvt_color!", RUBY_METHOD_FUNC(rb_cvt_color_bang), -1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "cvt_color!", RUBY_METHOD_FUNC(rb_cvt_color_bang), -1); // in ext/opencv/mat_imgproc.cpp
|
||||||
rb_define_method(rb_klass, "blur", RUBY_METHOD_FUNC(rb_blur), -1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "blur", RUBY_METHOD_FUNC(rb_blur), -1); // in ext/opencv/mat_imgproc.cpp
|
||||||
|
rb_define_method(rb_klass, "blur!", RUBY_METHOD_FUNC(rb_blur_bang), -1); // in ext/opencv/mat_imgproc.cpp
|
||||||
rb_define_method(rb_klass, "gaussian_blur", RUBY_METHOD_FUNC(rb_gaussian_blur), -1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "gaussian_blur", RUBY_METHOD_FUNC(rb_gaussian_blur), -1); // in ext/opencv/mat_imgproc.cpp
|
||||||
rb_define_method(rb_klass, "median_blur", RUBY_METHOD_FUNC(rb_median_blur), 1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "median_blur", RUBY_METHOD_FUNC(rb_median_blur), 1); // in ext/opencv/mat_imgproc.cpp
|
||||||
rb_define_method(rb_klass, "threshold", RUBY_METHOD_FUNC(rb_threshold), 3); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "threshold", RUBY_METHOD_FUNC(rb_threshold), 3); // in ext/opencv/mat_imgproc.cpp
|
||||||
|
|
|
@ -301,6 +301,18 @@ namespace rubyopencv {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cv::Mat* rb_blur_internal(int argc, VALUE *argv, VALUE self, cv::Mat* destptr) {
|
||||||
|
VALUE ksize, anchor, border_type;
|
||||||
|
rb_scan_args(argc, argv, "12", &ksize, &anchor, &border_type);
|
||||||
|
cv::Point anchor_value = NIL_P(anchor) ? cv::Point(-1, -1) : *(Point::obj2point(anchor));
|
||||||
|
int border_type_value = NIL_P(border_type) ? cv::BORDER_DEFAULT : NUM2INT(border_type);
|
||||||
|
|
||||||
|
cv::Mat* selfptr = obj2mat(self);
|
||||||
|
cv::blur(*selfptr, *destptr, *(Size::obj2size(ksize)), anchor_value, border_type_value);
|
||||||
|
|
||||||
|
return destptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Blurs an image using the normalized box filter.
|
* Blurs an image using the normalized box filter.
|
||||||
*
|
*
|
||||||
|
@ -311,22 +323,32 @@ namespace rubyopencv {
|
||||||
* @opencv_func cv::blur
|
* @opencv_func cv::blur
|
||||||
*/
|
*/
|
||||||
VALUE rb_blur(int argc, VALUE *argv, VALUE self) {
|
VALUE rb_blur(int argc, VALUE *argv, VALUE self) {
|
||||||
VALUE ksize, anchor, border_type;
|
cv::Mat* destptr = new cv::Mat();
|
||||||
rb_scan_args(argc, argv, "12", &ksize, &anchor, &border_type);
|
|
||||||
cv::Point anchor_value = NIL_P(anchor) ? cv::Point(-1, -1) : *(Point::obj2point(anchor));
|
|
||||||
int border_type_value = NIL_P(border_type) ? cv::BORDER_DEFAULT : NUM2INT(border_type);
|
|
||||||
|
|
||||||
cv::Mat* selfptr = obj2mat(self);
|
|
||||||
cv::Mat* dstptr = new cv::Mat();
|
|
||||||
try {
|
try {
|
||||||
cv::blur(*selfptr, *dstptr, *(Size::obj2size(ksize)), anchor_value, border_type_value);
|
rb_blur_internal(argc, argv, self, destptr);
|
||||||
}
|
}
|
||||||
catch (cv::Exception& e) {
|
catch (cv::Exception& e) {
|
||||||
delete dstptr;
|
delete destptr;
|
||||||
Error::raise(e);
|
Error::raise(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mat2obj(dstptr, CLASS_OF(self));
|
return mat2obj(destptr, CLASS_OF(self));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @overload blur!(ksize, anchor = Point.new(-1, -1), border_type = BORDER_DEFAULT)
|
||||||
|
* @see #blue
|
||||||
|
*/
|
||||||
|
VALUE rb_blur_bang(int argc, VALUE *argv, VALUE self) {
|
||||||
|
cv::Mat* destptr = obj2mat(self);
|
||||||
|
try {
|
||||||
|
rb_blur_internal(argc, argv, self, destptr);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace rubyopencv {
|
||||||
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_resize_bang(int argc, VALUE *argv, VALUE self);
|
VALUE rb_resize_bang(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_blur(int argc, VALUE *argv, VALUE self);
|
VALUE rb_blur(int argc, VALUE *argv, VALUE self);
|
||||||
|
VALUE rb_blur_bang(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_gaussian_blur(int argc, VALUE *argv, VALUE self);
|
VALUE rb_gaussian_blur(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_median_blur(VALUE self, VALUE ksize);
|
VALUE rb_median_blur(VALUE self, VALUE ksize);
|
||||||
VALUE rb_threshold(VALUE self, VALUE threshold, VALUE max_value, VALUE threshold_type);
|
VALUE rb_threshold(VALUE self, VALUE threshold, VALUE max_value, VALUE threshold_type);
|
||||||
|
|
|
@ -390,6 +390,44 @@ class TestCvMat < OpenCVTestCase
|
||||||
# Cv::wait_key
|
# Cv::wait_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_blur_bang
|
||||||
|
m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
m1 = m0.clone
|
||||||
|
m2 = m0.clone
|
||||||
|
m3 = m0.clone
|
||||||
|
|
||||||
|
ksize = Cv::Size.new(3, 3)
|
||||||
|
anchor = Cv::Point.new(1, 1)
|
||||||
|
m0.blur!(ksize)
|
||||||
|
m0.blur!(ksize, anchor)
|
||||||
|
m0.blur!(ksize, anchor, Cv::BORDER_REPLICATE)
|
||||||
|
|
||||||
|
blurs = [m1, m2, m3]
|
||||||
|
blurs.each { |m|
|
||||||
|
assert_equal(m0.rows, m.rows)
|
||||||
|
assert_equal(m0.cols, m.cols)
|
||||||
|
assert_equal(m0.depth, m.depth)
|
||||||
|
assert_equal(m0.dims, m.dims)
|
||||||
|
assert_equal(m0.channels, m.channels)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.blur!(DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.blur!(ksize, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.blur!(ksize, anchor, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
|
||||||
|
# w = Window.new('Blur')
|
||||||
|
# m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
# m0.blur!(ksize, anchor, Cv::BORDER_REPLICATE)
|
||||||
|
# w.show(m0)
|
||||||
|
# Cv::wait_key
|
||||||
|
end
|
||||||
|
|
||||||
def test_gaussian_blur
|
def test_gaussian_blur
|
||||||
m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue