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

tested CvCircle32f and CvMat#hough_circle_gradient

This commit is contained in:
ser1zw 2011-03-20 22:53:56 +09:00
parent 3c165b516f
commit 8cd64f243e
5 changed files with 91 additions and 5 deletions

View file

@ -42,8 +42,7 @@ define_ruby_class()
rb_define_alloc_func(rb_klass, rb_allocate);
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
//rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
rb_define_alias(rb_klass, "to_a", "to_ary");
}
@ -73,6 +72,32 @@ rb_radius(VALUE self)
return rb_float_new(CVCIRCLE32F(self)->radius);
}
/*
* call-seq:
* [<i>index</i>]
*
* Return value of <i>index</i> dimension.
*/
VALUE
rb_aref(VALUE self, VALUE index)
{
switch (NUM2INT(index)) {
case 0:
return DBL2NUM(CVCIRCLE32F(self)->center.x);
break;
case 1:
return DBL2NUM(CVCIRCLE32F(self)->center.y);
break;
case 2:
return DBL2NUM(CVCIRCLE32F(self)->radius);
break;
default:
rb_raise(rb_eIndexError, "index should be 0...3");
break;
}
return Qnil;
}
VALUE
rb_to_ary(VALUE self)
{

View file

@ -32,8 +32,7 @@ VALUE rb_allocate(VALUE klass);
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
VALUE rb_center(VALUE self);
VALUE rb_radius(VALUE self);
VALUE rb_to_s(VALUE self);
VALUE rb_aref(VALUE self, VALUE index);
VALUE rb_to_ary(VALUE self);
VALUE new_object(CvCircle32f circle32f);

View file

@ -4491,7 +4491,7 @@ rb_hough_circles_gradient(int argc, VALUE *argv, VALUE self)
{
SUPPORT_8UC1_ONLY(self);
VALUE dp, min_dist, threshold_canny, threshold_accumulate, min_radius, max_radius, storage;
rb_scan_args(argc, argv, "24", &dp, &min_dist, &threshold_canny, &threshold_accumulate, &min_radius, &max_radius);
rb_scan_args(argc, argv, "42", &dp, &min_dist, &threshold_canny, &threshold_accumulate, &min_radius, &max_radius);
storage = cCvMemStorage::new_object();
CvSeq *seq = cvHoughCircles(CVARR(self), CVMEMSTORAGE(storage),
CV_HOUGH_GRADIENT, NUM2DBL(dp), NUM2DBL(min_dist),

41
test/test_cvcircle32f.rb Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env ruby
# -*- mode: ruby; coding: utf-8-unix -*-
require 'test/unit'
require 'opencv'
require File.expand_path(File.dirname(__FILE__)) + '/helper'
include OpenCV
# Tests for OpenCV::CvCircle32f
class TestCvCircle32f < OpenCVTestCase
def setup
@circle = CvCircle32f.new
end
def test_initialize
assert_equal(CvCircle32f, @circle.class)
end
def test_center
assert_equal(CvPoint2D32f, @circle.center.class)
end
def test_radius
assert_equal(Float, @circle.radius.class)
end
def test_aref
assert_equal(Float, @circle[0].class)
assert_equal(Float, @circle[1].class)
assert_equal(Float, @circle[2].class)
assert_raise(IndexError) {
@circle[3]
}
end
def test_to_ary
assert_equal(Array, @circle.to_ary.class)
assert_equal(2, @circle.to_ary.size)
end
end

View file

@ -1370,5 +1370,26 @@ class TestCvMat_imageprocessing < OpenCVTestCase
# }
# 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
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_gradient(1.5, 40, 100, 50, 10, 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
end