Class: OpenCV::CvBox2D

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

Overview

Stores coordinates of a rotated rectangle.

Instance Method Summary collapse

Constructor Details

#new(center = nil, size = nil, angle = nil) ⇒ CvBox2D

Create a box

Parameters:

  • center (CvPoint2D32f, nil) (defaults to: nil)

    Center of the box

  • size (CvSize, nil) (defaults to: nil)

    Size of the box

  • angle (Number, nil) (defaults to: nil)

    Angle between the horizontal axis and the first side in degrees


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;
}

#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;
}

#pointsArray<CvPoint2D32f>

Find box vertices

Returns:


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;
}