mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
tested Curve
This commit is contained in:
parent
5266eb051a
commit
9567a93fba
2 changed files with 46 additions and 2 deletions
|
@ -36,7 +36,7 @@ define_ruby_module()
|
|||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
module = rb_define_module_under(opencv, "Curve");
|
||||
rb_define_method(module, "close?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
||||
rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
||||
rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
|
||||
rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
|
||||
rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
|
||||
|
@ -95,7 +95,9 @@ rb_arc_length(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
VALUE slice, is_closed;
|
||||
rb_scan_args(argc, argv, "02", &slice, &is_closed);
|
||||
return rb_float_new(cvArcLength(CVARR(self), NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice), TRUE_OR_FALSE(is_closed, -1)));
|
||||
return rb_float_new(cvArcLength(CVARR(self),
|
||||
NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
|
||||
TRUE_OR_FALSE(is_closed, -1)));
|
||||
}
|
||||
|
||||
__NAMESPACE_END_CURVE
|
||||
|
|
42
test/test_curve.rb
Executable file
42
test/test_curve.rb
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/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::Curve
|
||||
class TestCurve < OpenCVTestCase
|
||||
def setup
|
||||
@contour1 = CvContour.new
|
||||
|
||||
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
||||
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
||||
}
|
||||
@contour2 = mat0.find_contours
|
||||
end
|
||||
|
||||
def test_closed
|
||||
assert_false(@contour1.closed?)
|
||||
assert(@contour2.closed?)
|
||||
end
|
||||
|
||||
def test_convex
|
||||
assert_false(@contour1.convex?)
|
||||
end
|
||||
|
||||
def test_hole
|
||||
assert_false(@contour1.hole?)
|
||||
end
|
||||
|
||||
def test_simple
|
||||
assert(@contour1.simple?)
|
||||
end
|
||||
|
||||
def test_arc_length
|
||||
assert_in_delta(211.480, @contour2.arc_length, 0.001)
|
||||
assert_in_delta(18.071, @contour2.arc_length(0..10, true), 0.001)
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue