/* * call-seq: * IplImage::load(<i>filename[,iscolor = nil]</i>) * * Load an image from file. * iscolor = true, the loaded image is forced to be color 3-channel image. * iscolor = false, the loaded image is forced to be grayscale. * iscolor = nil, the loaded image will be loaded as is (depend on the file). * Currently the following file format are supported. * * Windows bitmaps - BMP,DIB * * JPEG files - JPEG,JPG,JPE * * Portable Network Graphics - PNG * * Portable image format - PBM,PGM,PPM * * Sun rasters - SR,RAS * * TIFF files - TIFF,TIF */ VALUE rb_load_image(int argc, VALUE *argv, VALUE self) { VALUE filename, iscolor; rb_scan_args(argc, argv, "11", &filename, &iscolor); Check_Type(filename, T_STRING); int _iscolor; switch (TYPE(iscolor)) { case T_FALSE: _iscolor = 0; break; case T_TRUE: _iscolor = 1; break; case T_NIL: _iscolor = -1; break; default: rb_warn("argument 2 should be true(color)/false(non-color) or nil(auto)."); _iscolor = -1; } IplImage *image; if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) { rb_raise(rb_eStandardError, "file does not exist or invalid format image."); } return OPENCV_OBJECT(rb_klass, image); }
/* * call-seq: * CvHaarClassiferCascade.load(<i>path</i>) -> object-detector * * Load trained cascade of haar classifers from file. * Object detection classifiers are stored in XML or YAML files. * sample of object detection classifier files is included by OpenCV. * * You can found these at * C:\Program Files\OpenCV\data\haarcascades\*.xml (Windows, default install path) * * e.g. you want to try to detect human's face. * detector = CvHaarClassiferCascade.load("haarcascade_frontalface_alt.xml") */ VALUE rb_load(VALUE klass, VALUE path) { CvHaarClassifierCascade *cascade = (CvHaarClassifierCascade*)cvLoad(StringValueCStr(path), 0, 0, 0); if(!CV_IS_HAAR_CLASSIFIER(cascade)) rb_raise(rb_eTypeError, "invalid format haar classifier cascade file."); return OPENCV_OBJECT(rb_klass, cascade); }
/* * call-seq: * IplImage::load(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>) * * Load an image from file. * iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image * iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale * iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is. * Currently the following file format are supported. * * Windows bitmaps - BMP,DIB * * JPEG files - JPEG,JPG,JPE * * Portable Network Graphics - PNG * * Portable image format - PBM,PGM,PPM * * Sun rasters - SR,RAS * * TIFF files - TIFF,TIF */ VALUE rb_load_image(int argc, VALUE *argv, VALUE self) { VALUE filename, iscolor; rb_scan_args(argc, argv, "11", &filename, &iscolor); Check_Type(filename, T_STRING); int _iscolor; if (TYPE(iscolor) == T_NIL) { _iscolor = CV_LOAD_IMAGE_COLOR; } else { Check_Type(iscolor, T_FIXNUM); _iscolor = FIX2INT(iscolor); } IplImage *image; if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) { rb_raise(rb_eStandardError, "file does not exist or invalid format image."); } return OPENCV_OBJECT(rb_klass, image); }
VALUE rb_allocate(VALUE klass) { return OPENCV_OBJECT(rb_klass, 0); }
VALUE new_object(CvSize size, int type) { return OPENCV_OBJECT(rb_klass, rb_cvCreateImage(size, cvIplDepth(type), CV_MAT_CN(type))); }
VALUE new_object(int width, int height, int type) { return OPENCV_OBJECT(rb_klass, rb_cvCreateImage(cvSize(width, height), cvIplDepth(type), CV_MAT_CN(type))); }