ruby-opencv 0.0.8-x86-mingw32 → 0.0.9.pre2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/DEVELOPERS_NOTE.md +29 -12
  3. data/Gemfile +1 -2
  4. data/License.txt +30 -30
  5. data/Manifest.txt +5 -4
  6. data/README.md +1 -1
  7. data/Rakefile +62 -4
  8. data/config.yml +7 -0
  9. data/examples/alpha_blend.rb +21 -21
  10. data/examples/find_obj.rb +169 -169
  11. data/examples/match_kdtree.rb +88 -88
  12. data/ext/opencv/cvcapture.cpp +19 -12
  13. data/ext/opencv/cvutils.cpp +192 -194
  14. data/ext/opencv/cvutils.h +30 -29
  15. data/{extconf.rb → ext/opencv/extconf.rb} +12 -4
  16. data/lib/opencv.rb +12 -3
  17. data/lib/opencv/psyched_yaml.rb +22 -22
  18. data/lib/opencv/version.rb +1 -1
  19. data/ruby-opencv.gemspec +17 -16
  20. data/test/helper.rb +1 -1
  21. data/test/runner.rb +30 -30
  22. data/test/test_curve.rb +1 -1
  23. data/test/test_cvavgcomp.rb +24 -24
  24. data/test/test_cvbox2d.rb +76 -76
  25. data/test/test_cvcapture.rb +183 -183
  26. data/test/test_cvchain.rb +108 -108
  27. data/test/test_cvcircle32f.rb +41 -41
  28. data/test/test_cvconnectedcomp.rb +61 -61
  29. data/test/test_cvcontour.rb +150 -150
  30. data/test/test_cvcontourtree.rb +43 -43
  31. data/test/test_cverror.rb +1 -1
  32. data/test/test_cvfeaturetree.rb +65 -65
  33. data/test/test_cvfont.rb +58 -58
  34. data/test/test_cvhaarclassifiercascade.rb +63 -63
  35. data/test/test_cvhistogram.rb +1 -1
  36. data/test/test_cvhumoments.rb +83 -83
  37. data/test/test_cvline.rb +50 -50
  38. data/test/test_cvmat.rb +1 -1
  39. data/test/test_cvmat_drawing.rb +1 -1
  40. data/test/test_cvmat_dxt.rb +1 -1
  41. data/test/test_cvmat_imageprocessing.rb +1 -1
  42. data/test/test_cvmat_matching.rb +1 -1
  43. data/test/test_cvmoments.rb +180 -180
  44. data/test/test_cvpoint.rb +75 -75
  45. data/test/test_cvpoint2d32f.rb +75 -75
  46. data/test/test_cvpoint3d32f.rb +93 -93
  47. data/test/test_cvrect.rb +144 -144
  48. data/test/test_cvscalar.rb +113 -113
  49. data/test/test_cvseq.rb +295 -295
  50. data/test/test_cvsize.rb +75 -75
  51. data/test/test_cvsize2d32f.rb +75 -75
  52. data/test/test_cvslice.rb +31 -31
  53. data/test/test_cvsurfparams.rb +57 -57
  54. data/test/test_cvsurfpoint.rb +66 -66
  55. data/test/test_cvtermcriteria.rb +56 -56
  56. data/test/test_cvtwopoints.rb +40 -40
  57. data/test/test_cvvideowriter.rb +58 -58
  58. data/test/test_iplconvkernel.rb +54 -54
  59. data/test/test_iplimage.rb +1 -1
  60. data/test/test_mouseevent.rb +17 -17
  61. data/test/test_opencv.rb +1 -1
  62. data/test/test_pointset.rb +1 -1
  63. data/test/test_preliminary.rb +130 -130
  64. data/test/test_trackbar.rb +47 -47
  65. data/test/test_window.rb +115 -115
  66. metadata +26 -54
  67. data/ext/opencv/lib/opencv.rb +0 -3
  68. data/ext/opencv/lib/opencv/psyched_yaml.rb +0 -22
  69. data/ext/opencv/lib/opencv/version.rb +0 -3
@@ -1,88 +1,88 @@
1
- #!/usr/bin/env ruby
2
- # -*- mode: ruby; coding: utf-8-unix -*-
3
-
4
- # A sample of matching SURF feature points using kd-tree
5
- # See http://tech.groups.yahoo.com/group/OpenCV/message/62318
6
-
7
- require 'opencv'
8
- include OpenCV
9
-
10
- USE_EXTENDED_DESCRIPTOR = true
11
- THRESHOLD = 1500
12
- DESCRIPTOR_SIZE = USE_EXTENDED_DESCRIPTOR ? 128 : 64
13
-
14
- img1 = CvMat.load('lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
15
- img2 = CvMat.load('lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
16
-
17
- puts 'Extracting features from img1 using SURF...'
18
- param = CvSURFParams.new(THRESHOLD, USE_EXTENDED_DESCRIPTOR)
19
- kp1, desc1 = img1.extract_surf(param)
20
- puts "found #{kp1.size} keypoints from img1"
21
-
22
- puts 'Extracting features from img2 using SURF...'
23
- kp2, desc2 = img2.extract_surf(param)
24
- puts "found #{kp2.size} keypoints from img2"
25
-
26
- puts 'Matching keypoints...'
27
- desc1mat = CvMat.new(kp1.size, DESCRIPTOR_SIZE, :cv32f, 1)
28
- desc2mat = CvMat.new(kp2.size, DESCRIPTOR_SIZE, :cv32f, 1)
29
- desc1.each_with_index { |desc, i|
30
- desc.each_with_index { |d, j|
31
- desc1mat[i, j] = CvScalar.new(d)
32
- }
33
- }
34
- desc2.each_with_index { |desc, i|
35
- desc.each_with_index { |d, j|
36
- desc2mat[i, j] = CvScalar.new(d)
37
- }
38
- }
39
-
40
- feature_tree = CvFeatureTree.new(desc1mat)
41
- results, distances = feature_tree.find_features(desc2mat, 1, 250)
42
-
43
- reverse_lookup = []
44
- reverse_lookup_dist = []
45
- kp1.size.times { |i|
46
- reverse_lookup << -1
47
- reverse_lookup_dist << Float::MAX
48
- }
49
-
50
- match_count = 0
51
- kp2.size.times { |j|
52
- i = results[j][0].to_i
53
- d = distances[j][0]
54
- if (d < reverse_lookup_dist[i])
55
- match_count += 1 if reverse_lookup_dist[i] == Float::MAX
56
- reverse_lookup[i] = j
57
- reverse_lookup_dist[i] = d
58
- end
59
- }
60
- puts "found #{match_count} putative correspondences"
61
-
62
- points1 = []
63
- points2 = []
64
- kp2.size.times { |j|
65
- i = results[j][0].to_i
66
- if (j == reverse_lookup[i])
67
- points1 << kp1[i].pt
68
- points2 << kp2[j].pt
69
- end
70
- }
71
-
72
- width = img1.cols + img2.cols
73
- height = (img1.rows > img2.rows) ? img1.rows : img2.rows
74
- correspond = IplImage.new(width, height, :cv8u, 1);
75
- correspond.set_roi(CvRect.new(0, 0, img1.cols, img1.rows))
76
- img1.copy(correspond)
77
- correspond.set_roi(CvRect.new(img1.cols, 0, img1.cols + img2.cols, img2.rows))
78
- img2.copy(correspond)
79
- correspond.reset_roi
80
-
81
- points1.zip(points2) { |pt1, pt2|
82
- pt2.x += img1.cols
83
- correspond.line!(pt1, pt2, :color => CvColor::White)
84
- }
85
-
86
- GUI::Window.new('Object Correspond').show correspond
87
- GUI::wait_key
88
-
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby; coding: utf-8 -*-
3
+
4
+ # A sample of matching SURF feature points using kd-tree
5
+ # See http://tech.groups.yahoo.com/group/OpenCV/message/62318
6
+
7
+ require 'opencv'
8
+ include OpenCV
9
+
10
+ USE_EXTENDED_DESCRIPTOR = true
11
+ THRESHOLD = 1500
12
+ DESCRIPTOR_SIZE = USE_EXTENDED_DESCRIPTOR ? 128 : 64
13
+
14
+ img1 = CvMat.load('lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
15
+ img2 = CvMat.load('lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
16
+
17
+ puts 'Extracting features from img1 using SURF...'
18
+ param = CvSURFParams.new(THRESHOLD, USE_EXTENDED_DESCRIPTOR)
19
+ kp1, desc1 = img1.extract_surf(param)
20
+ puts "found #{kp1.size} keypoints from img1"
21
+
22
+ puts 'Extracting features from img2 using SURF...'
23
+ kp2, desc2 = img2.extract_surf(param)
24
+ puts "found #{kp2.size} keypoints from img2"
25
+
26
+ puts 'Matching keypoints...'
27
+ desc1mat = CvMat.new(kp1.size, DESCRIPTOR_SIZE, :cv32f, 1)
28
+ desc2mat = CvMat.new(kp2.size, DESCRIPTOR_SIZE, :cv32f, 1)
29
+ desc1.each_with_index { |desc, i|
30
+ desc.each_with_index { |d, j|
31
+ desc1mat[i, j] = CvScalar.new(d)
32
+ }
33
+ }
34
+ desc2.each_with_index { |desc, i|
35
+ desc.each_with_index { |d, j|
36
+ desc2mat[i, j] = CvScalar.new(d)
37
+ }
38
+ }
39
+
40
+ feature_tree = CvFeatureTree.new(desc1mat)
41
+ results, distances = feature_tree.find_features(desc2mat, 1, 250)
42
+
43
+ reverse_lookup = []
44
+ reverse_lookup_dist = []
45
+ kp1.size.times { |i|
46
+ reverse_lookup << -1
47
+ reverse_lookup_dist << Float::MAX
48
+ }
49
+
50
+ match_count = 0
51
+ kp2.size.times { |j|
52
+ i = results[j][0].to_i
53
+ d = distances[j][0]
54
+ if (d < reverse_lookup_dist[i])
55
+ match_count += 1 if reverse_lookup_dist[i] == Float::MAX
56
+ reverse_lookup[i] = j
57
+ reverse_lookup_dist[i] = d
58
+ end
59
+ }
60
+ puts "found #{match_count} putative correspondences"
61
+
62
+ points1 = []
63
+ points2 = []
64
+ kp2.size.times { |j|
65
+ i = results[j][0].to_i
66
+ if (j == reverse_lookup[i])
67
+ points1 << kp1[i].pt
68
+ points2 << kp2[j].pt
69
+ end
70
+ }
71
+
72
+ width = img1.cols + img2.cols
73
+ height = (img1.rows > img2.rows) ? img1.rows : img2.rows
74
+ correspond = IplImage.new(width, height, :cv8u, 1);
75
+ correspond.set_roi(CvRect.new(0, 0, img1.cols, img1.rows))
76
+ img1.copy(correspond)
77
+ correspond.set_roi(CvRect.new(img1.cols, 0, img1.cols + img2.cols, img2.rows))
78
+ img2.copy(correspond)
79
+ correspond.reset_roi
80
+
81
+ points1.zip(points2) { |pt1, pt2|
82
+ pt2.x += img1.cols
83
+ correspond.line!(pt1, pt2, :color => CvColor::White)
84
+ }
85
+
86
+ GUI::Window.new('Object Correspond').show correspond
87
+ GUI::wait_key
88
+
@@ -187,21 +187,25 @@ VALUE
187
187
  rb_retrieve(VALUE self)
188
188
  {
189
189
  VALUE image = Qnil;
190
+ IplImage *frame = NULL;
190
191
  try {
191
- IplImage *frame = cvRetrieveFrame(CVCAPTURE(self));
192
- if (!frame)
192
+ if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
193
193
  return Qnil;
194
- image = cIplImage::new_object(cvSize(frame->width, frame->height),
195
- CV_MAKETYPE(CV_8U, frame->nChannels));
196
- if (frame->origin == IPL_ORIGIN_TL)
194
+ }
195
+ image = cIplImage::new_object(frame->width, frame->height,
196
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
197
+ if (frame->origin == IPL_ORIGIN_TL) {
197
198
  cvCopy(frame, CVARR(image));
198
- else
199
+ }
200
+ else {
199
201
  cvFlip(frame, CVARR(image));
202
+ }
200
203
  }
201
204
  catch (cv::Exception& e) {
202
205
  raise_cverror(e);
203
206
  }
204
207
  return image;
208
+
205
209
  }
206
210
 
207
211
  /*
@@ -214,16 +218,19 @@ VALUE
214
218
  rb_query(VALUE self)
215
219
  {
216
220
  VALUE image = Qnil;
221
+ IplImage *frame = NULL;
217
222
  try {
218
- IplImage *frame = cvQueryFrame(CVCAPTURE(self));
219
- if (!frame)
223
+ if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
220
224
  return Qnil;
221
- image = cIplImage::new_object(cvSize(frame->width, frame->height),
222
- CV_MAKETYPE(CV_8U, frame->nChannels));
223
- if (frame->origin == IPL_ORIGIN_TL)
225
+ }
226
+ image = cIplImage::new_object(frame->width, frame->height,
227
+ CV_MAKETYPE(IPL2CV_DEPTH(frame->depth), frame->nChannels));
228
+ if (frame->origin == IPL_ORIGIN_TL) {
224
229
  cvCopy(frame, CVARR(image));
225
- else
230
+ }
231
+ else {
226
232
  cvFlip(frame, CVARR(image));
233
+ }
227
234
  }
228
235
  catch (cv::Exception& e) {
229
236
  raise_cverror(e);
@@ -1,194 +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
- * 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
-
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
+