Class: OpenCV::CvBox2D

Inherits:
Object
  • Object
show all
Includes:
Curve
Defined in:
ext/opencv/cvbox2d.cpp,
ext/opencv/cvbox2d.cpp

Overview

Stores coordinates of a rotated rectangle.

Constant Summary collapse

APPROX_CHAIN_OPTION =
approx_chain_option

Instance Method Summary collapse

Methods included from Curve

#arc_length, #closed?, #convex?, #hole?, #simple?

Constructor Details

#new(storage = nil) ⇒ CvChain

Create a new chain code

Parameters:

  • storage (CvMemStorage, nil) (defaults to: nil)

    Sequence location (If storage is nil, allocates a new storage automatically)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/opencv/cvbox2d.cpp', line 42

VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE center, size, angle;
  CvBox2D* self_ptr = CVBOX2D(self);
  rb_scan_args(argc, argv, "03", &center, &size, &angle);
  
  if (!NIL_P(center)) {
    self_ptr->center = VALUE_TO_CVPOINT2D32F(center);
  }
  if (!NIL_P(size)) {
    self_ptr->size = VALUE_TO_CVSIZE2D32F(size);
    self_ptr->angle = NUM2DBL(angle);
  }
  
  return self;
}

Instance Method Details

#angleFloat

Returns angle of the box

Returns:

  • (Float)

    Angle of the box



113
114
115
116
117
# File 'ext/opencv/cvbox2d.cpp', line 113

VALUE
rb_angle(VALUE self)
{
  return rb_float_new(CVBOX2D(self)->angle);
}

#angle=CvBox2D

Set angle of the box

Parameters:

  • value (Number)

    Angle of the box

Returns:



125
126
127
128
129
130
# File 'ext/opencv/cvbox2d.cpp', line 125

VALUE
rb_set_angle(VALUE self, VALUE value)
{
  CVBOX2D(self)->angle = NUM2DBL(value);
  return self;
}

#approx_chain(options) ⇒ CvSeq<CvPoint> Also known as: approx

Approximates Freeman chains with a polygonal curve

Parameters:

  • options (Hash)

    Parameters

Options Hash (options):

  • :method (Symbol)

    Approximation method (see the description of CvMat#find_contours)

  • :minimal_perimeter (Number)

    Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure.

  • :recursive (Boolean)

    Recursion flag. If it is true, the function approximates all chains that can be obtained from chain by using the h_next or v_next links. Otherwise, the single input chain is approximated.

Returns:



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'ext/opencv/cvchain.cpp', line 163

VALUE
rb_approx_chains(int argc, VALUE *argv, VALUE self)
{
  VALUE approx_chain_option;
  rb_scan_args(argc, argv, "01", &approx_chain_option);

  approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
  VALUE storage = cCvMemStorage::new_object();
  CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),			      
			      APPROX_CHAIN_METHOD(approx_chain_option),
			      APPROX_CHAIN_PARAMETER(approx_chain_option),
			      APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
			      APPROX_CHAIN_RECURSIVE(approx_chain_option));

  if (seq && seq->total > 0) {
    return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
  }
  return Qnil;
}

#centerCvPoint2D32f

Returns center point of the box

Returns:



65
66
67
68
69
# File 'ext/opencv/cvbox2d.cpp', line 65

VALUE
rb_center(VALUE self)
{
  return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
}

#center=CvBox2D

Set center point of the box

Parameters:

Returns:



77
78
79
80
81
82
# File 'ext/opencv/cvbox2d.cpp', line 77

VALUE
rb_set_center(VALUE self, VALUE value)
{
  CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
  return self;
}

#codesArray<Fixnum>

Returns the chain codes

Returns:

  • (Array<Fixnum>)

    Chain codes



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'ext/opencv/cvchain.cpp', line 102

VALUE
rb_codes(VALUE self)
{
  CvChain *chain = CVCHAIN(self);
  CvChainPtReader reader;
  int total = chain->total;
  VALUE ary = rb_ary_new2(total);
  try {
    cvStartReadChainPoints(chain, &reader);
    for (int i = 0; i < total; ++i) {
      CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
      rb_ary_store(ary, i, INT2FIX(reader.code));
    }
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return ary;
}

#originCvPoint

Returns Freeman chain code origin

Returns:

  • (CvPoint)

    Origin of the chain code



76
77
78
79
80
# File 'ext/opencv/cvchain.cpp', line 76

VALUE
rb_origin(VALUE self)
{
  return cCvPoint::new_object(CVCHAIN(self)->origin);
}

#origin=CvChain

Set Freeman chain code origin

Parameters:

  • value (CvPoint)

    Origin of the chain code

Returns:



88
89
90
91
92
93
# File 'ext/opencv/cvchain.cpp', line 88

VALUE
rb_set_origin(VALUE self, VALUE origin)
{
  CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);  
  return self;
}

#pointsArray<CvPoint>

Returns the points of the chain codes

Returns:

  • (Array<CvPoint>)

    Points of the chain codes



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

VALUE
rb_points(VALUE self)
{
  const int n = 4;
  CvPoint2D32f p[n];
  try {
    cvBoxPoints(*CVBOX2D(self), p);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  VALUE points = rb_ary_new2(n);
  for (int i = 0; i < n; ++i) {
    rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
  }
  return points;
}

#sizeCvSize2D32f

Returns size of the box

Returns:



89
90
91
92
93
# File 'ext/opencv/cvbox2d.cpp', line 89

VALUE
rb_size(VALUE self)
{
  return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
}

#size=CvBox2D

Set size of the box

Parameters:

Returns:



101
102
103
104
105
106
# File 'ext/opencv/cvbox2d.cpp', line 101

VALUE
rb_set_size(VALUE self, VALUE value)
{
  CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(value);
  return self;
}