diff --git a/ext/opencv/cvmat.cpp b/ext/opencv/cvmat.cpp index ddecfea..9d4c1c2 100644 --- a/ext/opencv/cvmat.cpp +++ b/ext/opencv/cvmat.cpp @@ -5250,6 +5250,21 @@ new_object(CvSize size, int type) return OPENCV_OBJECT(rb_klass, rb_cvCreateMat(size.height, size.width, type)); } +VALUE +new_mat_kind_object(CvSize size, VALUE ref_obj) +{ + VALUE return_type = CLASS_OF(ref_obj); + if (rb_obj_is_kind_of(ref_obj, cIplImage::rb_class())) { + IplImage* img = IPLIMAGE(ref_obj); + return OPENCV_OBJECT(return_type, rb_cvCreateImage(size, img->depth, img->nChannels)); + } + else if (rb_obj_is_kind_of(ref_obj, rb_klass)) // CvMat + return OPENCV_OBJECT(return_type, rb_cvCreateMat(size.height, size.width, cvGetElemType(CVMAT(ref_obj)))); + else + rb_raise(rb_eNotImpError, "Only CvMat or IplImage are supported"); + + return Qnil; +} __NAMESPACE_END_OPENCV __NAMESPACE_END_CVMAT diff --git a/ext/opencv/cvmat.h b/ext/opencv/cvmat.h index acf5099..de363ba 100644 --- a/ext/opencv/cvmat.h +++ b/ext/opencv/cvmat.h @@ -270,7 +270,7 @@ VALUE rb_save_image(VALUE self, VALUE filename); VALUE new_object(int rows, int cols, int type); VALUE new_object(CvSize size, int type); - +VALUE new_mat_kind_object(CvSize size, VALUE ref_obj); __NAMESPACE_END_CVMAT