Class: OpenCV::CvRect
- Inherits:
-
Object
- Object
- OpenCV::CvRect
- Defined in:
- ext/opencv/cvrect.cpp,
ext/opencv/cvrect.cpp,
ext/opencv/cvavgcomp.cpp
Overview
This class have coordinate of top-left point(x, y) and size, width and height.
C stracture is here, very simple.
typdef struct CvRect {
int x;
int y;
int width;
int height;
}
Direct Known Subclasses
Class Method Summary collapse
-
.combatible?(obj) ⇒ Boolean
Return compatibility to CvRect.
-
.max_rect(rect1, rect2) ⇒ Object
Finds bounding rectangle for given rectangles.
Instance Method Summary collapse
-
#rb_check_inequality(val) ⇒ Object
Return true if CvRect does not have same values as we do.
-
#rb_check_equality(val) ⇒ Object
Return true if CvRect has same values as we do.
-
#bottom_center ⇒ Object
Return top-left point of rectangle.
-
#bottom_left ⇒ Object
Return bottom-left point of rectangle.
-
#bottom_right ⇒ Object
Return bottom-right point of rectangle.
-
#center ⇒ Object
Return center point of rectangle.
-
#center_left ⇒ Object
Return bottom-right point of rectangle.
-
#center_right ⇒ Object
Return bottom-right point of rectangle.
-
#rb_check_equality(val) ⇒ Boolean
Return true if CvRect has same values as we do.
- #hash ⇒ Object
-
#height ⇒ Object
Return size of y-axis.
-
#height=(val) ⇒ Object
Set y-axis size, return self.
-
#initialize(*args) ⇒ Object
constructor
Create new rectangle area.
-
#points ⇒ Object
Return 4 points (top-left, bottom-left, bottom-right, top-right).
-
#to_s ⇒ "<OpenCV::CvRect:(self.x]
Return x, y, width, and height by String.
-
#top_center ⇒ Object
Return top-left point of rectangle.
-
#top_left ⇒ Object
Return top-left point of rectangle.
-
#top_right ⇒ Object
Return top-right point of rectangle.
-
#width ⇒ Object
Return size of x-axis.
-
#width=(val) ⇒ Object
Set x-axis size, return self.
-
#x ⇒ Object
Return parameter on x-axis of top-left point.
-
#x=(val) ⇒ Object
Set x-axis parameter of top-left point, return self.
-
#y ⇒ Object
Return parameter on y-axis of top-left point.
-
#y=(val) ⇒ Object
Set y-axis parameter of top-left point, return self.
Constructor Details
#new ⇒ CvRect.new(0, 0, 0, 0) #new(obj) ⇒ CvRect.new(obj.x.to_i] #new(x, y, width, height) ⇒ Object
Create new rectangle area. (x, y) is top-left point, and width, height is size of area. It is dropped below the decimal point.
new() is same as new(0, 0, 0, 0)
new(obj) is same as new(obj.x.to_i, obj.y.to_i, obj.width.to_i, obj.height.to_i)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/opencv/cvrect.cpp', line 103
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
CvRect *self_ptr = CVRECT(self);
switch (argc) {
case 0:
break;
case 1: {
CvRect rect = VALUE_TO_CVRECT(argv[0]);
self_ptr->x = rect.x;
self_ptr->y = rect.y;
self_ptr->width = rect.width;
self_ptr->height = rect.height;
break;
}
case 4:
self_ptr->x = NUM2INT(argv[0]);
self_ptr->y = NUM2INT(argv[1]);
self_ptr->width = NUM2INT(argv[2]);
self_ptr->height = NUM2INT(argv[3]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
break;
}
return self;
}
|
Class Method Details
.combatible?(obj) ⇒ Boolean
62 63 64 65 66 67 68 69 |
# File 'ext/opencv/cvrect.cpp', line 62
VALUE
rb_compatible_q(VALUE klass, VALUE object)
{
return (rb_respond_to(object, rb_intern("x")) &&
rb_respond_to(object, rb_intern("y")) &&
rb_respond_to(object, rb_intern("width")) &&
rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
}
|
.max_rect(rect1, rect2) ⇒ Object
Finds bounding rectangle for given rectangles.
77 78 79 80 81 |
# File 'ext/opencv/cvrect.cpp', line 77
VALUE
rb_max_rect(VALUE klass, VALUE rect1, VALUE rect2)
{
return cCvRect::new_object(cvMaxRect(CVRECT(rect1), CVRECT(rect2)));
}
|
Instance Method Details
#rb_check_inequality(val) ⇒ Object
Return true if CvRect does not have same values as we do
151 152 153 154 155 156 157 |
# File 'ext/opencv/cvrect.cpp', line 151
VALUE
rb_check_inequality(VALUE self, VALUE compare_to) {
CvRect compare = VALUE_TO_CVRECT(compare_to);
CvRect* self_ptr = CVRECT(self);
return (self_ptr->x != compare.x || self_ptr->y != compare.y || self_ptr->width != compare.width || self_ptr->height != compare.height) ? Qtrue : Qfalse;
}
|
#rb_check_equality(val) ⇒ Object
Return true if CvRect has same values as we do
137 138 139 140 141 142 143 |
# File 'ext/opencv/cvrect.cpp', line 137
VALUE
rb_check_equality(VALUE self, VALUE compare_to) {
CvRect compare = VALUE_TO_CVRECT(compare_to);
CvRect* self_ptr = CVRECT(self);
return (self_ptr->x == compare.x && self_ptr->y == compare.y && self_ptr->width == compare.width && self_ptr->height == compare.height) ? Qtrue : Qfalse;
}
|
#bottom_center ⇒ Object
Return top-left point of rectangle.
306 307 308 309 310 311 |
# File 'ext/opencv/cvrect.cpp', line 306
VALUE
rb_top_left(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x, rect->y));
}
|
#bottom_left ⇒ Object
Return bottom-left point of rectangle.
326 327 328 329 330 331 332 |
# File 'ext/opencv/cvrect.cpp', line 326
VALUE
rb_bottom_left(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x,
rect->y + rect->height));
}
|
#bottom_right ⇒ Object
Return bottom-right point of rectangle.
337 338 339 340 341 342 343 |
# File 'ext/opencv/cvrect.cpp', line 337
VALUE
rb_bottom_right(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x + rect->width,
rect->y + rect->height));
}
|
#center ⇒ Object
Return center point of rectangle.
280 281 282 283 284 285 286 |
# File 'ext/opencv/cvrect.cpp', line 280
VALUE
rb_center(VALUE self)
{
CvRect *rect = CVRECT(self);
return cCvPoint2D32f::new_object(cvPoint2D32f((float)rect->x + (float)rect->width / 2.0,
(float)rect->y + (float)rect->height / 2.0));
}
|
#center_left ⇒ Object
Return bottom-right point of rectangle.
337 338 339 340 341 342 343 |
# File 'ext/opencv/cvrect.cpp', line 337
VALUE
rb_bottom_right(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x + rect->width,
rect->y + rect->height));
}
|
#center_right ⇒ Object
Return bottom-right point of rectangle.
337 338 339 340 341 342 343 |
# File 'ext/opencv/cvrect.cpp', line 337
VALUE
rb_bottom_right(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x + rect->width,
rect->y + rect->height));
}
|
#rb_check_equality(val) ⇒ Boolean
Return true if CvRect has same values as we do
137 138 139 140 141 142 143 |
# File 'ext/opencv/cvrect.cpp', line 137
VALUE
rb_check_equality(VALUE self, VALUE compare_to) {
CvRect compare = VALUE_TO_CVRECT(compare_to);
CvRect* self_ptr = CVRECT(self);
return (self_ptr->x == compare.x && self_ptr->y == compare.y && self_ptr->width == compare.width && self_ptr->height == compare.height) ? Qtrue : Qfalse;
}
|
#hash ⇒ Object
159 160 161 162 163 |
# File 'ext/opencv/cvrect.cpp', line 159 VALUE rb_hash(VALUE self) { CvRect* self_ptr = CVRECT(self); return INT2NUM(rb_memhash(self_ptr, sizeof(CvRect))); } |
#height ⇒ Object
Return size of y-axis.
257 258 259 260 261 |
# File 'ext/opencv/cvrect.cpp', line 257
VALUE
rb_height(VALUE self)
{
return INT2NUM(CVRECT(self)->height);
}
|
#height=(val) ⇒ Object
Set y-axis size, return self. It is dropped below the decimal point.
270 271 272 273 274 275 |
# File 'ext/opencv/cvrect.cpp', line 270
VALUE
rb_set_height(VALUE self, VALUE y)
{
CVRECT(self)->height = NUM2INT(y);
return self;
}
|
#points ⇒ Object
Return 4 points (top-left, bottom-left, bottom-right, top-right)
291 292 293 294 295 296 297 298 299 300 301 |
# File 'ext/opencv/cvrect.cpp', line 291
VALUE
rb_points(VALUE self)
{
CvRect *rect = CVRECT(self);
return rb_ary_new3(4,
cCvPoint::new_object(cvPoint(rect->x, rect->y)),
cCvPoint::new_object(cvPoint(rect->x, rect->y + rect->height)),
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y + rect->height)),
cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y))
);
}
|
#to_s ⇒ "<OpenCV::CvRect:(self.x]
Return x, y, width, and height by String.
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/opencv/cvrect.cpp', line 171
VALUE
rb_to_s(VALUE self)
{
const int i = 6;
VALUE str[i];
str[0] = rb_str_new2("<%s:(%d,%d,%dx%d)>");
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
str[2] = rb_x(self);
str[3] = rb_y(self);
str[4] = rb_width(self);
str[5] = rb_height(self);
return rb_f_sprintf(i, str);
}
|
#top_center ⇒ Object
Return top-left point of rectangle.
306 307 308 309 310 311 |
# File 'ext/opencv/cvrect.cpp', line 306
VALUE
rb_top_left(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x, rect->y));
}
|
#top_left ⇒ Object
Return top-left point of rectangle.
306 307 308 309 310 311 |
# File 'ext/opencv/cvrect.cpp', line 306
VALUE
rb_top_left(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x, rect->y));
}
|
#top_right ⇒ Object
Return top-right point of rectangle.
316 317 318 319 320 321 |
# File 'ext/opencv/cvrect.cpp', line 316
VALUE
rb_top_right(VALUE self)
{
CvRect* rect = CVRECT(self);
return cCvPoint::new_object(cvPoint(rect->x + rect->width, rect->y));
}
|
#width ⇒ Object
Return size of x-axis.
234 235 236 237 238 |
# File 'ext/opencv/cvrect.cpp', line 234
VALUE
rb_width(VALUE self)
{
return INT2NUM(CVRECT(self)->width);
}
|
#width=(val) ⇒ Object
Set x-axis size, return self. It is dropped below the decimal point.
247 248 249 250 251 252 |
# File 'ext/opencv/cvrect.cpp', line 247
VALUE
rb_set_width(VALUE self, VALUE x)
{
CVRECT(self)->width = NUM2INT(x);
return self;
}
|
#x ⇒ Object
Return parameter on x-axis of top-left point.
188 189 190 191 192 |
# File 'ext/opencv/cvrect.cpp', line 188
VALUE
rb_x(VALUE self)
{
return INT2NUM(CVRECT(self)->x);
}
|
#x=(val) ⇒ Object
Set x-axis parameter of top-left point, return self. It is dropped below the decimal point.
201 202 203 204 205 206 |
# File 'ext/opencv/cvrect.cpp', line 201
VALUE
rb_set_x(VALUE self, VALUE x)
{
CVRECT(self)->x = NUM2INT(x);
return self;
}
|
#y ⇒ Object
Return parameter on y-axis of top-left point.
211 212 213 214 215 |
# File 'ext/opencv/cvrect.cpp', line 211
VALUE
rb_y(VALUE self)
{
return INT2NUM(CVRECT(self)->y);
}
|
#y=(val) ⇒ Object
Set y-axis parameter of top-left point, return self. It is dropped below the decimal point.
224 225 226 227 228 229 |
# File 'ext/opencv/cvrect.cpp', line 224
VALUE
rb_set_y(VALUE self, VALUE y)
{
CVRECT(self)->y = NUM2INT(y);
return self;
}
|