1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

add Mat#canny!

This commit is contained in:
ser1zw 2017-04-30 03:18:34 +09:00
parent 668e7b842a
commit e157cd4f0a
4 changed files with 75 additions and 15 deletions

View file

@ -67,19 +67,7 @@ namespace rubyopencv {
return self;
}
/**
* Finds edges in an image using the [Canny86] algorithm.
*
* @overload canny(threshold1, threshold2, aperture_size = 3, l2gradient = false)
* @param threshold1 [Number] First threshold for the hysteresis procedure.
* @param threshold2 [Number] Second threshold for the hysteresis procedure.
* @param aperture_size [Integer] Aperture size for the Sobel operator.
* @param l2gradient [Boolean] a flag, indicating whether a more accurate L_2 =\sqrt{ (dI/dx)^2 + (dI/dy)^2 } norm
* should be used to calculate the image gradient magnitude (l2gradient=true),
* or whether the default L_1 norm =|dI/dx|+|dI/dy| is enough (l2gradient=false).
* @opencv_func cv::Canny
*/
VALUE rb_canny(int argc, VALUE *argv, VALUE self) {
cv::Mat* rb_canny_internal(int argc, VALUE *argv, VALUE self, cv::Mat* destptr) {
VALUE threshold1, threshold2, aperture_size, l2gradient;
rb_scan_args(argc, argv, "22", &threshold1, &threshold2, &aperture_size, &l2gradient);
@ -87,10 +75,29 @@ namespace rubyopencv {
bool l2gradient_value = RTEST(l2gradient) ? true : false;
cv::Mat* selfptr = obj2mat(self);
cv::Canny(*selfptr, *destptr, NUM2DBL(threshold1), NUM2DBL(threshold2),
aperture_size_value, l2gradient_value);
return destptr;
}
/**
* Finds edges in an image using the [Canny86] algorithm.
*
* @overload canny(threshold1, threshold2, aperture_size = 3, l2gradient = false)
* @param threshold1 [Number] First threshold for the hysteresis procedure.
* @param threshold2 [Number] Second threshold for the hysteresis procedure.
* @param aperture_size [Integer] Aperture size for the Sobel operator.
* @param l2gradient [Boolean] a flag, indicating whether a more accurate L_2 = \sqrt{ (dI/dx)^2 + (dI/dy)^2 } norm
* should be used to calculate the image gradient magnitude (l2gradient=true),
* or whether the default L_1 norm = |dI/dx|+|dI/dy| is enough (l2gradient=false).
* @return [Mat] Output image
* @opencv_func cv::Canny
*/
VALUE rb_canny(int argc, VALUE *argv, VALUE self) {
cv::Mat* destptr = new cv::Mat();
try {
cv::Canny(*selfptr, *destptr, NUM2DBL(threshold1), NUM2DBL(threshold2),
aperture_size_value, l2gradient_value);
rb_canny_internal(argc, argv, self, destptr);
}
catch (cv::Exception& e) {
delete destptr;
@ -100,6 +107,22 @@ namespace rubyopencv {
return mat2obj(destptr, CLASS_OF(self));
}
/**
* @overload canny!(threshold1, threshold2, aperture_size = 3, l2gradient = false)
* @see #canny
*/
VALUE rb_canny_bang(int argc, VALUE *argv, VALUE self) {
cv::Mat* destptr = obj2mat(self);
try {
rb_canny_internal(argc, argv, self, destptr);
}
catch (cv::Exception& e) {
Error::raise(e);
}
return self;
}
/*
* Calculates the Laplacian of an image.
*