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

implemented and tested CvMat#hough_circles

This commit is contained in:
ser1zw 2011-03-20 23:13:38 +09:00
parent 8cd64f243e
commit 9b309eeef8
5 changed files with 53 additions and 1 deletions

View file

@ -371,6 +371,7 @@ void define_ruby_class()
rb_define_method(rb_klass, "hough_lines_standard", RUBY_METHOD_FUNC(rb_hough_lines_standard), 3);
rb_define_method(rb_klass, "hough_lines_probabilistic", RUBY_METHOD_FUNC(rb_hough_lines_probabilistic), 5);
rb_define_method(rb_klass, "hough_lines_multi_scale", RUBY_METHOD_FUNC(rb_hough_lines_multi_scale), 5);
rb_define_method(rb_klass, "hough_circles", RUBY_METHOD_FUNC(rb_hough_circles), -1);
rb_define_method(rb_klass, "hough_circles_gradient", RUBY_METHOD_FUNC(rb_hough_circles_gradient), -1);
//rb_define_method(rb_klass, "dist_transform", RUBY_METHOD_FUNC(rb_dist_transform), -1);
@ -4480,6 +4481,29 @@ rb_hough_lines_multi_scale(VALUE self, VALUE rho, VALUE theta, VALUE threshold,
return cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvLine::rb_class(), storage);
}
/*
* call-seq:
* hough_circles(<i>method, dp, min_dist, param1, param2, min_radius = 0, max_radius = max(width,height)</i>) -> cvseq(include CvCircle32f)
*
* Finds circles in grayscale image using Hough transform.
*/
VALUE
rb_hough_circles(int argc, VALUE *argv, VALUE self)
{
SUPPORT_8UC1_ONLY(self);
const int INVALID_TYPE = -1;
VALUE method, dp, min_dist, param1, param2, min_radius, max_radius, storage;
rb_scan_args(argc, argv, "52", &method, &dp, &min_dist, &param1, &param2,
&min_radius, &max_radius);
storage = cCvMemStorage::new_object();
int method_flag = CVMETHOD("HOUGH_TRANSFORM_METHOD", method, INVALID_TYPE);
CvSeq *seq = cvHoughCircles(CVARR(self), CVMEMSTORAGE(storage),
method_flag, NUM2DBL(dp), NUM2DBL(min_dist),
NUM2DBL(param1), NUM2DBL(param2),
IF_INT(min_radius, 0), IF_INT(max_radius, 0));
return cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvCircle32f::rb_class(), storage);
}
/*
* call-seq:
* hough_circles_gradient(<i>dp, min_dist, threshold_canny, threshold_accumulate, min_radius = 0, max_radius = max(width,height)</i>) -> cvseq(include CvCircle32f)

View file

@ -232,6 +232,7 @@ VALUE rb_hough_lines(int argc, VALUE *argv, VALUE self);
VALUE rb_hough_lines_standard(VALUE self, VALUE rho, VALUE theta, VALUE threshold);
VALUE rb_hough_lines_probabilistic(VALUE self, VALUE rho, VALUE theta, VALUE threshold, VALUE p1, VALUE p2);
VALUE rb_hough_lines_multi_scale(VALUE self, VALUE rho, VALUE theta, VALUE threshold, VALUE p1, VALUE p2);
VALUE rb_hough_circles(int argc, VALUE *argv, VALUE self);
VALUE rb_hough_circles_gradient(int argc, VALUE *argv, VALUE self);
VALUE rb_dist_transform(int argc, VALUE *argv, VALUE self);
VALUE rb_inpaint_ns(VALUE self, VALUE mask, VALUE radius);

View file

@ -238,7 +238,8 @@ define_ruby_module()
rb_define_const(rb_module, "CV_HOUGH_STANDARD", INT2FIX(CV_HOUGH_STANDARD));
rb_define_const(rb_module, "CV_HOUGH_PROBABILISTIC", INT2FIX(CV_HOUGH_PROBABILISTIC));
rb_define_const(rb_module, "CV_HOUGH_MULTI_SCALE", INT2FIX(CV_HOUGH_MULTI_SCALE));
rb_define_const(rb_module, "CV_HOUGH_GRADIENT", INT2FIX(CV_HOUGH_GRADIENT));
VALUE inversion_method = rb_hash_new();
/* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
@ -367,6 +368,7 @@ define_ruby_module()
RESIST_CVMETHOD(hough_transform_method, "standard", CV_HOUGH_STANDARD);
RESIST_CVMETHOD(hough_transform_method, "probabilistic", CV_HOUGH_PROBABILISTIC);
RESIST_CVMETHOD(hough_transform_method, "multi_scale", CV_HOUGH_MULTI_SCALE);
RESIST_CVMETHOD(hough_transform_method, "gradient", CV_HOUGH_GRADIENT);
/* color convert methods */
rb_define_module_function(rb_module, "BGR2BGRA", RUBY_METHOD_FUNC(rb_BGR2BGRA), 1);

View file

@ -1371,6 +1371,29 @@ class TestCvMat_imageprocessing < OpenCVTestCase
# snap mat0
end
def test_hough_circles
mat0 = CvMat.load(FILENAME_LINES, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
# make a binary image
mat = CvMat.new(mat0.rows, mat0.cols, :cv8u, 1)
(mat0.rows * mat0.cols).times { |i|
mat[i] = (mat0[i][0] <= 100) ? CvScalar.new(0) : CvScalar.new(255);
}
[mat.hough_circles(CV_HOUGH_GRADIENT, 1.5, 40, 100, 50, 10, 50),
mat.hough_circles(:gradient, 1.5, 40, 100, 50, 10, 50),
mat.hough_circles(CV_HOUGH_GRADIENT, 1.5, 40, 100, 50),
mat.hough_circles(:gradient, 1.5, 40, 100, 50)].each { |seq|
assert_equal(2, seq.size)
}
# Uncomment the following lines to show the result
# seq = mat.hough_circles(:gradient, 1.5, 40, 100, 50, 10, 50)
# seq.each { |circle|
# mat0.circle!(circle.center, circle.radius, :color => CvColor::Red, :thickness => 2)
# }
# snap mat0
end
def test_hough_circles_gradient
mat0 = CvMat.load(FILENAME_LINES, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
# make a binary image

View file

@ -75,6 +75,7 @@ class TestOpenCV < OpenCVTestCase
assert_equal(0, CV_HOUGH_STANDARD)
assert_equal(1, CV_HOUGH_PROBABILISTIC)
assert_equal(2, CV_HOUGH_MULTI_SCALE)
assert_equal(3, CV_HOUGH_GRADIENT)
end
def test_symbols
@ -174,6 +175,7 @@ class TestOpenCV < OpenCVTestCase
assert_equal(0, HOUGH_TRANSFORM_METHOD[:standard])
assert_equal(1, HOUGH_TRANSFORM_METHOD[:probabilistic])
assert_equal(2, HOUGH_TRANSFORM_METHOD[:multi_scale])
assert_equal(3, HOUGH_TRANSFORM_METHOD[:gradient])
end
def test_cvt_color_funcs