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.
- checksums.yaml +7 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +1 -1
- data/License.txt +30 -30
- data/Manifest.txt +7 -5
- data/README.md +98 -0
- data/Rakefile +63 -5
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -21
- data/examples/find_obj.rb +169 -169
- data/examples/match_kdtree.rb +88 -88
- data/ext/opencv/cvcapture.cpp +19 -12
- data/ext/opencv/cvutils.cpp +192 -194
- data/ext/opencv/cvutils.h +30 -29
- data/{extconf.rb → ext/opencv/extconf.rb} +12 -4
- data/lib/opencv.rb +12 -3
- data/lib/opencv/psyched_yaml.rb +22 -22
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +44 -43
- data/test/helper.rb +1 -1
- data/test/runner.rb +30 -30
- data/test/test_curve.rb +1 -1
- data/test/test_cvavgcomp.rb +24 -24
- data/test/test_cvbox2d.rb +76 -76
- data/test/test_cvcapture.rb +183 -183
- data/test/test_cvchain.rb +108 -108
- data/test/test_cvcircle32f.rb +41 -41
- data/test/test_cvconnectedcomp.rb +61 -61
- data/test/test_cvcontour.rb +150 -150
- data/test/test_cvcontourtree.rb +43 -43
- data/test/test_cverror.rb +1 -1
- data/test/test_cvfeaturetree.rb +65 -65
- data/test/test_cvfont.rb +58 -58
- data/test/test_cvhaarclassifiercascade.rb +63 -63
- data/test/test_cvhistogram.rb +1 -1
- data/test/test_cvhumoments.rb +83 -83
- data/test/test_cvline.rb +50 -50
- data/test/test_cvmat.rb +1 -1
- data/test/test_cvmat_drawing.rb +1 -1
- data/test/test_cvmat_dxt.rb +1 -1
- data/test/test_cvmat_imageprocessing.rb +1 -1
- data/test/test_cvmat_matching.rb +1 -1
- data/test/test_cvmoments.rb +180 -180
- data/test/test_cvpoint.rb +75 -75
- data/test/test_cvpoint2d32f.rb +75 -75
- data/test/test_cvpoint3d32f.rb +93 -93
- data/test/test_cvrect.rb +144 -144
- data/test/test_cvscalar.rb +113 -113
- data/test/test_cvseq.rb +295 -295
- data/test/test_cvsize.rb +75 -75
- data/test/test_cvsize2d32f.rb +75 -75
- data/test/test_cvslice.rb +31 -31
- data/test/test_cvsurfparams.rb +57 -57
- data/test/test_cvsurfpoint.rb +66 -66
- data/test/test_cvtermcriteria.rb +56 -56
- data/test/test_cvtwopoints.rb +40 -40
- data/test/test_cvvideowriter.rb +58 -58
- data/test/test_iplconvkernel.rb +54 -54
- data/test/test_iplimage.rb +1 -1
- data/test/test_mouseevent.rb +17 -17
- data/test/test_opencv.rb +1 -1
- data/test/test_pointset.rb +1 -1
- data/test/test_preliminary.rb +130 -130
- data/test/test_trackbar.rb +47 -47
- data/test/test_window.rb +115 -115
- metadata +28 -56
- data/README.rdoc +0 -149
- data/ext/opencv/lib/opencv.rb +0 -3
- data/ext/opencv/lib/opencv/psyched_yaml.rb +0 -22
- data/ext/opencv/lib/opencv/version.rb +0 -3
data/ext/opencv/cvcapture.cpp
CHANGED
@@ -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
|
-
|
192
|
-
if (!frame)
|
192
|
+
if (!(frame = cvRetrieveFrame(CVCAPTURE(self)))) {
|
193
193
|
return Qnil;
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
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
|
-
|
219
|
-
if (!frame)
|
223
|
+
if (!(frame = cvQueryFrame(CVCAPTURE(self)))) {
|
220
224
|
return Qnil;
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
-
|
230
|
+
}
|
231
|
+
else {
|
226
232
|
cvFlip(frame, CVARR(image));
|
233
|
+
}
|
227
234
|
}
|
228
235
|
catch (cv::Exception& e) {
|
229
236
|
raise_cverror(e);
|
data/ext/opencv/cvutils.cpp
CHANGED
@@ -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
|
-
*
|
41
|
-
*/
|
42
|
-
void*
|
43
|
-
|
44
|
-
{
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
CvMat*
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
return
|
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 =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
{
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
rb_raise(
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
{
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
rb_raise(
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
return table;
|
191
|
-
|
192
|
-
|
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/
|
15
|
-
#include "opencv2/imgproc/
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
void raise_typeerror(VALUE object,
|
21
|
-
void
|
22
|
-
void raise_compatible_typeerror(VALUE object,
|
23
|
-
void
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
+
|