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

add IplImage#decode (wrapper of cvDecodeImage)

This commit is contained in:
ser1zw 2012-07-15 03:14:39 +09:00
parent 35537b6248
commit 36f6864dfa
5 changed files with 108 additions and 15 deletions

View file

@ -62,6 +62,9 @@ define_ruby_class()
rb_define_method(rb_klass, "reset_coi", RUBY_METHOD_FUNC(rb_reset_coi), 0);
rb_define_method(rb_klass, "smoothness", RUBY_METHOD_FUNC(rb_smoothness), -1);
rb_define_singleton_method(rb_klass, "decode_image", RUBY_METHOD_FUNC(rb_decode_image), -1);
rb_define_alias(rb_singleton_class(rb_klass), "decode", "decode_image");
}
VALUE
@ -133,6 +136,35 @@ rb_load_image(int argc, VALUE *argv, VALUE self)
return OPENCV_OBJECT(rb_klass, image);
}
/*
* call-seq:
* decode_image(buf[, iscolor=CV_LOAD_IMAGE_COLOR]) -> CvMat
*
* Reads an image from a buffer in memory.
*
* Parameters:
* buf <CvMat, Array, String> - Input array
* iscolor <Integer> - Flags specifying the color type of a decoded image (the same flags as CvMat#load)
*/
VALUE
rb_decode_image(int argc, VALUE *argv, VALUE self)
{
int iscolor, need_release;
CvMat* buff = cCvMat::prepare_decoding(argc, argv, &iscolor, &need_release);
IplImage* img_ptr = NULL;
try {
img_ptr = cvDecodeImage(buff, iscolor);
if (need_release) {
cvReleaseMat(&buff);
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return OPENCV_OBJECT(rb_klass, img_ptr);
}
/*
* Get ROI as CvRect.
*/