Class: OpenCV::IplConvKernel

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

Overview

Structuring element can be used in the morphological operations.

CvMat#erode, CvMat#dilate, CvMat#morphology_open, CvMat#morphology_close, CvMat#morphology_gradient, CvMat#morphology_tophat, CvMat#morphology_blackhat

Create by IplConvKernel.new or CvMat#to_IplConvKernel

Instance Method Summary collapse

Constructor Details

#new(cols, rows, anchor_x, anchor_y, shape[,values = nil]) ⇒ Object

Creates structuring element.

cols
  Number of columns in the structuring element.
rows
  Number of rows in the structuring element.
anchor_x
  Relative horizontal offset of the anchor point.
anchor_y
  Relative vertical offset of the anchor point.
shape
  Shape of the structuring element; may have the following values:
   :rect
   :cross
   :ellipse
   :custom


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'ext/opencv/iplconvkernel.cpp', line 59

VALUE
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);
  int shape_type;
  int _cols = NUM2INT(cols);
  int _rows = NUM2INT(rows);
  int num_values;
  int *_values = NULL;
  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.");
    num_values = RARRAY_LEN(values);
    _values = RB_ALLOC_N(int, num_values);
    VALUE *values_ptr = RARRAY_PTR(values);
    for (int i = 0; i < num_values; ++i)
      _values[i] = NUM2INT(values_ptr[i]);
  }
  try {
    DATA_PTR(self) = rb_cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),
						     shape_type, _values);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return self;
}

Instance Method Details

#anchorObject

Return anchor of the structuring element.



136
137
138
139
140
141
# File 'ext/opencv/iplconvkernel.cpp', line 136

VALUE
rb_anchor(VALUE self)
{
  IplConvKernel *kernel = IPLCONVKERNEL(self);
  return cCvPoint::new_object(cvPoint(kernel->anchorX, kernel->anchorY));
}

#anchor_xInteger

Return relative horizontal offset of the anchor point.

Returns:

  • (Integer)


149
150
151
152
153
# File 'ext/opencv/iplconvkernel.cpp', line 149

VALUE
rb_anchor_x(VALUE self)
{
  return INT2NUM(IPLCONVKERNEL(self)->anchorX);
}

#anchor_yInteger

Return relative vertical offset of the anchor point.

Returns:

  • (Integer)


161
162
163
164
165
# File 'ext/opencv/iplconvkernel.cpp', line 161

VALUE
rb_anchor_y(VALUE self)
{
  return INT2NUM(IPLCONVKERNEL(self)->anchorY);
}

#colsInteger Also known as: columns

Return number of columns in the structuring element.

Returns:

  • (Integer)


112
113
114
115
116
# File 'ext/opencv/iplconvkernel.cpp', line 112

VALUE
rb_cols(VALUE self)
{
  return INT2NUM(IPLCONVKERNEL(self)->nCols);
}

#rowsInteger

Return number of rows in the structuring element.

Returns:

  • (Integer)


124
125
126
127
128
# File 'ext/opencv/iplconvkernel.cpp', line 124

VALUE
rb_rows(VALUE self)
{
  return INT2NUM(IPLCONVKERNEL(self)->nRows);
}

#sizeObject

Return the structuring element’s size.



99
100
101
102
103
104
# File 'ext/opencv/iplconvkernel.cpp', line 99

VALUE
rb_size(VALUE self)
{
  IplConvKernel *kernel = IPLCONVKERNEL(self);
  return cCvSize::new_object(cvSize(kernel->nCols, kernel->nRows));
}