Class: OpenCV::CvTermCriteria

Inherits:
Object
  • Object
show all
Defined in:
ext/opencv/cvtermcriteria.cpp,
ext/opencv/cvtermcriteria.cpp

Overview

CvTermCriteria has parameter “max” and “eps”. “max” is the maximum repetition frequency. “eps” is a minimum difference value during current and previous state (It is different to which state “eps” refer depending on the method).

Because the name of CvTermCriteria seems to be very long, it has alias named CvTerm.

Instance Method Summary collapse

Constructor Details

#new([max = 0][,eps = 0.0]) ⇒ Object #new(int) ⇒ Object #new(float) ⇒ Object

Create new term criteria.

Overloads:

  • #new([max = 0][,eps = 0.0]) ⇒ Object

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/opencv/cvtermcriteria.cpp', line 47

VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE max, eps;
  rb_scan_args(argc, argv, "02", &max, &eps);
  int type = 0;
  if (!NIL_P(max))
    type |= CV_TERMCRIT_ITER;
  if (!NIL_P(eps))
    type |= CV_TERMCRIT_EPS;
  try {
    *CVTERMCRITERIA(self) = cvTermCriteria(type, IF_INT(max, 0), IF_DBL(eps, 0.0));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return self;
}

Instance Method Details

#epsFloat? Also known as: epsilon

Return the minimum difference value during current and previous state.

Returns:

  • (Float, nil)

123
124
125
126
127
128
129
130
131
# File 'ext/opencv/cvtermcriteria.cpp', line 123

VALUE
rb_eps(VALUE self)
{
  CvTermCriteria *ptr = CVTERMCRITERIA(self);
  if (ptr->type & CV_TERMCRIT_EPS)
    return rb_float_new(ptr->epsilon);
  else
    return Qnil;
}

#eps=(eps_value) ⇒ Object Also known as: epsilon=

Set the minimum difference value during current and previous state. If val is 0.0 (or negative value), the minimum difference value during current and previous state is disregarded.


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'ext/opencv/cvtermcriteria.cpp', line 141

VALUE
rb_set_eps(VALUE self, VALUE eps_value)
{
  CvTermCriteria *ptr = CVTERMCRITERIA(self);
  double eps = NUM2DBL(eps_value);
  if (eps > 0) {
    ptr->type = ptr->type | CV_TERMCRIT_EPS;
    ptr->epsilon = eps;
  }
  else {
    ptr->type = ptr->type ^ CV_TERMCRIT_EPS;
    ptr->epsilon = 0;
  }
  return self;
}

#maxInteger?

Return the maximum repetition frequency.

Returns:

  • (Integer, nil)

84
85
86
87
88
89
90
91
92
# File 'ext/opencv/cvtermcriteria.cpp', line 84

VALUE
rb_max(VALUE self)
{
  CvTermCriteria *ptr = CVTERMCRITERIA(self);
  if (ptr->type & CV_TERMCRIT_ITER)
    return INT2NUM(ptr->max_iter);
  else
    return Qnil;
}

#max=(max_value) ⇒ Object

Set the maximum repetition frequency. If val is 0 (or negative value), repetition frequency is disregarded.


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'ext/opencv/cvtermcriteria.cpp', line 101

VALUE
rb_set_max(VALUE self, VALUE max_value)
{
  CvTermCriteria *ptr = CVTERMCRITERIA(self);
  int max = NUM2INT(max_value);
  if (max > 0) {
    ptr->type |= CV_TERMCRIT_ITER;
    ptr->max_iter = max;
  }
  else {
    ptr->type ^= CV_TERMCRIT_ITER;
    ptr->max_iter = 0;
  }
  return self;
}

#typeInteger

Return a combination of CV_TERMCRIT_ITER and CV_TERMCRIT_EPS

Returns:

  • (Integer)

72
73
74
75
76
# File 'ext/opencv/cvtermcriteria.cpp', line 72

VALUE
rb_type(VALUE self)
{
  return INT2NUM(CVTERMCRITERIA(self)->type);
}