ruby-opencv 0.0.8.pre-mswin32 → 0.0.9.pre2-mswin32

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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/DEVELOPERS_NOTE.md +137 -0
  3. data/Gemfile +1 -1
  4. data/License.txt +30 -30
  5. data/Manifest.txt +7 -5
  6. data/README.md +98 -0
  7. data/Rakefile +63 -5
  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 +44 -43
  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 +28 -56
  67. data/README.rdoc +0 -149
  68. data/ext/opencv/lib/opencv.rb +0 -3
  69. data/ext/opencv/lib/opencv/psyched_yaml.rb +0 -22
  70. data/ext/opencv/lib/opencv/version.rb +0 -3
@@ -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
+
data/ext/opencv/cvutils.h CHANGED
@@ -1,29 +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/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
-
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
+