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
4ec9d3e235
commit
f0c42c52ea
5 changed files with 64 additions and 1 deletions
|
@ -895,7 +895,8 @@ namespace rubyopencv {
|
||||||
|
|
||||||
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -1); // in ext/opencv/mat_imgproc.cpp
|
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -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), -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, "save", RUBY_METHOD_FUNC(rb_save), -1);
|
rb_define_method(rb_klass, "save", RUBY_METHOD_FUNC(rb_save), -1);
|
||||||
|
|
||||||
rb_define_method(rb_klass, "imencode", RUBY_METHOD_FUNC(rb_imencode), -1);
|
rb_define_method(rb_klass, "imencode", RUBY_METHOD_FUNC(rb_imencode), -1);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "mat.hpp"
|
#include "mat.hpp"
|
||||||
#include "size.hpp"
|
#include "size.hpp"
|
||||||
|
#include "point.hpp"
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -177,5 +178,32 @@ namespace rubyopencv {
|
||||||
|
|
||||||
return mat2obj(destptr, CLASS_OF(self));
|
return mat2obj(destptr, CLASS_OF(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Blurs an image using the normalized box filter.
|
||||||
|
*
|
||||||
|
* @overload blur(ksize, anchor = Point.new(-1, -1), border_type = BORDER_DEFAULT)
|
||||||
|
* @param ksize [Integer] Blurring kernel size.
|
||||||
|
* @param border_type [Integer] Border mode used to extrapolate pixels outside of the image.
|
||||||
|
* @return [Mat] Output array
|
||||||
|
* @opencv_func cv::blur
|
||||||
|
*/
|
||||||
|
VALUE rb_blur(int argc, VALUE *argv, VALUE self) {
|
||||||
|
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::Mat* dstptr = empty_mat();
|
||||||
|
try {
|
||||||
|
cv::blur(*selfptr, *dstptr, *(Size::obj2size(ksize)), anchor_value, border_type_value);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mat2obj(dstptr, CLASS_OF(self));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace rubyopencv {
|
||||||
VALUE rb_laplacian(int argc, VALUE *argv, VALUE self);
|
VALUE rb_laplacian(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_cvt_color(int argc, VALUE *argv, VALUE self);
|
VALUE rb_cvt_color(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
||||||
|
VALUE rb_blur(int argc, VALUE *argv, VALUE self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace rubyopencv {
|
||||||
namespace Point {
|
namespace Point {
|
||||||
void init();
|
void init();
|
||||||
cv::Point conpatible_obj2point(VALUE obj);
|
cv::Point conpatible_obj2point(VALUE obj);
|
||||||
|
cv::Point* obj2point(VALUE obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,4 +148,36 @@ class TestCvMat < OpenCVTestCase
|
||||||
Cv::add_weighted(m0, 0.5, m1, 0.5, 32, DUMMY_OBJ)
|
Cv::add_weighted(m0, 0.5, m1, 0.5, 32, DUMMY_OBJ)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_blur
|
||||||
|
m0 = Cv::imread(FILENAME_LENA256x256, -1)
|
||||||
|
|
||||||
|
ksize = Cv::Size.new(3, 3)
|
||||||
|
anchor = Cv::Point.new(1, 1)
|
||||||
|
blurs = []
|
||||||
|
blurs << m0.blur(ksize)
|
||||||
|
blurs << m0.blur(ksize, anchor)
|
||||||
|
blurs << m0.blur(ksize, anchor, Cv::BORDER_REPLICATE)
|
||||||
|
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')
|
||||||
|
# w.show(m0.blur(ksize, anchor, Cv::BORDER_REPLICATE))
|
||||||
|
# Cv::wait_key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue