mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
implemented rb_cvCreateStructuringElementEx and replaced cvCreateStructuringElementEx with rb_cvCreateStructuringElementEx to create IplConvKernel as much as possible
This commit is contained in:
parent
586f2161eb
commit
d9a7960949
4 changed files with 36 additions and 2 deletions
|
@ -594,7 +594,8 @@ rb_to_IplConvKernel(VALUE self, VALUE anchor)
|
||||||
{
|
{
|
||||||
CvMat *src = CVMAT(self);
|
CvMat *src = CVMAT(self);
|
||||||
CvPoint p = VALUE_TO_CVPOINT(anchor);
|
CvPoint p = VALUE_TO_CVPOINT(anchor);
|
||||||
IplConvKernel *kernel = cvCreateStructuringElementEx(src->cols, src->rows, p.x, p.y, CV_SHAPE_CUSTOM, src->data.i);
|
IplConvKernel *kernel = rb_cvCreateStructuringElementEx(src->cols, src->rows, p.x, p.y,
|
||||||
|
CV_SHAPE_CUSTOM, src->data.i);
|
||||||
return DEPEND_OBJECT(cIplConvKernel::rb_class(), kernel, self);
|
return DEPEND_OBJECT(cIplConvKernel::rb_class(), kernel, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,8 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
for (int i = 0; i < num_values; i++)
|
for (int i = 0; i < num_values; i++)
|
||||||
_values[i] = NUM2INT(values_ptr[i]);
|
_values[i] = NUM2INT(values_ptr[i]);
|
||||||
}
|
}
|
||||||
DATA_PTR(self) = cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),shape_type, _values);
|
DATA_PTR(self) = rb_cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),
|
||||||
|
shape_type, _values);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,37 @@ rb_cvCreateImage(CvSize size, int depth, int channels)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates a structuring element
|
||||||
|
* When memory allocation is failed, run GC and retry it
|
||||||
|
*/
|
||||||
|
IplConvKernel *
|
||||||
|
rb_cvCreateStructuringElementEx(int cols, int rows,
|
||||||
|
int anchorX, int anchorY,
|
||||||
|
int shape, int *values)
|
||||||
|
{
|
||||||
|
IplConvKernel* ptr = NULL;
|
||||||
|
try {
|
||||||
|
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
||||||
|
}
|
||||||
|
catch(cv::Exception& e) {
|
||||||
|
if (e.code != CV_StsNoMem)
|
||||||
|
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||||
|
|
||||||
|
rb_gc_start();
|
||||||
|
try {
|
||||||
|
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
if (e.code == CV_StsNoMem)
|
||||||
|
rb_raise(rb_eNoMemError, "%s", e.what());
|
||||||
|
else
|
||||||
|
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
VALUE rb_module;
|
VALUE rb_module;
|
||||||
VALUE rb_opencv_constants;
|
VALUE rb_opencv_constants;
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,7 @@ void define_ruby_module();
|
||||||
void* rb_cvAlloc(size_t size);
|
void* rb_cvAlloc(size_t size);
|
||||||
CvMat* rb_cvCreateMat(int height, int width, int type);
|
CvMat* rb_cvCreateMat(int height, int width, int type);
|
||||||
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
|
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
|
||||||
|
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
|
||||||
|
|
||||||
// Ruby/OpenCV inline functions
|
// Ruby/OpenCV inline functions
|
||||||
inline CvArr*
|
inline CvArr*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue