ruby-opencv 0.0.8.pre-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +225 -0
- data/README.rdoc +149 -0
- data/Rakefile +32 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/matching_to_many_images.rb +16 -0
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +3 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +499 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +296 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5848 -0
- data/ext/opencv/cvmat.h +284 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +245 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +194 -0
- data/ext/opencv/cvutils.h +29 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +644 -0
- data/ext/opencv/iplimage.h +73 -0
- data/ext/opencv/lib/opencv.rb +3 -0
- data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
- data/ext/opencv/lib/opencv/version.rb +3 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +722 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +274 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/extconf.rb +75 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/opencv.rb +3 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +43 -0
- data/test/helper.rb +166 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/chessboard.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +2947 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2025 -0
- data/test/test_cvmat_matching.rb +57 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +236 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +324 -0
- data/test/test_pointset.rb +126 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +414 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
iplconvkernel.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_IPLCONVKERNEL_H
|
11
|
+
#define RUBY_OPENCV_IPLCONVKERNEL_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_IPLCONVKERNEL namespace cIplConvKernel {
|
16
|
+
#define __NAMESPACE_END_IPLCONVKERNEL }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_IPLCONVKERNEL
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
VALUE rb_allocate(VALUE klass);
|
23
|
+
|
24
|
+
void define_ruby_class();
|
25
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
26
|
+
VALUE rb_size(VALUE self);
|
27
|
+
VALUE rb_cols(VALUE self);
|
28
|
+
VALUE rb_rows(VALUE self);
|
29
|
+
VALUE rb_anchor(VALUE self);
|
30
|
+
VALUE rb_anchor_x(VALUE self);
|
31
|
+
VALUE rb_anchor_y(VALUE self);
|
32
|
+
|
33
|
+
__NAMESPACE_END_IPLCONVKERNEL
|
34
|
+
|
35
|
+
inline IplConvKernel*
|
36
|
+
IPLCONVKERNEL(VALUE object)
|
37
|
+
{
|
38
|
+
IplConvKernel *ptr;
|
39
|
+
Data_Get_Struct(object, IplConvKernel, ptr);
|
40
|
+
return ptr;
|
41
|
+
}
|
42
|
+
|
43
|
+
inline IplConvKernel*
|
44
|
+
IPLCONVKERNEL_WITH_CHECK(VALUE object)
|
45
|
+
{
|
46
|
+
if (!rb_obj_is_kind_of(object, cIplConvKernel::rb_class()))
|
47
|
+
raise_typeerror(object, cIplConvKernel::rb_class());
|
48
|
+
return IPLCONVKERNEL(object);
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
inline IplConvKernel*
|
53
|
+
IPLCONVKERNEL(VALUE object)
|
54
|
+
{
|
55
|
+
IplConvKernel *ptr;
|
56
|
+
if (NIL_P(object))
|
57
|
+
return NULL;
|
58
|
+
else if (rb_obj_is_kind_of(object, cIplConvKernel::rb_class())) {
|
59
|
+
Data_Get_Struct(object, IplConvKernel, ptr);
|
60
|
+
return ptr;
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
rb_warn("invalid kernel. use default kernel (3x3 rectangle).");
|
64
|
+
return NULL;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
*/
|
68
|
+
|
69
|
+
__NAMESPACE_END_OPENCV
|
70
|
+
|
71
|
+
#endif // RUBY_OPENCV_IPLCONVKERNEL_H
|
@@ -0,0 +1,644 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
iplimage.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "iplimage.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::IplImage
|
13
|
+
*
|
14
|
+
* IPL(Intel Image Processing Library) Image class.
|
15
|
+
*
|
16
|
+
* IplImage is subclass of CvMat. IplImage support ROI(region of interest) and COI(color of interest).
|
17
|
+
* Most of CvMat method support ROI, and some of CvMat method support COI.
|
18
|
+
*
|
19
|
+
* =What is ROI?
|
20
|
+
* region of interest.
|
21
|
+
*
|
22
|
+
* =What is COI?
|
23
|
+
* color of interest.
|
24
|
+
*/
|
25
|
+
__NAMESPACE_BEGIN_OPENCV
|
26
|
+
__NAMESPACE_BEGIN_IPLIMAGE
|
27
|
+
|
28
|
+
VALUE rb_klass;
|
29
|
+
|
30
|
+
VALUE
|
31
|
+
rb_class()
|
32
|
+
{
|
33
|
+
return rb_klass;
|
34
|
+
}
|
35
|
+
|
36
|
+
void
|
37
|
+
define_ruby_class()
|
38
|
+
{
|
39
|
+
if (rb_klass)
|
40
|
+
return;
|
41
|
+
/*
|
42
|
+
* opencv = rb_define_module("OpenCV");
|
43
|
+
* cvmat = rb_define_class_under(opencv, "CvMat", rb_cObject);
|
44
|
+
*
|
45
|
+
* note: this comment is used by rdoc.
|
46
|
+
*/
|
47
|
+
VALUE opencv = rb_module_opencv();
|
48
|
+
VALUE cvmat = cCvMat::rb_class();
|
49
|
+
rb_klass = rb_define_class_under(opencv, "IplImage", cvmat);
|
50
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
51
|
+
rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load_image), -1);
|
52
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
53
|
+
rb_define_method(rb_klass, "get_roi", RUBY_METHOD_FUNC(rb_get_roi), 0);
|
54
|
+
rb_define_alias(rb_klass, "roi", "get_roi");
|
55
|
+
rb_define_method(rb_klass, "set_roi", RUBY_METHOD_FUNC(rb_set_roi), 1);
|
56
|
+
rb_define_alias(rb_klass, "roi=", "set_roi");
|
57
|
+
rb_define_method(rb_klass, "reset_roi", RUBY_METHOD_FUNC(rb_reset_roi), 0);
|
58
|
+
rb_define_method(rb_klass, "get_coi", RUBY_METHOD_FUNC(rb_get_coi), 0);
|
59
|
+
rb_define_alias(rb_klass, "coi", "get_coi");
|
60
|
+
rb_define_method(rb_klass, "set_coi", RUBY_METHOD_FUNC(rb_set_coi), 1);
|
61
|
+
rb_define_alias(rb_klass, "coi=", "set_coi");
|
62
|
+
rb_define_method(rb_klass, "reset_coi", RUBY_METHOD_FUNC(rb_reset_coi), 0);
|
63
|
+
rb_define_method(rb_klass, "pyr_segmentation", RUBY_METHOD_FUNC(rb_pyr_segmentation), 3);
|
64
|
+
rb_define_method(rb_klass, "smoothness", RUBY_METHOD_FUNC(rb_smoothness), -1);
|
65
|
+
|
66
|
+
rb_define_singleton_method(rb_klass, "decode_image", RUBY_METHOD_FUNC(rb_decode_image), -1);
|
67
|
+
rb_define_alias(rb_singleton_class(rb_klass), "decode", "decode_image");
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE
|
71
|
+
rb_allocate(VALUE klass)
|
72
|
+
{
|
73
|
+
return OPENCV_OBJECT(rb_klass, 0);
|
74
|
+
}
|
75
|
+
|
76
|
+
/*
|
77
|
+
* call-seq:
|
78
|
+
* new(<i>width, height[, depth = CV_8U][, channel = 3]</i>)
|
79
|
+
*
|
80
|
+
* Create width * height image. Each element-value set 0.
|
81
|
+
*
|
82
|
+
* Each element possigle range is set by <i>depth</i>. Default is unsigned 8bit.
|
83
|
+
*
|
84
|
+
* Number of channel is set by <i>channel</i>. <i>channel</i> should be 1..4.
|
85
|
+
*
|
86
|
+
* note: width = col, height = row, on CvMat. It is noted not to make a mistake
|
87
|
+
* because the order of argument is differenct to CvMat.
|
88
|
+
*/
|
89
|
+
VALUE
|
90
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
91
|
+
{
|
92
|
+
VALUE width, height, depth, channel;
|
93
|
+
rb_scan_args(argc, argv, "22", &width, &height, &depth, &channel);
|
94
|
+
int _depth = CVMETHOD("DEPTH", depth, CV_8U);
|
95
|
+
int _channel = argc < 4 ? 3 : NUM2INT(channel);
|
96
|
+
DATA_PTR(self) = rb_cvCreateImage(cvSize(NUM2INT(width), NUM2INT(height)), cvIplDepth(_depth), _channel);
|
97
|
+
return self;
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* IplImage::load(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>)
|
103
|
+
*
|
104
|
+
* Load an image from file.
|
105
|
+
* iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image
|
106
|
+
* iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale
|
107
|
+
* iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is.
|
108
|
+
* Currently the following file format are supported.
|
109
|
+
* * Windows bitmaps - BMP,DIB
|
110
|
+
* * JPEG files - JPEG,JPG,JPE
|
111
|
+
* * Portable Network Graphics - PNG
|
112
|
+
* * Portable image format - PBM,PGM,PPM
|
113
|
+
* * Sun rasters - SR,RAS
|
114
|
+
* * TIFF files - TIFF,TIF
|
115
|
+
*/
|
116
|
+
VALUE
|
117
|
+
rb_load_image(int argc, VALUE *argv, VALUE self)
|
118
|
+
{
|
119
|
+
VALUE filename, iscolor;
|
120
|
+
rb_scan_args(argc, argv, "11", &filename, &iscolor);
|
121
|
+
Check_Type(filename, T_STRING);
|
122
|
+
|
123
|
+
int _iscolor;
|
124
|
+
if (TYPE(iscolor) == T_NIL) {
|
125
|
+
_iscolor = CV_LOAD_IMAGE_COLOR;
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
Check_Type(iscolor, T_FIXNUM);
|
129
|
+
_iscolor = FIX2INT(iscolor);
|
130
|
+
}
|
131
|
+
|
132
|
+
IplImage *image;
|
133
|
+
if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) {
|
134
|
+
rb_raise(rb_eStandardError, "file does not exist or invalid format image.");
|
135
|
+
}
|
136
|
+
return OPENCV_OBJECT(rb_klass, image);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* decode_image(buf[, iscolor=CV_LOAD_IMAGE_COLOR]) -> IplImage
|
142
|
+
*
|
143
|
+
* Reads an image from a buffer in memory.
|
144
|
+
*
|
145
|
+
* Parameters:
|
146
|
+
* buf <CvMat, Array, String> - Input array
|
147
|
+
* iscolor <Integer> - Flags specifying the color type of a decoded image (the same flags as CvMat#load)
|
148
|
+
*/
|
149
|
+
VALUE
|
150
|
+
rb_decode_image(int argc, VALUE *argv, VALUE self)
|
151
|
+
{
|
152
|
+
int iscolor, need_release;
|
153
|
+
CvMat* buff = cCvMat::prepare_decoding(argc, argv, &iscolor, &need_release);
|
154
|
+
IplImage* img_ptr = NULL;
|
155
|
+
try {
|
156
|
+
img_ptr = cvDecodeImage(buff, iscolor);
|
157
|
+
if (need_release) {
|
158
|
+
cvReleaseMat(&buff);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
catch (cv::Exception& e) {
|
162
|
+
raise_cverror(e);
|
163
|
+
}
|
164
|
+
|
165
|
+
return OPENCV_OBJECT(rb_klass, img_ptr);
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Get ROI as CvRect.
|
170
|
+
*/
|
171
|
+
VALUE
|
172
|
+
rb_get_roi(VALUE self)
|
173
|
+
{
|
174
|
+
CvRect rect;
|
175
|
+
try {
|
176
|
+
rect = cvGetImageROI(IPLIMAGE(self));
|
177
|
+
}
|
178
|
+
catch (cv::Exception& e) {
|
179
|
+
raise_cverror(e);
|
180
|
+
}
|
181
|
+
return cCvRect::new_object(rect);
|
182
|
+
}
|
183
|
+
|
184
|
+
/*
|
185
|
+
* call-seq:
|
186
|
+
* set_roi(<i>rect</i>)
|
187
|
+
* set_roi(<i>rect</i>){|image| ...}
|
188
|
+
*
|
189
|
+
* Set ROI. <i>rect</i> should be CvRect or compatible object.
|
190
|
+
* Return self.
|
191
|
+
*/
|
192
|
+
VALUE
|
193
|
+
rb_set_roi(VALUE self, VALUE roi)
|
194
|
+
{
|
195
|
+
VALUE block = rb_block_given_p() ? rb_block_proc() : 0;
|
196
|
+
try {
|
197
|
+
if (block) {
|
198
|
+
CvRect prev_roi = cvGetImageROI(IPLIMAGE(self));
|
199
|
+
cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi));
|
200
|
+
rb_yield_values(1, self);
|
201
|
+
cvSetImageROI(IPLIMAGE(self), prev_roi);
|
202
|
+
}
|
203
|
+
else {
|
204
|
+
cvSetImageROI(IPLIMAGE(self), VALUE_TO_CVRECT(roi));
|
205
|
+
}
|
206
|
+
}
|
207
|
+
catch (cv::Exception& e) {
|
208
|
+
raise_cverror(e);
|
209
|
+
}
|
210
|
+
return self;
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
/*
|
215
|
+
* Reset ROI setting. Same as IplImage#roi = nil. Return self.
|
216
|
+
*/
|
217
|
+
VALUE
|
218
|
+
rb_reset_roi(VALUE self)
|
219
|
+
{
|
220
|
+
try {
|
221
|
+
cvResetImageROI(IPLIMAGE(self));
|
222
|
+
}
|
223
|
+
catch (cv::Exception& e) {
|
224
|
+
raise_cverror(e);
|
225
|
+
}
|
226
|
+
return self;
|
227
|
+
}
|
228
|
+
|
229
|
+
/*
|
230
|
+
* Return COI as Fixnum.
|
231
|
+
*/
|
232
|
+
VALUE
|
233
|
+
rb_get_coi(VALUE self)
|
234
|
+
{
|
235
|
+
int coi = 0;
|
236
|
+
try {
|
237
|
+
coi = cvGetImageCOI(IPLIMAGE(self));
|
238
|
+
}
|
239
|
+
catch (cv::Exception& e) {
|
240
|
+
raise_cverror(e);
|
241
|
+
}
|
242
|
+
return INT2FIX(coi);
|
243
|
+
}
|
244
|
+
|
245
|
+
/*
|
246
|
+
* call-seq:
|
247
|
+
* set_coi(<i>coi</i>)
|
248
|
+
* set_coi(<i>coi</i>){|image| ...}
|
249
|
+
*
|
250
|
+
* Set COI. <i>coi</i> should be Fixnum.
|
251
|
+
* Return self.
|
252
|
+
*/
|
253
|
+
VALUE
|
254
|
+
rb_set_coi(VALUE self, VALUE coi)
|
255
|
+
{
|
256
|
+
VALUE block = rb_block_given_p() ? rb_block_proc() : 0;
|
257
|
+
try {
|
258
|
+
if (block) {
|
259
|
+
int prev_coi = cvGetImageCOI(IPLIMAGE(self));
|
260
|
+
cvSetImageCOI(IPLIMAGE(self), NUM2INT(coi));
|
261
|
+
rb_yield_values(1, self);
|
262
|
+
cvSetImageCOI(IPLIMAGE(self), prev_coi);
|
263
|
+
}
|
264
|
+
else {
|
265
|
+
cvSetImageCOI(IPLIMAGE(self), NUM2INT(coi));
|
266
|
+
}
|
267
|
+
}
|
268
|
+
catch (cv::Exception& e) {
|
269
|
+
raise_cverror(e);
|
270
|
+
}
|
271
|
+
return self;
|
272
|
+
}
|
273
|
+
|
274
|
+
/*
|
275
|
+
* Reset COI setting. Same as IplImage#coi = 0. Return self.
|
276
|
+
*/
|
277
|
+
VALUE
|
278
|
+
rb_reset_coi(VALUE self)
|
279
|
+
{
|
280
|
+
try {
|
281
|
+
cvSetImageCOI(IPLIMAGE(self), 0);
|
282
|
+
}
|
283
|
+
catch (cv::Exception& e) {
|
284
|
+
raise_cverror(e);
|
285
|
+
}
|
286
|
+
return self;
|
287
|
+
}
|
288
|
+
|
289
|
+
/*
|
290
|
+
* call-seq:
|
291
|
+
* IplImage.smoothness(<i>lowFreqRatio, blankDensity, messyDensity, highFreqRatio</i>) -> [ symbol, float, float ]
|
292
|
+
*
|
293
|
+
* Determines if the image's smoothness is either, :smooth, :messy, or :blank.
|
294
|
+
*
|
295
|
+
* Original Author: yuhanz@gmail.com
|
296
|
+
*/
|
297
|
+
VALUE
|
298
|
+
rb_smoothness(int argc, VALUE *argv, VALUE self)
|
299
|
+
{
|
300
|
+
VALUE lowFreqRatio, blankDensity, messyDensity, highFreqRatio;
|
301
|
+
rb_scan_args(argc, argv, "04", &lowFreqRatio, &blankDensity, &messyDensity, &highFreqRatio);
|
302
|
+
|
303
|
+
double f_lowFreqRatio, f_blankDensity, f_messyDensity, f_highFreqRatio;
|
304
|
+
double outLowDensity, outHighDensity;
|
305
|
+
if (TYPE(lowFreqRatio) == T_NIL) {
|
306
|
+
f_lowFreqRatio = 10 / 128.0f;
|
307
|
+
}
|
308
|
+
else {
|
309
|
+
Check_Type(lowFreqRatio, T_FLOAT);
|
310
|
+
f_lowFreqRatio = NUM2DBL(lowFreqRatio);
|
311
|
+
}
|
312
|
+
if (TYPE(blankDensity) == T_NIL) {
|
313
|
+
f_blankDensity = 1.2f;
|
314
|
+
}
|
315
|
+
else {
|
316
|
+
Check_Type(blankDensity, T_FLOAT);
|
317
|
+
f_blankDensity = NUM2DBL(blankDensity);
|
318
|
+
}
|
319
|
+
if (TYPE(messyDensity) == T_NIL) {
|
320
|
+
f_messyDensity = 0.151f;
|
321
|
+
}
|
322
|
+
else {
|
323
|
+
Check_Type(messyDensity, T_FLOAT);
|
324
|
+
f_messyDensity = NUM2DBL(messyDensity);
|
325
|
+
}
|
326
|
+
if (TYPE(highFreqRatio) == T_NIL) {
|
327
|
+
f_highFreqRatio = 5 / 128.0f;
|
328
|
+
}
|
329
|
+
else {
|
330
|
+
Check_Type(highFreqRatio, T_FLOAT);
|
331
|
+
f_highFreqRatio = NUM2DBL(highFreqRatio);
|
332
|
+
}
|
333
|
+
|
334
|
+
IplImage *pFourierImage;
|
335
|
+
IplImage *p64DepthImage;
|
336
|
+
|
337
|
+
// the image is required to be in depth of 64
|
338
|
+
if (IPLIMAGE(self)->depth == 64) {
|
339
|
+
p64DepthImage = NULL;
|
340
|
+
pFourierImage = create_fourier_image(IPLIMAGE(self));
|
341
|
+
}
|
342
|
+
else {
|
343
|
+
p64DepthImage = rb_cvCreateImage(cvGetSize(IPLIMAGE(self)), IPL_DEPTH_64F, 1);
|
344
|
+
cvConvertScale(CVARR(self), p64DepthImage, 1.0, 0.0);
|
345
|
+
pFourierImage = create_fourier_image(p64DepthImage);
|
346
|
+
}
|
347
|
+
|
348
|
+
Smoothness result = compute_smoothness(pFourierImage, f_lowFreqRatio, f_blankDensity, f_messyDensity,
|
349
|
+
f_highFreqRatio, outLowDensity, outHighDensity);
|
350
|
+
|
351
|
+
cvReleaseImage(&pFourierImage);
|
352
|
+
if (p64DepthImage != NULL)
|
353
|
+
cvReleaseImage(&p64DepthImage);
|
354
|
+
|
355
|
+
switch(result) {
|
356
|
+
case SMOOTH:
|
357
|
+
return rb_ary_new3(3, ID2SYM(rb_intern("smooth")), rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
358
|
+
case MESSY:
|
359
|
+
return rb_ary_new3(3, ID2SYM(rb_intern("messy")), rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
360
|
+
case BLANK:
|
361
|
+
return rb_ary_new3(3, ID2SYM(rb_intern("blank")), rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
362
|
+
default:
|
363
|
+
return rb_ary_new3(3, NULL, rb_float_new(outLowDensity), rb_float_new(outHighDensity));
|
364
|
+
}
|
365
|
+
}
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Note: if lowDensity < blankDensityThreshold -> blank;
|
369
|
+
* else if highDensity > messyDensityThreshold -> messy;
|
370
|
+
* else -> good;
|
371
|
+
*/
|
372
|
+
Smoothness
|
373
|
+
compute_smoothness(const IplImage *pFourierImage, const double lowFreqRatio, const double blankDensity,
|
374
|
+
const double messyDensity, const double highFreqRatio, double &outLowDensity,
|
375
|
+
double &outHighDensity)
|
376
|
+
{
|
377
|
+
int low, high;
|
378
|
+
IplImage *filteredFourierImage;
|
379
|
+
int totalIntensity;
|
380
|
+
double den, totalArea;
|
381
|
+
CvScalar scalar;
|
382
|
+
|
383
|
+
if (!(pFourierImage->nChannels == 1 && pFourierImage->depth == 64) ) {
|
384
|
+
cvError(CV_StsUnmatchedSizes, "compute_smoothness", "input image must contain only 1 channel and a depth of 64",
|
385
|
+
__FILE__, __LINE__ );
|
386
|
+
}
|
387
|
+
|
388
|
+
high_pass_range(pFourierImage, lowFreqRatio, low, high );
|
389
|
+
totalArea = M_PI * (high * high - low * low);
|
390
|
+
|
391
|
+
filteredFourierImage = create_frequency_filtered_image(pFourierImage, low, high);
|
392
|
+
scalar = cvSum(filteredFourierImage);
|
393
|
+
totalIntensity = (int)scalar.val[0];
|
394
|
+
cvReleaseImage(&filteredFourierImage);
|
395
|
+
outLowDensity = den = totalIntensity / totalArea;
|
396
|
+
|
397
|
+
if (den <= blankDensity) {
|
398
|
+
return BLANK;
|
399
|
+
}
|
400
|
+
|
401
|
+
low = (int)(high * (1.0 - highFreqRatio));
|
402
|
+
|
403
|
+
filteredFourierImage = create_frequency_filtered_image(pFourierImage, low, high);
|
404
|
+
scalar = cvSum(filteredFourierImage);
|
405
|
+
totalIntensity = (int)scalar.val[0];
|
406
|
+
cvReleaseImage(&filteredFourierImage);
|
407
|
+
outHighDensity = den = totalIntensity / totalArea;
|
408
|
+
|
409
|
+
if (den >= messyDensity) {
|
410
|
+
return MESSY;
|
411
|
+
}
|
412
|
+
|
413
|
+
return SMOOTH;
|
414
|
+
}
|
415
|
+
|
416
|
+
// Rearrange the quadrants of Fourier image so that the origin is at
|
417
|
+
// the image center
|
418
|
+
// src & dst arrays of equal size & type
|
419
|
+
void
|
420
|
+
cvShiftDFT(CvArr *src_arr, CvArr *dst_arr )
|
421
|
+
{
|
422
|
+
CvMat *tmp = NULL;
|
423
|
+
CvMat q1stub, q2stub;
|
424
|
+
CvMat q3stub, q4stub;
|
425
|
+
CvMat d1stub, d2stub;
|
426
|
+
CvMat d3stub, d4stub;
|
427
|
+
CvMat *q1, *q2, *q3, *q4;
|
428
|
+
CvMat *d1, *d2, *d3, *d4;
|
429
|
+
|
430
|
+
CvSize size = cvGetSize(src_arr);
|
431
|
+
CvSize dst_size = cvGetSize(dst_arr);
|
432
|
+
int cx, cy;
|
433
|
+
|
434
|
+
if (dst_size.width != size.width ||
|
435
|
+
dst_size.height != size.height) {
|
436
|
+
cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes",
|
437
|
+
__FILE__, __LINE__ );
|
438
|
+
}
|
439
|
+
|
440
|
+
if (src_arr == dst_arr) {
|
441
|
+
tmp = rb_cvCreateMat(size.height / 2, size.width / 2, cvGetElemType(src_arr));
|
442
|
+
}
|
443
|
+
|
444
|
+
cx = size.width / 2;
|
445
|
+
cy = size.height / 2; // image center
|
446
|
+
|
447
|
+
q1 = cvGetSubRect(src_arr, &q1stub, cvRect(0,0,cx, cy));
|
448
|
+
q2 = cvGetSubRect(src_arr, &q2stub, cvRect(cx,0,cx,cy));
|
449
|
+
q3 = cvGetSubRect(src_arr, &q3stub, cvRect(cx,cy,cx,cy));
|
450
|
+
q4 = cvGetSubRect(src_arr, &q4stub, cvRect(0,cy,cx,cy));
|
451
|
+
d1 = cvGetSubRect(src_arr, &d1stub, cvRect(0,0,cx,cy));
|
452
|
+
d2 = cvGetSubRect(src_arr, &d2stub, cvRect(cx,0,cx,cy));
|
453
|
+
d3 = cvGetSubRect(src_arr, &d3stub, cvRect(cx,cy,cx,cy));
|
454
|
+
d4 = cvGetSubRect(src_arr, &d4stub, cvRect(0,cy,cx,cy));
|
455
|
+
|
456
|
+
if (src_arr != dst_arr) {
|
457
|
+
if (!CV_ARE_TYPES_EQ(q1, d1)) {
|
458
|
+
cvError(CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format",
|
459
|
+
__FILE__, __LINE__ );
|
460
|
+
}
|
461
|
+
cvCopy(q3, d1, 0);
|
462
|
+
cvCopy(q4, d2, 0);
|
463
|
+
cvCopy(q1, d3, 0);
|
464
|
+
cvCopy(q2, d4, 0);
|
465
|
+
}
|
466
|
+
else {
|
467
|
+
cvCopy(q3, tmp, 0);
|
468
|
+
cvCopy(q1, q3, 0);
|
469
|
+
cvCopy(tmp, q1, 0);
|
470
|
+
cvCopy(q4, tmp, 0);
|
471
|
+
cvCopy(q2, q4, 0);
|
472
|
+
cvCopy(tmp, q2, 0);
|
473
|
+
}
|
474
|
+
|
475
|
+
if (tmp != NULL) {
|
476
|
+
cvReleaseMat(&tmp);
|
477
|
+
}
|
478
|
+
}
|
479
|
+
|
480
|
+
IplImage*
|
481
|
+
create_fourier_image(const IplImage *im)
|
482
|
+
{
|
483
|
+
IplImage *realInput;
|
484
|
+
IplImage *imaginaryInput;
|
485
|
+
IplImage *complexInput;
|
486
|
+
int dft_M, dft_N;
|
487
|
+
CvMat *dft_A, tmp;
|
488
|
+
IplImage *image_Re;
|
489
|
+
IplImage *image_Im;
|
490
|
+
|
491
|
+
realInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 1);
|
492
|
+
imaginaryInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 1);
|
493
|
+
complexInput = rb_cvCreateImage(cvGetSize(im), IPL_DEPTH_64F, 2);
|
494
|
+
|
495
|
+
cvScale(im, realInput, 1.0, 0.0);
|
496
|
+
cvZero(imaginaryInput);
|
497
|
+
cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
|
498
|
+
|
499
|
+
dft_M = cvGetOptimalDFTSize(im->height - 1);
|
500
|
+
dft_N = cvGetOptimalDFTSize(im->width - 1);
|
501
|
+
|
502
|
+
dft_A = rb_cvCreateMat(dft_M, dft_N, CV_64FC2);
|
503
|
+
image_Re = rb_cvCreateImage(cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
|
504
|
+
image_Im = rb_cvCreateImage(cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
|
505
|
+
|
506
|
+
// copy A to dft_A and pad dft_A with zeros
|
507
|
+
cvGetSubRect(dft_A, &tmp, cvRect(0,0, im->width, im->height));
|
508
|
+
cvCopy(complexInput, &tmp, NULL);
|
509
|
+
if (dft_A->cols > im->width) {
|
510
|
+
cvGetSubRect(dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height));
|
511
|
+
cvZero(&tmp);
|
512
|
+
}
|
513
|
+
|
514
|
+
// no need to pad bottom part of dft_A with zeros because of
|
515
|
+
// use nonzero_rows parameter in cvDFT() call below
|
516
|
+
|
517
|
+
cvDFT(dft_A, dft_A, CV_DXT_FORWARD, complexInput->height);
|
518
|
+
|
519
|
+
// Split Fourier in real and imaginary parts
|
520
|
+
cvSplit(dft_A, image_Re, image_Im, 0, 0);
|
521
|
+
|
522
|
+
// Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
|
523
|
+
cvPow(image_Re, image_Re, 2.0);
|
524
|
+
cvPow(image_Im, image_Im, 2.0);
|
525
|
+
cvAdd(image_Re, image_Im, image_Re, NULL);
|
526
|
+
cvPow(image_Re, image_Re, 0.5);
|
527
|
+
|
528
|
+
// Compute log(1 + Mag)
|
529
|
+
cvAddS(image_Re, cvScalarAll(1.0), image_Re, NULL); // 1 + Mag
|
530
|
+
cvLog(image_Re, image_Re); // log(1 + Mag)
|
531
|
+
|
532
|
+
// Rearrange the quadrants of Fourier image so that the origin is at
|
533
|
+
// the image center
|
534
|
+
cvShiftDFT(image_Re, image_Re);
|
535
|
+
|
536
|
+
cvReleaseImage(&realInput);
|
537
|
+
cvReleaseImage(&imaginaryInput);
|
538
|
+
cvReleaseImage(&complexInput);
|
539
|
+
cvReleaseImage(&image_Im);
|
540
|
+
|
541
|
+
cvReleaseMat(&dft_A);
|
542
|
+
|
543
|
+
return image_Re;
|
544
|
+
}
|
545
|
+
|
546
|
+
IplImage*
|
547
|
+
create_frequency_filtered_image(const IplImage *pImage, int low, int high)
|
548
|
+
{
|
549
|
+
|
550
|
+
CvPoint2D32f center;
|
551
|
+
center.x = (float)(pImage->width / 2);
|
552
|
+
center.y = (float)(pImage->height / 2);
|
553
|
+
CvBox2D box;
|
554
|
+
box.center = center;
|
555
|
+
|
556
|
+
box.size.width = (float)high;
|
557
|
+
box.size.height = (float)high;
|
558
|
+
|
559
|
+
IplImage *pFilterMask = rb_cvCreateImage(cvGetSize(pImage), IPL_DEPTH_64F, 1);
|
560
|
+
IplImage *pFiltered = rb_cvCreateImage(cvGetSize(pImage), IPL_DEPTH_64F, 1);
|
561
|
+
|
562
|
+
cvZero(pFilterMask);
|
563
|
+
cvZero(pFiltered);
|
564
|
+
|
565
|
+
if (high > 0)
|
566
|
+
cvEllipseBox(pFilterMask, box, cvScalar(255, 255, 255, 255), CV_FILLED, 8, 0);
|
567
|
+
|
568
|
+
box.size.width = (float)low;
|
569
|
+
box.size.height = (float)low;
|
570
|
+
if (low > 0)
|
571
|
+
cvEllipseBox(pFilterMask, box, cvScalar(0, 0, 0, 0), CV_FILLED, 8, 0);
|
572
|
+
|
573
|
+
cvAnd(pImage, pFilterMask, pFiltered, NULL);
|
574
|
+
|
575
|
+
cvReleaseImage(&pFilterMask);
|
576
|
+
|
577
|
+
return pFiltered;
|
578
|
+
}
|
579
|
+
|
580
|
+
void
|
581
|
+
high_pass_range(const IplImage *pImage, float lostPercentage, int &outLow, int &outHigh)
|
582
|
+
{
|
583
|
+
if (lostPercentage > 1.0f) {
|
584
|
+
lostPercentage = 1;
|
585
|
+
}
|
586
|
+
else if (lostPercentage < 0.0f) {
|
587
|
+
lostPercentage = 0;
|
588
|
+
}
|
589
|
+
|
590
|
+
outHigh = (int)MIN(pImage->width, pImage->height);
|
591
|
+
outLow = (int)(lostPercentage * outHigh);
|
592
|
+
}
|
593
|
+
|
594
|
+
/*
|
595
|
+
* call-seq:
|
596
|
+
* pyr_segmentation(<i>level, threshold1, threshold2</i>) -> [iplimage, cvseq(include cvconnectedcomp)]
|
597
|
+
*
|
598
|
+
* Does image segmentation by pyramids.
|
599
|
+
* The pyramid builds up to the level <i>level<i>.
|
600
|
+
* The links between any pixel a on <i>level<i>i and
|
601
|
+
* its candidate father pixel b on the adjacent level are established if
|
602
|
+
* p(c(a),c(b)) < threshold1. After the connected components are defined, they are joined into several clusters. Any two segments A and B belong to the same cluster, if
|
603
|
+
* p(c(A),c(B)) < threshold2. The input image has only one channel, then
|
604
|
+
* p(c^2,c^2)=|c^2-c^2|. If the input image has three channels (red, green and blue), then
|
605
|
+
* p(c^2,c^2)=0,3*(c^2 r-c^2 r)+0.59*(c^2 g-c^2 g)+0,11*(c^2 b-c^2 b) . There may be more than one connected component per a cluster.
|
606
|
+
*
|
607
|
+
* Return segmented image and sequence of connected components.
|
608
|
+
* <b>support single-channel or 3-channel 8bit unsigned image only</b>
|
609
|
+
*/
|
610
|
+
VALUE
|
611
|
+
rb_pyr_segmentation(VALUE self, VALUE level, VALUE threshold1, VALUE threshold2)
|
612
|
+
{
|
613
|
+
IplImage* self_ptr = IPLIMAGE(self);
|
614
|
+
CvSeq *comp = NULL;
|
615
|
+
VALUE storage = cCvMemStorage::new_object();
|
616
|
+
VALUE dest = Qnil;
|
617
|
+
try {
|
618
|
+
dest = cIplImage::new_object(cvGetSize(self_ptr), cvGetElemType(self_ptr));
|
619
|
+
cvPyrSegmentation(self_ptr, IPLIMAGE(dest), CVMEMSTORAGE(storage), &comp,
|
620
|
+
NUM2INT(level), NUM2DBL(threshold1), NUM2DBL(threshold2));
|
621
|
+
}
|
622
|
+
catch (cv::Exception& e) {
|
623
|
+
raise_cverror(e);
|
624
|
+
}
|
625
|
+
if (!comp) {
|
626
|
+
comp = cvCreateSeq(CV_SEQ_CONNECTED_COMP, sizeof(CvSeq), sizeof(CvConnectedComp), CVMEMSTORAGE(storage));
|
627
|
+
}
|
628
|
+
return rb_ary_new3(2, dest, cCvSeq::new_sequence(cCvSeq::rb_class(), comp, cCvConnectedComp::rb_class(), storage));
|
629
|
+
}
|
630
|
+
|
631
|
+
VALUE
|
632
|
+
new_object(int width, int height, int type)
|
633
|
+
{
|
634
|
+
return OPENCV_OBJECT(rb_klass, rb_cvCreateImage(cvSize(width, height), cvIplDepth(type), CV_MAT_CN(type)));
|
635
|
+
}
|
636
|
+
|
637
|
+
VALUE
|
638
|
+
new_object(CvSize size, int type)
|
639
|
+
{
|
640
|
+
return OPENCV_OBJECT(rb_klass, rb_cvCreateImage(size, cvIplDepth(type), CV_MAT_CN(type)));
|
641
|
+
}
|
642
|
+
|
643
|
+
__NAMESPACE_END_IPLIMAGE
|
644
|
+
__NAMESPACE_END_OPENCV
|