mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
modified and tested CvTermCriteria
This commit is contained in:
parent
615fd63e0c
commit
493644a55a
5 changed files with 84 additions and 18 deletions
|
@ -46,14 +46,13 @@ define_ruby_class()
|
||||||
rb_define_const(opencv, "CvTerm", rb_klass);
|
rb_define_const(opencv, "CvTerm", rb_klass);
|
||||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||||
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||||
|
rb_define_method(rb_klass, "type", RUBY_METHOD_FUNC(rb_type), 0);
|
||||||
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
|
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
|
||||||
rb_define_method(rb_klass, "max=", RUBY_METHOD_FUNC(rb_set_max), 1);
|
rb_define_method(rb_klass, "max=", RUBY_METHOD_FUNC(rb_set_max), 1);
|
||||||
rb_define_method(rb_klass, "eps", RUBY_METHOD_FUNC(rb_eps), 0);
|
rb_define_method(rb_klass, "eps", RUBY_METHOD_FUNC(rb_eps), 0);
|
||||||
rb_define_method(rb_klass, "eps=", RUBY_METHOD_FUNC(rb_set_eps), 1);
|
rb_define_method(rb_klass, "eps=", RUBY_METHOD_FUNC(rb_set_eps), 1);
|
||||||
rb_define_alias(rb_klass, "epsilon", "eps");
|
rb_define_alias(rb_klass, "epsilon", "eps");
|
||||||
rb_define_alias(rb_klass, "epsilon=", "eps=");
|
rb_define_alias(rb_klass, "epsilon=", "eps=");
|
||||||
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
|
||||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
@ -77,12 +76,26 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
VALUE max, eps;
|
VALUE max, eps;
|
||||||
rb_scan_args(argc, argv, "02", &max, &eps);
|
rb_scan_args(argc, argv, "02", &max, &eps);
|
||||||
int type = 0;
|
int type = 0;
|
||||||
if (!NIL_P(max)) {type |= CV_TERMCRIT_ITER;}
|
if (!NIL_P(max))
|
||||||
if (!NIL_P(eps)) {type |= CV_TERMCRIT_EPS;}
|
type |= CV_TERMCRIT_ITER;
|
||||||
|
if (!NIL_P(eps))
|
||||||
|
type |= CV_TERMCRIT_EPS;
|
||||||
*CVTERMCRITERIA(self) = cvTermCriteria(type, IF_INT(max, 0), IF_DBL(eps, 0.0));
|
*CVTERMCRITERIA(self) = cvTermCriteria(type, IF_INT(max, 0), IF_DBL(eps, 0.0));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* type -> int
|
||||||
|
*
|
||||||
|
* Return a combination of CV_TERMCRIT_ITER and CV_TERMCRIT_EPS
|
||||||
|
*/
|
||||||
|
VALUE
|
||||||
|
rb_type(VALUE self)
|
||||||
|
{
|
||||||
|
return INT2NUM(CVTERMCRITERIA(self)->type);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* max -> int or nil
|
* max -> int or nil
|
||||||
|
@ -160,18 +173,6 @@ rb_set_eps(VALUE self, VALUE eps_value)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
|
||||||
rb_to_ary(VALUE self)
|
|
||||||
{
|
|
||||||
CvTermCriteria *ptr = CVTERMCRITERIA(self);
|
|
||||||
VALUE ary = rb_ary_new();
|
|
||||||
if (ptr->type & CV_TERMCRIT_ITER)
|
|
||||||
rb_ary_push(ary, INT2FIX(ptr->max_iter));
|
|
||||||
if (ptr->type & CV_TERMCRIT_EPS)
|
|
||||||
rb_ary_push(ary, rb_float_new(ptr->epsilon));
|
|
||||||
return ary;
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
new_object(CvTermCriteria criteria)
|
new_object(CvTermCriteria criteria)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,11 +25,11 @@ void define_ruby_class();
|
||||||
VALUE rb_allocate(VALUE klass);
|
VALUE rb_allocate(VALUE klass);
|
||||||
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
||||||
|
|
||||||
|
VALUE rb_type(VALUE self);
|
||||||
VALUE rb_max(VALUE self);
|
VALUE rb_max(VALUE self);
|
||||||
VALUE rb_set_max(VALUE self, VALUE max_value);
|
VALUE rb_set_max(VALUE self, VALUE max_value);
|
||||||
VALUE rb_eps(VALUE self);
|
VALUE rb_eps(VALUE self);
|
||||||
VALUE rb_set_eps(VALUE self, VALUE eps_value);
|
VALUE rb_set_eps(VALUE self, VALUE eps_value);
|
||||||
VALUE rb_to_ary(VALUE self);
|
|
||||||
|
|
||||||
VALUE new_object(CvTermCriteria criteria);
|
VALUE new_object(CvTermCriteria criteria);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ VALUE_TO_CVTERMCRITERIA(VALUE object)
|
||||||
NUM2DBL(rb_ary_entry(object, 1)));
|
NUM2DBL(rb_ary_entry(object, 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_raise(rb_eTypeError, "");
|
rb_raise(rb_eTypeError, "Invalid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
__NAMESPACE_END_OPENCV
|
__NAMESPACE_END_OPENCV
|
||||||
|
|
|
@ -229,6 +229,11 @@ define_ruby_module()
|
||||||
rb_define_const(rb_module, "CV_CHAIN_APPROX_TC89_KCOS", INT2FIX(CV_CHAIN_APPROX_TC89_KCOS));
|
rb_define_const(rb_module, "CV_CHAIN_APPROX_TC89_KCOS", INT2FIX(CV_CHAIN_APPROX_TC89_KCOS));
|
||||||
rb_define_const(rb_module, "CV_LINK_RUNS", INT2FIX(CV_LINK_RUNS));
|
rb_define_const(rb_module, "CV_LINK_RUNS", INT2FIX(CV_LINK_RUNS));
|
||||||
|
|
||||||
|
/* Termination criteria for iterative algorithms */
|
||||||
|
rb_define_const(rb_module, "CV_TERMCRIT_ITER", INT2FIX(CV_TERMCRIT_ITER));
|
||||||
|
rb_define_const(rb_module, "CV_TERMCRIT_NUMBER", INT2FIX(CV_TERMCRIT_NUMBER));
|
||||||
|
rb_define_const(rb_module, "CV_TERMCRIT_EPS", INT2FIX(CV_TERMCRIT_EPS));
|
||||||
|
|
||||||
VALUE inversion_method = rb_hash_new();
|
VALUE inversion_method = rb_hash_new();
|
||||||
/* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
|
/* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
|
||||||
rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
|
rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
|
||||||
|
|
56
test/test_cvtermcriteria.rb
Executable file
56
test/test_cvtermcriteria.rb
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/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::CvTermCriteria
|
||||||
|
class TestCvTermCriteria < OpenCVTestCase
|
||||||
|
def setup
|
||||||
|
@criteria1 = CvTermCriteria.new
|
||||||
|
@criteria2 = CvTermCriteria.new(100)
|
||||||
|
@criteria3 = CvTermCriteria.new(nil, 0.01)
|
||||||
|
@criteria4 = CvTermCriteria.new(100, 0.01)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
assert_not_nil(@criteria1)
|
||||||
|
assert_equal(CvTermCriteria, @criteria1.class)
|
||||||
|
assert_not_nil(@criteria2)
|
||||||
|
assert_equal(CvTermCriteria, @criteria2.class)
|
||||||
|
assert_not_nil(@criteria3)
|
||||||
|
assert_equal(CvTermCriteria, @criteria3.class)
|
||||||
|
assert_not_nil(@criteria4)
|
||||||
|
assert_equal(CvTermCriteria, @criteria4.class)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_type
|
||||||
|
assert_equal(0, @criteria1.type)
|
||||||
|
assert_equal(CV_TERMCRIT_ITER, @criteria2.type)
|
||||||
|
assert_equal(CV_TERMCRIT_EPS, @criteria3.type)
|
||||||
|
assert_equal(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, @criteria4.type)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_max
|
||||||
|
assert_nil(@criteria1.max)
|
||||||
|
assert_equal(100, @criteria2.max)
|
||||||
|
assert_nil(@criteria3.max)
|
||||||
|
assert_equal(100, @criteria4.max)
|
||||||
|
|
||||||
|
@criteria1.max = 999
|
||||||
|
assert_equal(999, @criteria1.max)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_eps
|
||||||
|
assert_nil(@criteria1.eps)
|
||||||
|
assert_nil(@criteria2.eps)
|
||||||
|
assert_in_delta(0.01, @criteria3.eps, 0.001)
|
||||||
|
assert_in_delta(0.01, @criteria4.eps, 0.001)
|
||||||
|
|
||||||
|
@criteria1.eps = 3.14
|
||||||
|
assert_in_delta(3.14, @criteria1.eps, 0.001)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -66,6 +66,10 @@ class TestOpenCV < OpenCVTestCase
|
||||||
assert_equal(4, CV_CHAIN_APPROX_TC89_KCOS)
|
assert_equal(4, CV_CHAIN_APPROX_TC89_KCOS)
|
||||||
assert_equal(5, CV_LINK_RUNS)
|
assert_equal(5, CV_LINK_RUNS)
|
||||||
|
|
||||||
|
# Termination criteria for iterative algorithms
|
||||||
|
assert_equal(1, CV_TERMCRIT_ITER)
|
||||||
|
assert_equal(1, CV_TERMCRIT_NUMBER)
|
||||||
|
assert_equal(2, CV_TERMCRIT_EPS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols
|
def test_symbols
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue