ruby-opencv 0.0.8-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/.gitignore +25 -0
  2. data/DEVELOPERS_NOTE.md +120 -0
  3. data/Gemfile +9 -0
  4. data/History.txt +5 -0
  5. data/License.txt +30 -0
  6. data/Manifest.txt +226 -0
  7. data/README.md +98 -0
  8. data/Rakefile +32 -0
  9. data/examples/alpha_blend.rb +21 -0
  10. data/examples/box.png +0 -0
  11. data/examples/box_in_scene.png +0 -0
  12. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  13. data/examples/contours/bitmap-contours.png +0 -0
  14. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  15. data/examples/contours/contour_retrieval_modes.rb +139 -0
  16. data/examples/contours/rotated-boxes.jpg +0 -0
  17. data/examples/convexhull.rb +47 -0
  18. data/examples/face_detect.rb +20 -0
  19. data/examples/find_obj.rb +169 -0
  20. data/examples/houghcircle.rb +22 -0
  21. data/examples/inpaint.png +0 -0
  22. data/examples/inpaint.rb +57 -0
  23. data/examples/lenna-rotated.jpg +0 -0
  24. data/examples/lenna.jpg +0 -0
  25. data/examples/match_kdtree.rb +88 -0
  26. data/examples/matching_to_many_images.rb +16 -0
  27. data/examples/matching_to_many_images/query.png +0 -0
  28. data/examples/matching_to_many_images/train/1.png +0 -0
  29. data/examples/matching_to_many_images/train/2.png +0 -0
  30. data/examples/matching_to_many_images/train/3.png +0 -0
  31. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  32. data/examples/paint.rb +70 -0
  33. data/examples/snake.rb +43 -0
  34. data/examples/stuff.jpg +0 -0
  35. data/examples/tiffany.jpg +0 -0
  36. data/ext/opencv/curve.cpp +112 -0
  37. data/ext/opencv/curve.h +34 -0
  38. data/ext/opencv/cvavgcomp.cpp +67 -0
  39. data/ext/opencv/cvavgcomp.h +39 -0
  40. data/ext/opencv/cvbox2d.cpp +197 -0
  41. data/ext/opencv/cvbox2d.h +61 -0
  42. data/ext/opencv/cvcapture.cpp +499 -0
  43. data/ext/opencv/cvcapture.h +72 -0
  44. data/ext/opencv/cvchain.cpp +233 -0
  45. data/ext/opencv/cvchain.h +46 -0
  46. data/ext/opencv/cvcircle32f.cpp +116 -0
  47. data/ext/opencv/cvcircle32f.h +52 -0
  48. data/ext/opencv/cvcondensation.cpp +282 -0
  49. data/ext/opencv/cvcondensation.h +49 -0
  50. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  51. data/ext/opencv/cvconnectedcomp.h +49 -0
  52. data/ext/opencv/cvcontour.cpp +296 -0
  53. data/ext/opencv/cvcontour.h +48 -0
  54. data/ext/opencv/cvcontourtree.cpp +91 -0
  55. data/ext/opencv/cvcontourtree.h +41 -0
  56. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  57. data/ext/opencv/cvconvexitydefect.h +42 -0
  58. data/ext/opencv/cverror.cpp +159 -0
  59. data/ext/opencv/cverror.h +28 -0
  60. data/ext/opencv/cvfeaturetree.cpp +125 -0
  61. data/ext/opencv/cvfeaturetree.h +55 -0
  62. data/ext/opencv/cvfont.cpp +208 -0
  63. data/ext/opencv/cvfont.h +64 -0
  64. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  65. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  66. data/ext/opencv/cvhistogram.cpp +546 -0
  67. data/ext/opencv/cvhistogram.h +73 -0
  68. data/ext/opencv/cvhumoments.cpp +139 -0
  69. data/ext/opencv/cvhumoments.h +51 -0
  70. data/ext/opencv/cvline.cpp +154 -0
  71. data/ext/opencv/cvline.h +54 -0
  72. data/ext/opencv/cvmat.cpp +5848 -0
  73. data/ext/opencv/cvmat.h +284 -0
  74. data/ext/opencv/cvmatnd.cpp +44 -0
  75. data/ext/opencv/cvmatnd.h +28 -0
  76. data/ext/opencv/cvmemstorage.cpp +68 -0
  77. data/ext/opencv/cvmemstorage.h +53 -0
  78. data/ext/opencv/cvmoments.cpp +287 -0
  79. data/ext/opencv/cvmoments.h +75 -0
  80. data/ext/opencv/cvpoint.cpp +228 -0
  81. data/ext/opencv/cvpoint.h +64 -0
  82. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  83. data/ext/opencv/cvpoint2d32f.h +63 -0
  84. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  85. data/ext/opencv/cvpoint3d32f.h +66 -0
  86. data/ext/opencv/cvrect.cpp +333 -0
  87. data/ext/opencv/cvrect.h +79 -0
  88. data/ext/opencv/cvscalar.cpp +236 -0
  89. data/ext/opencv/cvscalar.h +71 -0
  90. data/ext/opencv/cvseq.cpp +599 -0
  91. data/ext/opencv/cvseq.h +74 -0
  92. data/ext/opencv/cvsize.cpp +221 -0
  93. data/ext/opencv/cvsize.h +65 -0
  94. data/ext/opencv/cvsize2d32f.cpp +209 -0
  95. data/ext/opencv/cvsize2d32f.h +64 -0
  96. data/ext/opencv/cvslice.cpp +120 -0
  97. data/ext/opencv/cvslice.h +61 -0
  98. data/ext/opencv/cvsparsemat.cpp +44 -0
  99. data/ext/opencv/cvsparsemat.h +28 -0
  100. data/ext/opencv/cvsurfparams.cpp +199 -0
  101. data/ext/opencv/cvsurfparams.h +58 -0
  102. data/ext/opencv/cvsurfpoint.cpp +223 -0
  103. data/ext/opencv/cvsurfpoint.h +52 -0
  104. data/ext/opencv/cvtermcriteria.cpp +192 -0
  105. data/ext/opencv/cvtermcriteria.h +71 -0
  106. data/ext/opencv/cvtwopoints.cpp +116 -0
  107. data/ext/opencv/cvtwopoints.h +51 -0
  108. data/ext/opencv/cvutils.cpp +194 -0
  109. data/ext/opencv/cvutils.h +29 -0
  110. data/ext/opencv/cvvideowriter.cpp +137 -0
  111. data/ext/opencv/cvvideowriter.h +43 -0
  112. data/ext/opencv/gui.cpp +68 -0
  113. data/ext/opencv/gui.h +30 -0
  114. data/ext/opencv/iplconvkernel.cpp +192 -0
  115. data/ext/opencv/iplconvkernel.h +71 -0
  116. data/ext/opencv/iplimage.cpp +644 -0
  117. data/ext/opencv/iplimage.h +73 -0
  118. data/ext/opencv/lib/opencv.rb +3 -0
  119. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  120. data/ext/opencv/lib/opencv/version.rb +3 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +722 -0
  124. data/ext/opencv/opencv.h +400 -0
  125. data/ext/opencv/pointset.cpp +274 -0
  126. data/ext/opencv/pointset.h +68 -0
  127. data/ext/opencv/trackbar.cpp +121 -0
  128. data/ext/opencv/trackbar.h +69 -0
  129. data/ext/opencv/window.cpp +357 -0
  130. data/ext/opencv/window.h +66 -0
  131. data/extconf.rb +75 -0
  132. data/images/CvMat_sobel.png +0 -0
  133. data/images/CvMat_sub_rect.png +0 -0
  134. data/images/CvSeq_relationmap.png +0 -0
  135. data/images/face_detect_from_lena.jpg +0 -0
  136. data/lib/opencv.rb +3 -0
  137. data/lib/opencv/psyched_yaml.rb +22 -0
  138. data/lib/opencv/version.rb +3 -0
  139. data/ruby-opencv.gemspec +43 -0
  140. data/test/helper.rb +166 -0
  141. data/test/runner.rb +30 -0
  142. data/test/samples/airplane.jpg +0 -0
  143. data/test/samples/baboon.jpg +0 -0
  144. data/test/samples/baboon200.jpg +0 -0
  145. data/test/samples/baboon200_rotated.jpg +0 -0
  146. data/test/samples/blank0.jpg +0 -0
  147. data/test/samples/blank1.jpg +0 -0
  148. data/test/samples/blank2.jpg +0 -0
  149. data/test/samples/blank3.jpg +0 -0
  150. data/test/samples/blank4.jpg +0 -0
  151. data/test/samples/blank5.jpg +0 -0
  152. data/test/samples/blank6.jpg +0 -0
  153. data/test/samples/blank7.jpg +0 -0
  154. data/test/samples/blank8.jpg +0 -0
  155. data/test/samples/blank9.jpg +0 -0
  156. data/test/samples/cat.jpg +0 -0
  157. data/test/samples/chessboard.jpg +0 -0
  158. data/test/samples/contours.jpg +0 -0
  159. data/test/samples/fruits.jpg +0 -0
  160. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  161. data/test/samples/inpaint-mask.bmp +0 -0
  162. data/test/samples/lena-256x256.jpg +0 -0
  163. data/test/samples/lena-32x32.jpg +0 -0
  164. data/test/samples/lena-eyes.jpg +0 -0
  165. data/test/samples/lena-inpaint.jpg +0 -0
  166. data/test/samples/lena.jpg +0 -0
  167. data/test/samples/lines.jpg +0 -0
  168. data/test/samples/messy0.jpg +0 -0
  169. data/test/samples/messy1.jpg +0 -0
  170. data/test/samples/movie_sample.avi +0 -0
  171. data/test/samples/one_way_train_0000.jpg +0 -0
  172. data/test/samples/one_way_train_0001.jpg +0 -0
  173. data/test/samples/partially_blank0.jpg +0 -0
  174. data/test/samples/partially_blank1.jpg +0 -0
  175. data/test/samples/smooth0.jpg +0 -0
  176. data/test/samples/smooth1.jpg +0 -0
  177. data/test/samples/smooth2.jpg +0 -0
  178. data/test/samples/smooth3.jpg +0 -0
  179. data/test/samples/smooth4.jpg +0 -0
  180. data/test/samples/smooth5.jpg +0 -0
  181. data/test/samples/smooth6.jpg +0 -0
  182. data/test/samples/str-cv-rotated.jpg +0 -0
  183. data/test/samples/str-cv.jpg +0 -0
  184. data/test/samples/str-ov.jpg +0 -0
  185. data/test/samples/stuff.jpg +0 -0
  186. data/test/test_curve.rb +43 -0
  187. data/test/test_cvavgcomp.rb +24 -0
  188. data/test/test_cvbox2d.rb +76 -0
  189. data/test/test_cvcapture.rb +183 -0
  190. data/test/test_cvchain.rb +108 -0
  191. data/test/test_cvcircle32f.rb +41 -0
  192. data/test/test_cvconnectedcomp.rb +61 -0
  193. data/test/test_cvcontour.rb +150 -0
  194. data/test/test_cvcontourtree.rb +43 -0
  195. data/test/test_cverror.rb +50 -0
  196. data/test/test_cvfeaturetree.rb +65 -0
  197. data/test/test_cvfont.rb +58 -0
  198. data/test/test_cvhaarclassifiercascade.rb +63 -0
  199. data/test/test_cvhistogram.rb +271 -0
  200. data/test/test_cvhumoments.rb +83 -0
  201. data/test/test_cvline.rb +50 -0
  202. data/test/test_cvmat.rb +2947 -0
  203. data/test/test_cvmat_drawing.rb +349 -0
  204. data/test/test_cvmat_dxt.rb +150 -0
  205. data/test/test_cvmat_imageprocessing.rb +2025 -0
  206. data/test/test_cvmat_matching.rb +57 -0
  207. data/test/test_cvmoments.rb +180 -0
  208. data/test/test_cvpoint.rb +75 -0
  209. data/test/test_cvpoint2d32f.rb +75 -0
  210. data/test/test_cvpoint3d32f.rb +93 -0
  211. data/test/test_cvrect.rb +144 -0
  212. data/test/test_cvscalar.rb +113 -0
  213. data/test/test_cvseq.rb +295 -0
  214. data/test/test_cvsize.rb +75 -0
  215. data/test/test_cvsize2d32f.rb +75 -0
  216. data/test/test_cvslice.rb +31 -0
  217. data/test/test_cvsurfparams.rb +57 -0
  218. data/test/test_cvsurfpoint.rb +66 -0
  219. data/test/test_cvtermcriteria.rb +56 -0
  220. data/test/test_cvtwopoints.rb +40 -0
  221. data/test/test_cvvideowriter.rb +58 -0
  222. data/test/test_iplconvkernel.rb +54 -0
  223. data/test/test_iplimage.rb +236 -0
  224. data/test/test_mouseevent.rb +17 -0
  225. data/test/test_opencv.rb +324 -0
  226. data/test/test_pointset.rb +126 -0
  227. data/test/test_preliminary.rb +130 -0
  228. data/test/test_trackbar.rb +47 -0
  229. data/test/test_window.rb +115 -0
  230. metadata +414 -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,194 @@
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
+ * When memory allocation is failed, run GC and retry it
41
+ */
42
+ void*
43
+ rb_cvAlloc(size_t size)
44
+ {
45
+ void* ptr = NULL;
46
+ try {
47
+ ptr = cvAlloc(size);
48
+ }
49
+ catch(cv::Exception& e) {
50
+ if (e.code != CV_StsNoMem)
51
+ rb_raise(rb_eRuntimeError, "%s", e.what());
52
+
53
+ rb_gc_start();
54
+ try {
55
+ ptr = cvAlloc(size);
56
+ }
57
+ catch (cv::Exception& e) {
58
+ if (e.code == CV_StsNoMem)
59
+ rb_raise(rb_eNoMemError, "%s", e.what());
60
+ else
61
+ rb_raise(rb_eRuntimeError, "%s", e.what());
62
+ }
63
+ }
64
+ return ptr;
65
+ }
66
+
67
+ /*
68
+ * Creates CvMat and underlying data
69
+ * When memory allocation is failed, run GC and retry it
70
+ */
71
+ CvMat*
72
+ rb_cvCreateMat(int height, int width, int type)
73
+ {
74
+ CvMat* ptr = NULL;
75
+ try {
76
+ ptr = cvCreateMat(height, width, type);
77
+ }
78
+ catch(cv::Exception& e) {
79
+ if (e.code != CV_StsNoMem)
80
+ rb_raise(rb_eRuntimeError, "%s", e.what());
81
+
82
+ rb_gc_start();
83
+ try {
84
+ ptr = cvCreateMat(height, width, type);
85
+ }
86
+ catch (cv::Exception& e) {
87
+ if (e.code == CV_StsNoMem)
88
+ rb_raise(rb_eNoMemError, "%s", e.what());
89
+ else
90
+ rb_raise(rb_eRuntimeError, "%s", e.what());
91
+ }
92
+ }
93
+ return ptr;
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 = cvCreateImage(size, depth, channels);
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 = cvCreateImage(size, depth, channels);
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
+ * Creates a structuring element
127
+ * When memory allocation is failed, run GC and retry it
128
+ */
129
+ IplConvKernel*
130
+ rb_cvCreateStructuringElementEx(int cols, int rows,
131
+ int anchorX, int anchorY,
132
+ int shape, int *values)
133
+ {
134
+ IplConvKernel* ptr = NULL;
135
+ try {
136
+ ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
137
+ }
138
+ catch(cv::Exception& e) {
139
+ if (e.code != CV_StsNoMem)
140
+ rb_raise(rb_eRuntimeError, "%s", e.what());
141
+
142
+ rb_gc_start();
143
+ try {
144
+ ptr = cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
145
+ }
146
+ catch (cv::Exception& e) {
147
+ if (e.code == CV_StsNoMem)
148
+ rb_raise(rb_eNoMemError, "%s", e.what());
149
+ else
150
+ rb_raise(rb_eRuntimeError, "%s", e.what());
151
+ }
152
+ }
153
+ return ptr;
154
+ }
155
+
156
+ /*
157
+ * Creates memory storage
158
+ * When memory allocation is failed, run GC and retry it
159
+ */
160
+ CvMemStorage*
161
+ rb_cvCreateMemStorage(int block_size)
162
+ {
163
+ CvMemStorage* ptr = NULL;
164
+ try {
165
+ ptr = cvCreateMemStorage(block_size);
166
+ }
167
+ catch(cv::Exception& e) {
168
+ if (e.code != CV_StsNoMem)
169
+ rb_raise(rb_eRuntimeError, "%s", e.what());
170
+
171
+ rb_gc_start();
172
+ try {
173
+ ptr = cvCreateMemStorage(block_size);
174
+ }
175
+ catch (cv::Exception& e) {
176
+ if (e.code == CV_StsNoMem)
177
+ rb_raise(rb_eNoMemError, "%s", e.what());
178
+ else
179
+ rb_raise(rb_eRuntimeError, "%s", e.what());
180
+ }
181
+ }
182
+ return ptr;
183
+ }
184
+
185
+ VALUE
186
+ rb_get_option_table(VALUE klass, const char* table_name, VALUE option)
187
+ {
188
+ VALUE table = rb_const_get(klass, rb_intern(table_name));
189
+ if (NIL_P(option))
190
+ return table;
191
+ else
192
+ return rb_funcall(table, rb_intern("merge"), 1, option);
193
+ }
194
+
@@ -0,0 +1,29 @@
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/imgproc/imgproc_c.h"
15
+ #include "opencv2/imgproc/imgproc.hpp"
16
+
17
+ #define raise_cverror(e) cCvError::raise(e)
18
+
19
+ void raise_typeerror(VALUE object, VALUE expected_class);
20
+ void raise_typeerror(VALUE object, const char* expected_class_name);
21
+ void raise_compatible_typeerror(VALUE object, VALUE expected_class);
22
+ void raise_compatible_typeerror(VALUE object, const char* expected_class_name);
23
+ void* rb_cvAlloc(size_t size);
24
+ CvMat* rb_cvCreateMat(int height, int width, int type);
25
+ IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
26
+ IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
27
+ CvMemStorage* rb_cvCreateMemStorage(int block_size);
28
+ VALUE rb_get_option_table(VALUE klass, const char* table_name, VALUE option);
29
+