bonanza-ruby-opencv 0.0.13.20140330211753
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -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/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -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 +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -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/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -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 +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -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_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -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 init_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,122 @@
|
|
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
|
+
VALUE
|
35
|
+
rb_allocate(VALUE klass)
|
36
|
+
{
|
37
|
+
CvTwoPoints *ptr;
|
38
|
+
return Data_Make_Struct(klass, CvTwoPoints, 0, -1, ptr);
|
39
|
+
}
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Return point 1.
|
43
|
+
*/
|
44
|
+
VALUE
|
45
|
+
rb_point1(VALUE self)
|
46
|
+
{
|
47
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p1);
|
48
|
+
}
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Return point2.
|
52
|
+
*/
|
53
|
+
VALUE
|
54
|
+
rb_point2(VALUE self)
|
55
|
+
{
|
56
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* call-seq:
|
61
|
+
* [<i>index</i>]
|
62
|
+
*
|
63
|
+
* Return value of <i>index</i> dimension.
|
64
|
+
*/
|
65
|
+
VALUE
|
66
|
+
rb_aref(VALUE self, VALUE index)
|
67
|
+
{
|
68
|
+
switch (NUM2INT(index)) {
|
69
|
+
case 0:
|
70
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p1);
|
71
|
+
break;
|
72
|
+
case 1:
|
73
|
+
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
74
|
+
break;
|
75
|
+
default:
|
76
|
+
rb_raise(rb_eIndexError, "index should be 0...2");
|
77
|
+
break;
|
78
|
+
}
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
|
82
|
+
/*
|
83
|
+
* call-seq:
|
84
|
+
* to_ary -> [self.point1, self.point2]
|
85
|
+
*
|
86
|
+
* Return 2 point by Array.
|
87
|
+
*/
|
88
|
+
VALUE
|
89
|
+
rb_to_ary(VALUE self)
|
90
|
+
{
|
91
|
+
return rb_ary_new3(2, rb_point1(self), rb_point2(self));
|
92
|
+
}
|
93
|
+
|
94
|
+
void
|
95
|
+
init_ruby_class()
|
96
|
+
{
|
97
|
+
#if 0
|
98
|
+
// For documentation using YARD
|
99
|
+
VALUE opencv = rb_define_module("OpenCV");
|
100
|
+
#endif
|
101
|
+
|
102
|
+
if (rb_klass)
|
103
|
+
return;
|
104
|
+
/*
|
105
|
+
* opencv = rb_define_module("OpenCV");
|
106
|
+
*
|
107
|
+
* note: this comment is used by rdoc.
|
108
|
+
*/
|
109
|
+
VALUE opencv = rb_module_opencv();
|
110
|
+
|
111
|
+
rb_klass = rb_define_class_under(opencv, "CvTwoPoints", rb_cObject);
|
112
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
113
|
+
rb_define_method(rb_klass, "point1", RUBY_METHOD_FUNC(rb_point1), 0);
|
114
|
+
rb_define_method(rb_klass, "point2", RUBY_METHOD_FUNC(rb_point2), 0);
|
115
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
116
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
117
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
118
|
+
}
|
119
|
+
|
120
|
+
__NAMESPACE_END_CVTWOPOINTS
|
121
|
+
__NAMESPACE_END_OPENCV
|
122
|
+
|
@@ -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 init_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,221 @@
|
|
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
|
+
* Creates CvMatND and underlying data
|
98
|
+
* When memory allocation is failed, run GC and retry it
|
99
|
+
*/
|
100
|
+
CvMatND*
|
101
|
+
rb_cvCreateMatND(int dims, const int* sizes, int type)
|
102
|
+
{
|
103
|
+
CvMatND* ptr = NULL;
|
104
|
+
try {
|
105
|
+
ptr = cvCreateMatND(dims, sizes, type);
|
106
|
+
}
|
107
|
+
catch(cv::Exception& e) {
|
108
|
+
if (e.code != CV_StsNoMem)
|
109
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
110
|
+
|
111
|
+
rb_gc_start();
|
112
|
+
try {
|
113
|
+
ptr = cvCreateMatND(dims, sizes, type);
|
114
|
+
}
|
115
|
+
catch (cv::Exception& e) {
|
116
|
+
if (e.code == CV_StsNoMem)
|
117
|
+
rb_raise(rb_eNoMemError, "%s", e.what());
|
118
|
+
else
|
119
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
120
|
+
}
|
121
|
+
}
|
122
|
+
return ptr;
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* Create IplImage header and allocate underlying data
|
127
|
+
* When memory allocation is failed, run GC and retry it
|
128
|
+
*/
|
129
|
+
IplImage*
|
130
|
+
rb_cvCreateImage(CvSize size, int depth, int channels)
|
131
|
+
{
|
132
|
+
IplImage* ptr = NULL;
|
133
|
+
try {
|
134
|
+
ptr = cvCreateImageHeader(size, depth, channels);
|
135
|
+
if (ptr) {
|
136
|
+
// see OpenCV's cvCreateData()
|
137
|
+
ptr->imageData = ptr->imageDataOrigin = (char*)rbFastMalloc((size_t)ptr->imageSize);
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
rb_raise(rb_eRuntimeError, "Failed to create image header");
|
141
|
+
}
|
142
|
+
}
|
143
|
+
catch(cv::Exception& e) {
|
144
|
+
if (ptr) {
|
145
|
+
cvReleaseImage(&ptr);
|
146
|
+
}
|
147
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
148
|
+
}
|
149
|
+
return ptr;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Creates a structuring element
|
154
|
+
* When memory allocation is failed, run GC and retry it
|
155
|
+
*/
|
156
|
+
IplConvKernel*
|
157
|
+
rb_cvCreateStructuringElementEx(int cols, int rows,
|
158
|
+
int anchorX, int anchorY,
|
159
|
+
int shape, int *values)
|
160
|
+
{
|
161
|
+
IplConvKernel* ptr = NULL;
|
162
|
+
try {
|
163
|
+
ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
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 = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
|
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
|
+
/*
|
184
|
+
* Creates memory storage
|
185
|
+
* When memory allocation is failed, run GC and retry it
|
186
|
+
*/
|
187
|
+
CvMemStorage*
|
188
|
+
rb_cvCreateMemStorage(int block_size)
|
189
|
+
{
|
190
|
+
CvMemStorage* ptr = NULL;
|
191
|
+
try {
|
192
|
+
ptr = cvCreateMemStorage(block_size);
|
193
|
+
}
|
194
|
+
catch(cv::Exception& e) {
|
195
|
+
if (e.code != CV_StsNoMem)
|
196
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
197
|
+
|
198
|
+
rb_gc_start();
|
199
|
+
try {
|
200
|
+
ptr = cvCreateMemStorage(block_size);
|
201
|
+
}
|
202
|
+
catch (cv::Exception& e) {
|
203
|
+
if (e.code == CV_StsNoMem)
|
204
|
+
rb_raise(rb_eNoMemError, "%s", e.what());
|
205
|
+
else
|
206
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return ptr;
|
210
|
+
}
|
211
|
+
|
212
|
+
VALUE
|
213
|
+
rb_get_option_table(VALUE klass, const char* table_name, VALUE option)
|
214
|
+
{
|
215
|
+
VALUE table = rb_const_get(klass, rb_intern(table_name));
|
216
|
+
if (NIL_P(option))
|
217
|
+
return table;
|
218
|
+
else
|
219
|
+
return rb_funcall(table, rb_intern("merge"), 1, option);
|
220
|
+
}
|
221
|
+
|