mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat#gaussian_blur!
This commit is contained in:
parent
1d258996ba
commit
35c696fe1f
4 changed files with 73 additions and 11 deletions
|
@ -1254,6 +1254,7 @@ namespace rubyopencv {
|
||||||
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, "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, "gaussian_blur!", RUBY_METHOD_FUNC(rb_gaussian_blur_bang), -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
|
||||||
rb_define_method(rb_klass, "adaptive_threshold", RUBY_METHOD_FUNC(rb_adaptive_threshold), 5); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "adaptive_threshold", RUBY_METHOD_FUNC(rb_adaptive_threshold), 5); // in ext/opencv/mat_imgproc.cpp
|
||||||
|
|
|
@ -351,6 +351,19 @@ namespace rubyopencv {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cv::Mat* rb_gaussian_blur_internal(int argc, VALUE *argv, VALUE self, cv::Mat* destptr) {
|
||||||
|
VALUE ksize, sigma_x, sigma_y, border_type;
|
||||||
|
rb_scan_args(argc, argv, "22", &ksize, &sigma_x, &sigma_y, &border_type);
|
||||||
|
double sigma_y_value = NIL_P(sigma_y) ? 0 : NUM2DBL(sigma_y);
|
||||||
|
int border_type_value = NIL_P(border_type) ? cv::BORDER_DEFAULT : NUM2INT(border_type);
|
||||||
|
|
||||||
|
cv::Mat* selfptr = obj2mat(self);
|
||||||
|
cv::GaussianBlur(*selfptr, *destptr, *(Size::obj2size(ksize)), NUM2DBL(sigma_x),
|
||||||
|
sigma_y_value, border_type_value);
|
||||||
|
|
||||||
|
return destptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Blurs an image using a Gaussian filter.
|
* Blurs an image using a Gaussian filter.
|
||||||
*
|
*
|
||||||
|
@ -366,23 +379,32 @@ namespace rubyopencv {
|
||||||
* @opencv_func cv::GaussianBlur
|
* @opencv_func cv::GaussianBlur
|
||||||
*/
|
*/
|
||||||
VALUE rb_gaussian_blur(int argc, VALUE *argv, VALUE self) {
|
VALUE rb_gaussian_blur(int argc, VALUE *argv, VALUE self) {
|
||||||
VALUE ksize, sigma_x, sigma_y, border_type;
|
cv::Mat* destptr = new cv::Mat();
|
||||||
rb_scan_args(argc, argv, "22", &ksize, &sigma_x, &sigma_y, &border_type);
|
|
||||||
double sigma_y_value = NIL_P(sigma_y) ? 0 : NUM2DBL(sigma_y);
|
|
||||||
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::GaussianBlur(*selfptr, *dstptr, *(Size::obj2size(ksize)), NUM2DBL(sigma_x),
|
rb_gaussian_blur_internal(argc, argv, self, destptr);
|
||||||
sigma_y_value, border_type_value);
|
|
||||||
}
|
}
|
||||||
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 gaussian_blur!(ksize, sigma_x, sigma_y = 0, border_type = BORDER_DEFAULT)
|
||||||
|
* @see #gaussian_blur
|
||||||
|
*/
|
||||||
|
VALUE rb_gaussian_blur_bang(int argc, VALUE *argv, VALUE self) {
|
||||||
|
cv::Mat* destptr = obj2mat(self);
|
||||||
|
try {
|
||||||
|
rb_gaussian_blur_internal(argc, argv, self, destptr);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace rubyopencv {
|
||||||
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_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_gaussian_blur_bang(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);
|
||||||
VALUE rb_adaptive_threshold(VALUE self, VALUE max_value, VALUE adaptive_method,
|
VALUE rb_adaptive_threshold(VALUE self, VALUE max_value, VALUE adaptive_method,
|
||||||
|
|
|
@ -459,6 +459,44 @@ class TestCvMat < OpenCVTestCase
|
||||||
# Cv::wait_key
|
# Cv::wait_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_gaussian_blur_bang
|
||||||
|
m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
m1 = m0.clone
|
||||||
|
m2 = m0.clone
|
||||||
|
m3 = m0.clone
|
||||||
|
|
||||||
|
ksize = Cv::Size.new(3, 3)
|
||||||
|
m1.gaussian_blur!(ksize, 3)
|
||||||
|
m2.gaussian_blur!(ksize, 3, 5)
|
||||||
|
m3.gaussian_blur!(ksize, 3, 5, Cv::BORDER_REPLICATE)
|
||||||
|
|
||||||
|
gaussian_blurs = [m1, m2, m3]
|
||||||
|
gaussian_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.gaussian_blur!(ksize, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.gaussian_blur!(ksize, 3, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.gaussian_blur!(ksize, 3, 5, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
|
||||||
|
# w = Window.new('Gaussian blur')
|
||||||
|
# m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
# ksize = Cv::Size.new(13, 13)
|
||||||
|
# m0.gaussian_blur!(ksize, 3, 5, Cv::BORDER_REPLICATE)
|
||||||
|
# w.show(m0)
|
||||||
|
# Cv::wait_key
|
||||||
|
end
|
||||||
|
|
||||||
def test_median_blur
|
def test_median_blur
|
||||||
m0 = Cv::Mat.ones(3, 3, Cv::CV_8U)
|
m0 = Cv::Mat.ones(3, 3, Cv::CV_8U)
|
||||||
m0[1, 1] = Cv::Scalar.new(0)
|
m0[1, 1] = Cv::Scalar.new(0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue