ruby-opencv 0.0.9.pre2-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +227 -0
- data/README.md +98 -0
- data/Rakefile +90 -0
- data/config.yml +7 -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 +506 -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 +192 -0
- data/ext/opencv/cvutils.h +30 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/extconf.rb +83 -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/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/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 +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +44 -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 +386 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvtermcriteria.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVTERMCRITERIA_H
|
11
|
+
#define RUBY_OPENCV_CVTERMCRITERIA_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVTERMCRITERIA namespace cCvTermCriteria {
|
16
|
+
#define __NAMESPACE_END_CVTERMCRITERIA }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVTERMCRITERIA
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_allocate(VALUE klass);
|
26
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
27
|
+
|
28
|
+
VALUE rb_type(VALUE self);
|
29
|
+
VALUE rb_max(VALUE self);
|
30
|
+
VALUE rb_set_max(VALUE self, VALUE max_value);
|
31
|
+
VALUE rb_eps(VALUE self);
|
32
|
+
VALUE rb_set_eps(VALUE self, VALUE eps_value);
|
33
|
+
|
34
|
+
VALUE new_object(CvTermCriteria criteria);
|
35
|
+
|
36
|
+
__NAMESPACE_END_CVTERMCRITERIA
|
37
|
+
|
38
|
+
inline CvTermCriteria*
|
39
|
+
CVTERMCRITERIA(VALUE object)
|
40
|
+
{
|
41
|
+
CvTermCriteria *ptr;
|
42
|
+
Data_Get_Struct(object, CvTermCriteria, ptr);
|
43
|
+
return ptr;
|
44
|
+
}
|
45
|
+
|
46
|
+
inline CvTermCriteria
|
47
|
+
VALUE_TO_CVTERMCRITERIA(VALUE object)
|
48
|
+
{
|
49
|
+
if (rb_obj_is_kind_of(object, cCvTermCriteria::rb_class())) {
|
50
|
+
return *CVTERMCRITERIA(object);
|
51
|
+
}
|
52
|
+
switch (TYPE(object)) {
|
53
|
+
case T_NIL:
|
54
|
+
return cvTermCriteria(CV_TERMCRIT_ITER, 0, 0);
|
55
|
+
case T_FIXNUM:
|
56
|
+
return cvTermCriteria(CV_TERMCRIT_ITER, NUM2INT(object), 0);
|
57
|
+
case T_FLOAT:
|
58
|
+
return cvTermCriteria(CV_TERMCRIT_EPS, 0, NUM2DBL(object));
|
59
|
+
case T_ARRAY:
|
60
|
+
if (RARRAY_LEN(object) == 2) {
|
61
|
+
return cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS,
|
62
|
+
NUM2INT(rb_ary_entry(object, 0)),
|
63
|
+
NUM2DBL(rb_ary_entry(object, 1)));
|
64
|
+
}
|
65
|
+
}
|
66
|
+
rb_raise(rb_eTypeError, "Invalid type");
|
67
|
+
}
|
68
|
+
|
69
|
+
__NAMESPACE_END_OPENCV
|
70
|
+
|
71
|
+
#endif // RUBY_OPENCV_CVTERMCRITERIA_H
|
@@ -0,0 +1,116 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvtwopoints.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvtwopoints.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvTwopoints
|
13
|
+
*
|
14
|
+
* This class means one twopoints on X axis Y axis.
|
15
|
+
* X and Y takes the value of the Fixnum. see also CvTwopoints2D32F
|
16
|
+
*
|
17
|
+
* C structure is here, very simple.
|
18
|
+
* typdef struct CvTwopoints {
|
19
|
+
* int x;
|
20
|
+
* int y;
|
21
|
+
* }
|
22
|
+
*/
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVTWOPOINTS
|
25
|
+
|
26
|
+
VALUE rb_klass;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
rb_class()
|
30
|
+
{
|
31
|
+
return rb_klass;
|
32
|
+
}
|
33
|
+
|
34
|
+
void
|
35
|
+
define_ruby_class()
|
36
|
+
{
|
37
|
+
if (rb_klass)
|
38
|
+
return;
|
39
|
+
/*
|
40
|
+
* opencv = rb_define_module("OpenCV");
|
41
|
+
*
|
42
|
+
* note: this comment is used by rdoc.
|
43
|
+
*/
|
44
|
+
VALUE opencv = rb_module_opencv();
|
45
|
+
|
46
|
+
rb_klass = rb_define_class_under(opencv, "CvTwoPoints", rb_cObject);
|
47
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
48
|
+
rb_define_method(rb_klass, "point1", RUBY_METHOD_FUNC(rb_point1), 0);
|
49
|
+
rb_define_method(rb_klass, "point2", RUBY_METHOD_FUNC(rb_point2), 0);
|
50
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
51
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
52
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE
|
56
|
+
rb_allocate(VALUE klass)
|
57
|
+
{
|
58
|
+
CvTwoPoints *ptr;
|
59
|
+
return Data_Make_Struct(klass, CvTwoPoints, 0, -1, ptr);
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* Return point 1.
|
64
|
+
*/
|
65
|
+
VALUE
|
66
|
+
rb_point1(VALUE self)
|
67
|
+
{
|
68
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p1);
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* Return point2.
|
73
|
+
*/
|
74
|
+
VALUE
|
75
|
+
rb_point2(VALUE self)
|
76
|
+
{
|
77
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
78
|
+
}
|
79
|
+
|
80
|
+
/*
|
81
|
+
* call-seq:
|
82
|
+
* [<i>index</i>]
|
83
|
+
*
|
84
|
+
* Return value of <i>index</i> dimension.
|
85
|
+
*/
|
86
|
+
VALUE
|
87
|
+
rb_aref(VALUE self, VALUE index)
|
88
|
+
{
|
89
|
+
switch (NUM2INT(index)) {
|
90
|
+
case 0:
|
91
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p1);
|
92
|
+
break;
|
93
|
+
case 1:
|
94
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
95
|
+
break;
|
96
|
+
default:
|
97
|
+
rb_raise(rb_eIndexError, "index should be 0...2");
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* to_ary -> [self.point1, self.point2]
|
106
|
+
*
|
107
|
+
* Return 2 point by Array.
|
108
|
+
*/
|
109
|
+
VALUE
|
110
|
+
rb_to_ary(VALUE self)
|
111
|
+
{
|
112
|
+
return rb_ary_new3(2, rb_point1(self), rb_point2(self));
|
113
|
+
}
|
114
|
+
|
115
|
+
__NAMESPACE_END_CVTWOPOINTS
|
116
|
+
__NAMESPACE_END_OPENCV
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvtwopoints.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVTWOPOINTS_H
|
11
|
+
#define RUBY_OPENCV_CVTWOPOINTS_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVTWOPOINTS namespace cCvTwoPoints {
|
16
|
+
#define __NAMESPACE_END_CVTWOPOINTS }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
|
20
|
+
typedef struct CvTwoPoints {
|
21
|
+
CvPoint p1;
|
22
|
+
CvPoint p2;
|
23
|
+
} CvTwoPoints;
|
24
|
+
|
25
|
+
__NAMESPACE_BEGIN_CVTWOPOINTS
|
26
|
+
|
27
|
+
VALUE rb_class();
|
28
|
+
|
29
|
+
void define_ruby_class();
|
30
|
+
|
31
|
+
VALUE rb_allocate(VALUE klass);
|
32
|
+
|
33
|
+
VALUE rb_point1(VALUE self);
|
34
|
+
VALUE rb_point2(VALUE self);
|
35
|
+
VALUE rb_aref(VALUE self, VALUE index);
|
36
|
+
VALUE rb_to_ary(VALUE self);
|
37
|
+
|
38
|
+
VALUE new_object(CvTwoPoints twopoints);
|
39
|
+
|
40
|
+
__NAMESPACE_END_CVTWOPOINTS
|
41
|
+
|
42
|
+
inline CvTwoPoints*
|
43
|
+
CVTWOPOINTS(VALUE object) {
|
44
|
+
CvTwoPoints *ptr;
|
45
|
+
Data_Get_Struct(object, CvTwoPoints, ptr);
|
46
|
+
return ptr;
|
47
|
+
}
|
48
|
+
|
49
|
+
__NAMESPACE_END_OPENCV
|
50
|
+
|
51
|
+
#endif // RUBY_OPENCV_CVTWOPOINTS_H
|
@@ -0,0 +1,192 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvutils.cpp -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2011 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvutils.h"
|
11
|
+
|
12
|
+
void
|
13
|
+
raise_typeerror(VALUE object, VALUE expected_class)
|
14
|
+
{
|
15
|
+
raise_typeerror(object, rb_class2name(expected_class));
|
16
|
+
}
|
17
|
+
|
18
|
+
void
|
19
|
+
raise_typeerror(VALUE object, const char* expected_class_name)
|
20
|
+
{
|
21
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
22
|
+
rb_obj_classname(object), expected_class_name);
|
23
|
+
}
|
24
|
+
|
25
|
+
void
|
26
|
+
raise_compatible_typeerror(VALUE object, VALUE expected_class)
|
27
|
+
{
|
28
|
+
raise_compatible_typeerror(object, rb_class2name(expected_class));
|
29
|
+
}
|
30
|
+
|
31
|
+
void
|
32
|
+
raise_compatible_typeerror(VALUE object, const char* expected_class_name)
|
33
|
+
{
|
34
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s or compatible object)",
|
35
|
+
rb_obj_classname(object), expected_class_name);
|
36
|
+
}
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Allocates a memory buffer
|
40
|
+
* see cv::fastMalloc()
|
41
|
+
*/
|
42
|
+
void*
|
43
|
+
rbFastMalloc(size_t size)
|
44
|
+
{
|
45
|
+
uchar* udata = (uchar*)xmalloc(size + sizeof(void*) + CV_MALLOC_ALIGN);
|
46
|
+
if(!udata) {
|
47
|
+
rb_raise(rb_eNoMemError, "Failed to allocate memory");
|
48
|
+
}
|
49
|
+
uchar** adata = cv::alignPtr((uchar**)udata + 1, CV_MALLOC_ALIGN);
|
50
|
+
adata[-1] = udata;
|
51
|
+
return adata;
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* Allocates a memory buffer
|
56
|
+
* When memory allocation is failed, run GC and retry it
|
57
|
+
*/
|
58
|
+
void*
|
59
|
+
rb_cvAlloc(size_t size)
|
60
|
+
{
|
61
|
+
return rbFastMalloc(size);
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* Creates CvMat and underlying data
|
66
|
+
* When memory allocation is failed, run GC and retry it
|
67
|
+
*/
|
68
|
+
CvMat*
|
69
|
+
rb_cvCreateMat(int rows, int cols, int type)
|
70
|
+
{
|
71
|
+
CvMat* mat = NULL;
|
72
|
+
try {
|
73
|
+
mat = cvCreateMatHeader(rows, cols, type);
|
74
|
+
if (mat) {
|
75
|
+
// see OpenCV's cvCreateData()
|
76
|
+
size_t step = mat->step;
|
77
|
+
size_t total_size = step * mat->rows + sizeof(int) + CV_MALLOC_ALIGN;
|
78
|
+
|
79
|
+
mat->refcount = (int*)rbFastMalloc(total_size);
|
80
|
+
mat->data.ptr = (uchar*)cvAlignPtr(mat->refcount + 1, CV_MALLOC_ALIGN);
|
81
|
+
*mat->refcount = 1;
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
rb_raise(rb_eRuntimeError, "Failed to create mat header");
|
85
|
+
}
|
86
|
+
}
|
87
|
+
catch(cv::Exception& e) {
|
88
|
+
if (mat) {
|
89
|
+
cvReleaseMat(&mat);
|
90
|
+
}
|
91
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
92
|
+
}
|
93
|
+
return mat;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* Create IplImage header and allocate underlying data
|
98
|
+
* When memory allocation is failed, run GC and retry it
|
99
|
+
*/
|
100
|
+
IplImage*
|
101
|
+
rb_cvCreateImage(CvSize size, int depth, int channels)
|
102
|
+
{
|
103
|
+
IplImage* ptr = NULL;
|
104
|
+
try {
|
105
|
+
ptr = cvCreateImageHeader(size, depth, channels);
|
106
|
+
if (ptr) {
|
107
|
+
// see OpenCV's cvCreateData()
|
108
|
+
ptr->imageData = ptr->imageDataOrigin = (char*)rbFastMalloc((size_t)ptr->imageSize);
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
rb_raise(rb_eRuntimeError, "Failed to create image header");
|
112
|
+
}
|
113
|
+
}
|
114
|
+
catch(cv::Exception& e) {
|
115
|
+
if (ptr) {
|
116
|
+
cvReleaseImage(&ptr);
|
117
|
+
}
|
118
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
119
|
+
}
|
120
|
+
return ptr;
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Creates a structuring element
|
125
|
+
* When memory allocation is failed, run GC and retry it
|
126
|
+
*/
|
127
|
+
IplConvKernel*
|
128
|
+
rb_cvCreateStructuringElementEx(int cols, int rows,
|
129
|
+
int anchorX, int anchorY,
|
130
|
+
int shape, int *values)
|
131
|
+
{
|
132
|
+
IplConvKernel* ptr = NULL;
|
133
|
+
try {
|
134
|
+
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
135
|
+
}
|
136
|
+
catch(cv::Exception& e) {
|
137
|
+
if (e.code != CV_StsNoMem)
|
138
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
139
|
+
|
140
|
+
rb_gc_start();
|
141
|
+
try {
|
142
|
+
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
143
|
+
}
|
144
|
+
catch (cv::Exception& e) {
|
145
|
+
if (e.code == CV_StsNoMem)
|
146
|
+
rb_raise(rb_eNoMemError, "%s", e.what());
|
147
|
+
else
|
148
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return ptr;
|
152
|
+
}
|
153
|
+
|
154
|
+
/*
|
155
|
+
* Creates memory storage
|
156
|
+
* When memory allocation is failed, run GC and retry it
|
157
|
+
*/
|
158
|
+
CvMemStorage*
|
159
|
+
rb_cvCreateMemStorage(int block_size)
|
160
|
+
{
|
161
|
+
CvMemStorage* ptr = NULL;
|
162
|
+
try {
|
163
|
+
ptr = cvCreateMemStorage(block_size);
|
164
|
+
}
|
165
|
+
catch(cv::Exception& e) {
|
166
|
+
if (e.code != CV_StsNoMem)
|
167
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
168
|
+
|
169
|
+
rb_gc_start();
|
170
|
+
try {
|
171
|
+
ptr = cvCreateMemStorage(block_size);
|
172
|
+
}
|
173
|
+
catch (cv::Exception& e) {
|
174
|
+
if (e.code == CV_StsNoMem)
|
175
|
+
rb_raise(rb_eNoMemError, "%s", e.what());
|
176
|
+
else
|
177
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
178
|
+
}
|
179
|
+
}
|
180
|
+
return ptr;
|
181
|
+
}
|
182
|
+
|
183
|
+
VALUE
|
184
|
+
rb_get_option_table(VALUE klass, const char* table_name, VALUE option)
|
185
|
+
{
|
186
|
+
VALUE table = rb_const_get(klass, rb_intern(table_name));
|
187
|
+
if (NIL_P(option))
|
188
|
+
return table;
|
189
|
+
else
|
190
|
+
return rb_funcall(table, rb_intern("merge"), 1, option);
|
191
|
+
}
|
192
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvutils.h -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2011 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
|
11
|
+
#include <ruby.h>
|
12
|
+
#include "opencv2/core/core_c.h"
|
13
|
+
#include "opencv2/core/core.hpp"
|
14
|
+
#include "opencv2/core/internal.hpp"
|
15
|
+
#include "opencv2/imgproc/imgproc_c.h"
|
16
|
+
#include "opencv2/imgproc/imgproc.hpp"
|
17
|
+
|
18
|
+
#define raise_cverror(e) cCvError::raise(e)
|
19
|
+
|
20
|
+
void raise_typeerror(VALUE object, VALUE expected_class);
|
21
|
+
void raise_typeerror(VALUE object, const char* expected_class_name);
|
22
|
+
void raise_compatible_typeerror(VALUE object, VALUE expected_class);
|
23
|
+
void raise_compatible_typeerror(VALUE object, const char* expected_class_name);
|
24
|
+
void* rb_cvAlloc(size_t size);
|
25
|
+
CvMat* rb_cvCreateMat(int height, int width, int type);
|
26
|
+
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
|
27
|
+
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
|
28
|
+
CvMemStorage* rb_cvCreateMemStorage(int block_size);
|
29
|
+
VALUE rb_get_option_table(VALUE klass, const char* table_name, VALUE option);
|
30
|
+
|