1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

added structuring element shape constants for IplConvKernel

This commit is contained in:
ser1zw 2011-01-29 18:04:32 +09:00
parent d82a1506cc
commit a9717d18a8
5 changed files with 48 additions and 24 deletions

View file

@ -85,32 +85,26 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE shape, rows, cols, anchor_x, anchor_y, values;
rb_scan_args(argc, argv, "51", &cols, &rows, &anchor_x, &anchor_y, &shape, &values);
Check_Type(shape, T_SYMBOL);
const char *shape_name = rb_id2name(SYM2ID(shape));
int shape_type = 0;
int shape_type;
int _cols = NUM2INT(cols);
int _rows = NUM2INT(rows);
int num_values;
int *_values;
if (!strcmp(shape_name, "rect"))
shape_type = CV_SHAPE_RECT;
else if (!strcmp(shape_name, "cross"))
shape_type = CV_SHAPE_CROSS;
else if (!strcmp(shape_name, "ellipse"))
shape_type = CV_SHAPE_ELLIPSE;
else if (!strcmp(shape_name, "custom")) {
const int INVALID_SHAPE = -1;
shape_type = CVMETHOD("STRUCTURING_ELEMENT_SHAPE", shape, INVALID_SHAPE);
if (shape_type == INVALID_SHAPE)
rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse or :custom.");
if (shape_type == CV_SHAPE_CUSTOM) {
if (NIL_P(values))
rb_raise(rb_eArgError, "argument 6 (values) should not be nil when the shape is :custom.");
shape_type = CV_SHAPE_CUSTOM;
num_values = RARRAY_LEN(values);
_values = ALLOCA_N(int, num_values);
VALUE *values_ptr = RARRAY_PTR(values);
for (int i = 0; i < num_values; i++)
_values[i] = NUM2INT(values_ptr[i]);
}
else
rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse or :custom.");
DATA_PTR(self) = cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y), shape_type, _values);
DATA_PTR(self) = cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),shape_type, _values);
return self;
}