mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat#laplacian!
This commit is contained in:
parent
21769f8553
commit
0c8f2fc593
4 changed files with 80 additions and 18 deletions
|
@ -1236,6 +1236,7 @@ namespace rubyopencv {
|
|||
rb_define_method(rb_klass, "canny", RUBY_METHOD_FUNC(rb_canny), -1); // in ext/opencv/mat_imgproc.cpp
|
||||
rb_define_method(rb_klass, "canny!", RUBY_METHOD_FUNC(rb_canny_bang), -1); // in ext/opencv/mat_imgproc.cpp
|
||||
rb_define_method(rb_klass, "laplacian", RUBY_METHOD_FUNC(rb_laplacian), -1); // in ext/opencv/mat_imgproc.cpp
|
||||
rb_define_method(rb_klass, "laplacian!", RUBY_METHOD_FUNC(rb_laplacian_bang), -1); // in ext/opencv/mat_imgproc.cpp
|
||||
|
||||
rb_define_method(rb_klass, "line", RUBY_METHOD_FUNC(rb_line), -1); // in ext/opencv/mat_drawing.cpp
|
||||
rb_define_method(rb_klass, "line!", RUBY_METHOD_FUNC(rb_line_bang), -1); // in ext/opencv/mat_drawing.cpp
|
||||
|
|
|
@ -123,6 +123,21 @@ namespace rubyopencv {
|
|||
return self;
|
||||
}
|
||||
|
||||
cv::Mat* rb_laplacian_internal(int argc, VALUE *argv, VALUE self, cv::Mat* destptr) {
|
||||
VALUE ddepth, ksize, scale, delta, border_type;
|
||||
rb_scan_args(argc, argv, "14", &ddepth, &ksize, &scale, &delta, &border_type);
|
||||
int ksize_value = NIL_P(ksize) ? 3 : NUM2INT(ksize);
|
||||
double scale_value = NIL_P(scale) ? 1.0 : NUM2DBL(scale);
|
||||
double delta_value = NIL_P(delta) ? 0.0 : NUM2DBL(delta);
|
||||
int border_type_value = NIL_P(border_type) ? cv::BORDER_DEFAULT : NUM2INT(border_type);
|
||||
|
||||
cv::Mat* selfptr = obj2mat(self);
|
||||
cv::Laplacian(*selfptr, *destptr, NUM2INT(ddepth), ksize_value, scale_value,
|
||||
delta_value, border_type_value);
|
||||
|
||||
return destptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculates the Laplacian of an image.
|
||||
*
|
||||
|
@ -137,18 +152,9 @@ namespace rubyopencv {
|
|||
* @opencv_func cv::Laplacian
|
||||
*/
|
||||
VALUE rb_laplacian(int argc, VALUE *argv, VALUE self) {
|
||||
VALUE ddepth, ksize, scale, delta, border_type;
|
||||
rb_scan_args(argc, argv, "14", &ddepth, &ksize, &scale, &delta, &border_type);
|
||||
int ksize_value = NIL_P(ksize) ? 3 : NUM2INT(ksize);
|
||||
double scale_value = NIL_P(scale) ? 1.0 : NUM2DBL(scale);
|
||||
double delta_value = NIL_P(delta) ? 0.0 : NUM2DBL(delta);
|
||||
int border_type_value = NIL_P(border_type) ? cv::BORDER_DEFAULT : NUM2INT(border_type);
|
||||
|
||||
cv::Mat* selfptr = obj2mat(self);
|
||||
cv::Mat* destptr = new cv::Mat();
|
||||
try {
|
||||
cv::Laplacian(*selfptr, *destptr, NUM2INT(ddepth), ksize_value, scale_value,
|
||||
delta_value, border_type_value);
|
||||
rb_laplacian_internal(argc, argv, self, destptr);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
delete destptr;
|
||||
|
@ -158,6 +164,22 @@ namespace rubyopencv {
|
|||
return mat2obj(destptr, CLASS_OF(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* @overload laplacian!(ddepth, ksize = 1, scale = 1, delta = 0, border_type = BORDER_DEFAULT)
|
||||
* @see (#laplacian)
|
||||
*/
|
||||
VALUE rb_laplacian_bang(int argc, VALUE *argv, VALUE self) {
|
||||
cv::Mat* destptr = obj2mat(self);
|
||||
try {
|
||||
rb_laplacian_internal(argc, argv, self, destptr);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
Error::raise(e);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an image from one color space to another.
|
||||
*
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace rubyopencv {
|
|||
VALUE rb_canny(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_canny_bang(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_laplacian(int argc, VALUE *argv, VALUE self);
|
||||
VALUE rb_laplacian_bang(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_bang(int argc, VALUE *argv, VALUE self);
|
||||
|
|
|
@ -216,12 +216,12 @@ class TestCvMat < OpenCVTestCase
|
|||
m0 = Cv::imread(FILENAME_LENA256x256, 0)
|
||||
|
||||
laplacian = []
|
||||
laplacian << m0.laplacian(CV_32F)
|
||||
laplacian << m0.laplacian(CV_32F, 5, 0.5, 32, BORDER_CONSTANT)
|
||||
laplacian << m0.laplacian(CV_8U)
|
||||
laplacian << m0.laplacian(CV_8U, 5, 0.5, 32, BORDER_CONSTANT)
|
||||
laplacian.each { |m|
|
||||
assert_equal(m0.rows, m.rows)
|
||||
assert_equal(m0.cols, m.cols)
|
||||
assert_equal(CV_32F, m.depth)
|
||||
assert_equal(CV_8U, m.depth)
|
||||
assert_equal(m0.dims, m.dims)
|
||||
assert_equal(m0.channels, m.channels)
|
||||
}
|
||||
|
@ -230,20 +230,58 @@ class TestCvMat < OpenCVTestCase
|
|||
m0.laplacian(DUMMY_OBJ, 5, 0.5, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian(CV_32F, DUMMY_OBJ, 0.5, 32, BORDER_CONSTANT)
|
||||
m0.laplacian(CV_8U, DUMMY_OBJ, 0.5, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian(CV_32F, 5, DUMMY_OBJ, 32, BORDER_CONSTANT)
|
||||
m0.laplacian(CV_8U, 5, DUMMY_OBJ, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian(CV_32F, 5, 0.5, DUMMY_OBJ, BORDER_CONSTANT)
|
||||
m0.laplacian(CV_8U, 5, 0.5, DUMMY_OBJ, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian(CV_32F, 5, 0.5, 32, DUMMY_OBJ)
|
||||
m0.laplacian(CV_8U, 5, 0.5, 32, DUMMY_OBJ)
|
||||
}
|
||||
|
||||
# w = Window.new('Laplacian')
|
||||
# w.show(m0.laplacian(CV_32F))
|
||||
# w.show(m0.laplacian(CV_8U))
|
||||
# Cv::wait_key
|
||||
end
|
||||
|
||||
def test_laplacian_bang
|
||||
m0 = Cv::imread(FILENAME_LENA256x256, 0)
|
||||
m1 = m0.clone
|
||||
m0.laplacian!(CV_8U)
|
||||
m1.laplacian!(CV_8U, 5, 0.5, 32, BORDER_CONSTANT)
|
||||
|
||||
laplacian = [m0, m1]
|
||||
laplacian.each { |m|
|
||||
assert_equal(m0.rows, m.rows)
|
||||
assert_equal(m0.cols, m.cols)
|
||||
assert_equal(CV_8U, m.depth)
|
||||
assert_equal(m0.dims, m.dims)
|
||||
assert_equal(m0.channels, m.channels)
|
||||
}
|
||||
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian!(DUMMY_OBJ, 5, 0.5, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian!(CV_8U, DUMMY_OBJ, 0.5, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian!(CV_8U, 5, DUMMY_OBJ, 32, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian!(CV_8U, 5, 0.5, DUMMY_OBJ, BORDER_CONSTANT)
|
||||
}
|
||||
assert_raise(TypeError) {
|
||||
m0.laplacian!(CV_8U, 5, 0.5, 32, DUMMY_OBJ)
|
||||
}
|
||||
|
||||
# w = Window.new('Laplacian')
|
||||
# m0 = Cv::imread(FILENAME_LENA256x256, 0)
|
||||
# m0.laplacian!(CV_8U)
|
||||
# w.show(m0)
|
||||
# Cv::wait_key
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue