opencv 0.0.6
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.
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +115 -0
- data/README.txt +47 -0
- data/Rakefile +34 -0
- data/examples/convexhull.rb +41 -0
- data/examples/face_detect.rb +25 -0
- data/examples/houghcircle.rb +23 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +43 -0
- data/examples/paint.rb +72 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/ext/curve.cpp +103 -0
- data/ext/curve.h +34 -0
- data/ext/cvavgcomp.cpp +67 -0
- data/ext/cvavgcomp.h +39 -0
- data/ext/cvbox2d.cpp +114 -0
- data/ext/cvbox2d.h +53 -0
- data/ext/cvcapture.cpp +276 -0
- data/ext/cvcapture.h +54 -0
- data/ext/cvchain.cpp +184 -0
- data/ext/cvchain.h +43 -0
- data/ext/cvchaincode.cpp +49 -0
- data/ext/cvchaincode.h +43 -0
- data/ext/cvcircle32f.cpp +90 -0
- data/ext/cvcircle32f.h +53 -0
- data/ext/cvcondensation.cpp +230 -0
- data/ext/cvcondensation.h +49 -0
- data/ext/cvconnectedcomp.cpp +115 -0
- data/ext/cvconnectedcomp.h +46 -0
- data/ext/cvcontour.cpp +219 -0
- data/ext/cvcontour.h +47 -0
- data/ext/cvcontourtree.cpp +86 -0
- data/ext/cvcontourtree.h +41 -0
- data/ext/cvconvexitydefect.cpp +103 -0
- data/ext/cvconvexitydefect.h +42 -0
- data/ext/cverror.cpp +140 -0
- data/ext/cverror.h +79 -0
- data/ext/cvfont.cpp +173 -0
- data/ext/cvfont.h +56 -0
- data/ext/cvhaarclassifiercascade.cpp +159 -0
- data/ext/cvhaarclassifiercascade.h +41 -0
- data/ext/cvhistogram.cpp +200 -0
- data/ext/cvhistogram.h +51 -0
- data/ext/cvindex.cpp +73 -0
- data/ext/cvindex.h +40 -0
- data/ext/cvline.cpp +106 -0
- data/ext/cvline.h +52 -0
- data/ext/cvmat.cpp +4809 -0
- data/ext/cvmat.h +286 -0
- data/ext/cvmatnd.cpp +44 -0
- data/ext/cvmatnd.h +28 -0
- data/ext/cvmemstorage.cpp +64 -0
- data/ext/cvmemstorage.h +53 -0
- data/ext/cvmoments.cpp +204 -0
- data/ext/cvmoments.h +48 -0
- data/ext/cvpoint.cpp +229 -0
- data/ext/cvpoint.h +59 -0
- data/ext/cvpoint2d32f.cpp +213 -0
- data/ext/cvpoint2d32f.h +61 -0
- data/ext/cvpoint3d32f.cpp +245 -0
- data/ext/cvpoint3d32f.h +64 -0
- data/ext/cvrect.cpp +340 -0
- data/ext/cvrect.h +79 -0
- data/ext/cvscalar.cpp +227 -0
- data/ext/cvscalar.h +63 -0
- data/ext/cvseq.cpp +583 -0
- data/ext/cvseq.h +71 -0
- data/ext/cvset.cpp +63 -0
- data/ext/cvset.h +39 -0
- data/ext/cvsize.cpp +223 -0
- data/ext/cvsize.h +63 -0
- data/ext/cvsize2d32f.cpp +180 -0
- data/ext/cvsize2d32f.h +59 -0
- data/ext/cvslice.cpp +82 -0
- data/ext/cvslice.h +53 -0
- data/ext/cvsparsemat.cpp +44 -0
- data/ext/cvsparsemat.h +28 -0
- data/ext/cvtermcriteria.cpp +183 -0
- data/ext/cvtermcriteria.h +71 -0
- data/ext/cvtwopoints.cpp +98 -0
- data/ext/cvtwopoints.h +50 -0
- data/ext/cvvector.cpp +206 -0
- data/ext/cvvector.h +54 -0
- data/ext/cvvideowriter.cpp +116 -0
- data/ext/cvvideowriter.h +41 -0
- data/ext/extconf.rb +61 -0
- data/ext/gui.cpp +65 -0
- data/ext/gui.h +33 -0
- data/ext/iplconvkernel.cpp +177 -0
- data/ext/iplconvkernel.h +52 -0
- data/ext/iplimage.cpp +238 -0
- data/ext/iplimage.h +54 -0
- data/ext/mouseevent.cpp +184 -0
- data/ext/mouseevent.h +59 -0
- data/ext/opencv.cpp +481 -0
- data/ext/opencv.h +356 -0
- data/ext/point3dset.cpp +41 -0
- data/ext/point3dset.h +31 -0
- data/ext/pointset.cpp +238 -0
- data/ext/pointset.h +69 -0
- data/ext/trackbar.cpp +122 -0
- data/ext/trackbar.h +65 -0
- data/ext/window.cpp +368 -0
- data/ext/window.h +56 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/opencv.rb +3 -0
- data/lib/version.rb +3 -0
- data/setup/setup.cygwin.rb +120 -0
- data/setup/setup.mingw.rb +99 -0
- data/setup/setup.mswin32.rb +103 -0
- data/test/test_opencv.rb +4 -0
- metadata +191 -0
data/ext/cvcapture.cpp
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvcapture.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include"cvcapture.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvCapture
|
13
|
+
*
|
14
|
+
* Capture image from video stream.
|
15
|
+
*
|
16
|
+
*/
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
18
|
+
__NAMESPACE_BEGIN_CVCAPTURE
|
19
|
+
|
20
|
+
VALUE rb_klass;
|
21
|
+
|
22
|
+
VALUE
|
23
|
+
rb_class()
|
24
|
+
{
|
25
|
+
return rb_klass;
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
define_ruby_class()
|
30
|
+
{
|
31
|
+
if (rb_klass)
|
32
|
+
return;
|
33
|
+
/*
|
34
|
+
* opencv = rb_define_module("OpenCV");
|
35
|
+
*
|
36
|
+
* note: this comment is used by rdoc.
|
37
|
+
*/
|
38
|
+
VALUE opencv = rb_module_opencv();
|
39
|
+
|
40
|
+
rb_klass = rb_define_class_under(opencv, "CvCapture", rb_cData);
|
41
|
+
|
42
|
+
VALUE video_interface = rb_hash_new();
|
43
|
+
/* {:any, :mil, :vfw, :v4l, :v4l2, :fireware, :ieee1394, :dc1394, :cmu1394, :stereo, :tyzx, :tyzx_left, :tyzx_right, :tyzx_color, :tyzx_z, :qt, :qtuicktime}: video source */
|
44
|
+
rb_define_const(rb_klass, "INTERFACE", video_interface);
|
45
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("any")), INT2FIX(CV_CAP_ANY));
|
46
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("mil")), INT2FIX(CV_CAP_MIL));
|
47
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("vfw")), INT2FIX(CV_CAP_VFW));
|
48
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l")), INT2FIX(CV_CAP_V4L));
|
49
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("v4l2")), INT2FIX(CV_CAP_V4L2));
|
50
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("fireware")), INT2FIX(CV_CAP_FIREWARE));
|
51
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("ieee1394")), INT2FIX(CV_CAP_IEEE1394));
|
52
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("dc1394")), INT2FIX(CV_CAP_DC1394));
|
53
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("cmu1394")), INT2FIX(CV_CAP_CMU1394));
|
54
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("stereo")), INT2FIX(CV_CAP_STEREO));
|
55
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx")), INT2FIX(CV_CAP_TYZX));
|
56
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_left")), INT2FIX(CV_TYZX_LEFT));
|
57
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_right")), INT2FIX(CV_TYZX_RIGHT));
|
58
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_color")), INT2FIX(CV_TYZX_COLOR));
|
59
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("tyzx_z")), INT2FIX(CV_TYZX_Z));
|
60
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("qt")), INT2FIX(CV_CAP_QT));
|
61
|
+
rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
|
62
|
+
|
63
|
+
rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
|
64
|
+
|
65
|
+
rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
|
66
|
+
rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
|
67
|
+
rb_define_method(rb_klass, "query", RUBY_METHOD_FUNC(rb_query), 0);
|
68
|
+
rb_define_method(rb_klass, "millisecond", RUBY_METHOD_FUNC(rb_millisecond), 0);
|
69
|
+
rb_define_method(rb_klass, "frames", RUBY_METHOD_FUNC(rb_frames), 0);
|
70
|
+
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
|
71
|
+
rb_define_method(rb_klass, "width", RUBY_METHOD_FUNC(rb_width), 0);
|
72
|
+
rb_define_method(rb_klass, "height", RUBY_METHOD_FUNC(rb_height), 0);
|
73
|
+
rb_define_method(rb_klass, "fps", RUBY_METHOD_FUNC(rb_fps), 0);
|
74
|
+
rb_define_method(rb_klass, "fourcc", RUBY_METHOD_FUNC(rb_fourcc), 0);
|
75
|
+
rb_define_method(rb_klass, "frame_count", RUBY_METHOD_FUNC(rb_frame_count), 0);
|
76
|
+
}
|
77
|
+
|
78
|
+
void
|
79
|
+
free(void *ptr)
|
80
|
+
{
|
81
|
+
if(ptr)
|
82
|
+
cvReleaseCapture((CvCapture**)&ptr);
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* CvCapture.open(<i>[dev = -1]</i>)
|
88
|
+
*
|
89
|
+
* Reading video stream from the specified file or camera device.
|
90
|
+
* If <i>dev</i> is string (i.e "stream.avi"), reading video stream from file.
|
91
|
+
* If <i>dev</i> is number or symbol(include CvCapture::INTERFACE),
|
92
|
+
* reading video stream from camera.
|
93
|
+
* Currently two camera interfaces can be used on Windows:
|
94
|
+
* * Video for Windows(VFW)
|
95
|
+
* * Matrox Imaging Library(MIL)
|
96
|
+
* and two on Linux
|
97
|
+
* * V4L
|
98
|
+
* * FireWire(IEEE1394).
|
99
|
+
* If there is only one camera or it does not matter what camera to use <i>nil</i> may be passed.
|
100
|
+
*/
|
101
|
+
VALUE
|
102
|
+
rb_open(int argc, VALUE *argv, VALUE self)
|
103
|
+
{
|
104
|
+
VALUE device, i;
|
105
|
+
rb_scan_args(argc, argv, "01", &device);
|
106
|
+
CvCapture *capture = 0;
|
107
|
+
switch (TYPE(device)) {
|
108
|
+
case T_STRING:
|
109
|
+
capture = cvCaptureFromFile(StringValueCStr(device));
|
110
|
+
break;
|
111
|
+
case T_FIXNUM:
|
112
|
+
capture = cvCaptureFromCAM(FIX2INT(device));
|
113
|
+
break;
|
114
|
+
case T_SYMBOL:
|
115
|
+
i = rb_hash_aref(rb_const_get(rb_class(), rb_intern("INTERFACE")), device);
|
116
|
+
if (NIL_P(i))
|
117
|
+
rb_raise(rb_eArgError, "undefined interface.");
|
118
|
+
capture = cvCaptureFromCAM(NUM2INT(i));
|
119
|
+
break;
|
120
|
+
case T_NIL:
|
121
|
+
capture = cvCaptureFromCAM(CV_CAP_ANY);
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
if (!capture)
|
125
|
+
rb_raise(rb_eStandardError, "Invalid capture format.");
|
126
|
+
return Data_Wrap_Struct(rb_klass, 0, free, capture);
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
/*
|
131
|
+
* call-seq:
|
132
|
+
* grab -> true or false
|
133
|
+
*
|
134
|
+
* Grabbed frame is stored internally. To grab frame
|
135
|
+
* <i>fast</i> that is important for syncronization in case of reading from
|
136
|
+
* several cameras simultaneously. The grabbed frames are not exposed because
|
137
|
+
* they may be stored in compressed format (as defined by camera/driver).
|
138
|
+
* To retrieve the grabbed frame, retrieve should be used.
|
139
|
+
*
|
140
|
+
* If grabbed frame was success, return true. Otherwise return false.
|
141
|
+
*/
|
142
|
+
VALUE
|
143
|
+
rb_grab(VALUE self)
|
144
|
+
{
|
145
|
+
return cvGrabFrame(CVCAPTURE(self)) ? Qtrue : Qfalse;
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* retrieve -> CvMat or nil
|
151
|
+
*
|
152
|
+
* Gets the image grabbed with grab.
|
153
|
+
*/
|
154
|
+
VALUE
|
155
|
+
rb_retrieve(VALUE self)
|
156
|
+
{
|
157
|
+
IplImage *frame = cvRetrieveFrame(CVCAPTURE(self));
|
158
|
+
if(!frame)
|
159
|
+
return Qnil;
|
160
|
+
VALUE image = cIplImage::new_object(cvSize(frame->width, frame->height), CV_MAKETYPE(CV_8U, frame->nChannels));
|
161
|
+
if (frame->origin == IPL_ORIGIN_TL) {
|
162
|
+
cvCopy(frame, CVARR(image));
|
163
|
+
} else {
|
164
|
+
cvFlip(frame, CVARR(image));
|
165
|
+
}
|
166
|
+
return image;
|
167
|
+
}
|
168
|
+
|
169
|
+
/*
|
170
|
+
* call-seq:
|
171
|
+
* query -> CvMat or nil
|
172
|
+
*
|
173
|
+
* Grabs and returns a frame camera or file. Just a combination of grab and retrieve in one call.
|
174
|
+
*/
|
175
|
+
VALUE
|
176
|
+
rb_query(VALUE self)
|
177
|
+
{
|
178
|
+
IplImage *frame = cvQueryFrame(CVCAPTURE(self));
|
179
|
+
if(!frame)
|
180
|
+
return Qnil;
|
181
|
+
VALUE image = cIplImage::new_object(cvSize(frame->width, frame->height), CV_MAKETYPE(CV_8U, frame->nChannels));
|
182
|
+
if (frame->origin == IPL_ORIGIN_TL) {
|
183
|
+
cvCopy(frame, CVARR(image));
|
184
|
+
} else {
|
185
|
+
cvFlip(frame, CVARR(image));
|
186
|
+
}
|
187
|
+
return image;
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* Film current position in milliseconds or video capture timestamp.
|
192
|
+
*/
|
193
|
+
VALUE
|
194
|
+
rb_millisecond(VALUE self)
|
195
|
+
{
|
196
|
+
return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_MSEC));
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
* 0-based index of the frame to be decoded/captured next
|
201
|
+
*/
|
202
|
+
VALUE
|
203
|
+
rb_frames(VALUE self)
|
204
|
+
{
|
205
|
+
return rb_float_new(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_FRAMES));
|
206
|
+
}
|
207
|
+
|
208
|
+
/*
|
209
|
+
* Relative position of video file (0 - start of the film, 1 - end of the film)
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
rb_avi_ratio(VALUE self)
|
213
|
+
{
|
214
|
+
return rb_float_new(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_POS_AVI_RATIO));
|
215
|
+
}
|
216
|
+
|
217
|
+
/*
|
218
|
+
* Size of frames in the video stream.
|
219
|
+
*/
|
220
|
+
VALUE
|
221
|
+
rb_size(VALUE self)
|
222
|
+
{
|
223
|
+
return cCvSize::new_object(cvSize((int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT)));
|
224
|
+
}
|
225
|
+
|
226
|
+
/*
|
227
|
+
* Width of frames in the video stream.
|
228
|
+
*/
|
229
|
+
VALUE
|
230
|
+
rb_width(VALUE self)
|
231
|
+
{
|
232
|
+
return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_WIDTH));
|
233
|
+
}
|
234
|
+
|
235
|
+
/*
|
236
|
+
* Height of frames in the video stream.
|
237
|
+
*/
|
238
|
+
VALUE
|
239
|
+
rb_height(VALUE self)
|
240
|
+
{
|
241
|
+
return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_HEIGHT));
|
242
|
+
}
|
243
|
+
|
244
|
+
/*
|
245
|
+
* Frame rate
|
246
|
+
*/
|
247
|
+
VALUE
|
248
|
+
rb_fps(VALUE self)
|
249
|
+
{
|
250
|
+
return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FPS));
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
* 4character code of codec. see http://www.fourcc.org/
|
255
|
+
*/
|
256
|
+
VALUE
|
257
|
+
rb_fourcc(VALUE self)
|
258
|
+
{
|
259
|
+
char str[4];
|
260
|
+
double fourcc = cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FOURCC);
|
261
|
+
sprintf(str, "%s", (char*)&fourcc);
|
262
|
+
return rb_str_new2(str);
|
263
|
+
}
|
264
|
+
|
265
|
+
/*
|
266
|
+
* Number of frames in video file.
|
267
|
+
*/
|
268
|
+
VALUE
|
269
|
+
rb_frame_count(VALUE self)
|
270
|
+
{
|
271
|
+
return rb_dbl2big(cvGetCaptureProperty(CVCAPTURE(self), CV_CAP_PROP_FRAME_COUNT));
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
__NAMESPACE_END_CVCAPTURE
|
276
|
+
__NAMESPACE_END_OPENCV
|
data/ext/cvcapture.h
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvcapture.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVCAPTURE_H
|
11
|
+
#define RUBY_OPENCV_CVCAPTURE_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVCAPTURE namespace cCvCapture{
|
16
|
+
#define __NAMESPACE_END_CVCAPTURE }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVCAPTURE
|
20
|
+
|
21
|
+
|
22
|
+
VALUE rb_class();
|
23
|
+
|
24
|
+
void define_ruby_class();
|
25
|
+
|
26
|
+
void free(void *ptr);
|
27
|
+
VALUE rb_open(int argc, VALUE *argv, VALUE klass);
|
28
|
+
|
29
|
+
VALUE rb_grab(VALUE self);
|
30
|
+
VALUE rb_retrieve(VALUE self);
|
31
|
+
VALUE rb_query(VALUE self);
|
32
|
+
|
33
|
+
VALUE rb_millisecond(VALUE self);
|
34
|
+
VALUE rb_frames(VALUE self);
|
35
|
+
VALUE rb_avi_ratio(VALUE self);
|
36
|
+
VALUE rb_size(VALUE self);
|
37
|
+
VALUE rb_width(VALUE self);
|
38
|
+
VALUE rb_height(VALUE self);
|
39
|
+
VALUE rb_fps(VALUE self);
|
40
|
+
VALUE rb_fourcc(VALUE self);
|
41
|
+
VALUE rb_frame_count(VALUE self);
|
42
|
+
|
43
|
+
__NAMESPACE_END_CVCAPTURE
|
44
|
+
|
45
|
+
|
46
|
+
inline CvCapture *CVCAPTURE(VALUE object){
|
47
|
+
CvCapture *ptr;
|
48
|
+
Data_Get_Struct(object, CvCapture, ptr);
|
49
|
+
return ptr;
|
50
|
+
}
|
51
|
+
|
52
|
+
__NAMESPACE_END_OPENCV
|
53
|
+
|
54
|
+
#endif // RUBY_OPENCV_CVCAPTURE_H
|
data/ext/cvchain.cpp
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvchain.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvchain.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvChain
|
13
|
+
*
|
14
|
+
* Freeman chain code.
|
15
|
+
* CvMat#find_contours(:method => :code)
|
16
|
+
*/
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
18
|
+
__NAMESPACE_BEGIN_CVCHAIN
|
19
|
+
|
20
|
+
#define APPROX_CHAIN_OPTION(op) NIL_P(op) ? rb_const_get(rb_class(), rb_intern("APPROX_CHAIN_OPTION")) : rb_funcall(rb_const_get(rb_class(), rb_intern("APPROX_CHAIN_OPTION")), rb_intern("merge"), 1, op)
|
21
|
+
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", rb_hash_aref(op, ID2SYM(rb_intern("method"))), CV_CHAIN_APPROX_SIMPLE)
|
22
|
+
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(rb_hash_aref(op, ID2SYM(rb_intern("parameter"))))
|
23
|
+
#define APPROX_CHAIN_MINIMAL_PARAMETER(op) NUM2INT(rb_hash_aref(op, ID2SYM(rb_intern("minimal_parameter"))))
|
24
|
+
#define APPROX_CHAIN_RECURSIVE(op) ({VALUE _recursive = rb_hash_aref(op, ID2SYM(rb_intern("recursive"))); NIL_P(_recursive) ? 0 : _recursive == Qfalse ? 0 : 1;})
|
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
|
+
* cvseq = rb_define_class_under(opencv, "CvSeq");
|
42
|
+
* curve = rb_define_module_under(opencv, "Curve");
|
43
|
+
* note: this comment is used by rdoc.
|
44
|
+
*/
|
45
|
+
VALUE opencv = rb_module_opencv();
|
46
|
+
VALUE cvseq = cCvSeq::rb_class();
|
47
|
+
VALUE curve = mCurve::rb_module();
|
48
|
+
|
49
|
+
rb_klass = rb_define_class_under(opencv, "CvChain", cvseq);
|
50
|
+
rb_include_module(rb_klass, curve);
|
51
|
+
VALUE approx_chain_option = rb_hash_new();
|
52
|
+
rb_define_const(rb_klass, "APPROX_CHAIN_OPTION", approx_chain_option);
|
53
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("approx_simple")));
|
54
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("parameter")), rb_float_new(0));
|
55
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("minimal_parameter")), INT2FIX(0));
|
56
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
57
|
+
|
58
|
+
rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
|
59
|
+
rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 0);
|
60
|
+
rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
|
61
|
+
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
62
|
+
rb_define_method(rb_klass, "approx_chain", RUBY_METHOD_FUNC(rb_approx_chain), -1);
|
63
|
+
rb_define_alias(rb_klass, "approx", "approx_chain");
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq:
|
68
|
+
* origin -> cvpoint
|
69
|
+
*
|
70
|
+
* Return Freeman chain code origin.
|
71
|
+
*/
|
72
|
+
VALUE
|
73
|
+
rb_origin(VALUE self)
|
74
|
+
{
|
75
|
+
return cCvPoint::new_object(CVCHAIN(self)->origin);
|
76
|
+
}
|
77
|
+
|
78
|
+
/*
|
79
|
+
* call-seq:
|
80
|
+
* origin = point -> self
|
81
|
+
*
|
82
|
+
* Set Freeman chain code origin.
|
83
|
+
*/
|
84
|
+
VALUE
|
85
|
+
rb_set_origin(VALUE self, VALUE origin)
|
86
|
+
{
|
87
|
+
CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
|
88
|
+
return self;
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq:
|
93
|
+
* codes -> array(contain fixnum)
|
94
|
+
*
|
95
|
+
* Return Freeman chain codes.
|
96
|
+
*/
|
97
|
+
VALUE
|
98
|
+
rb_codes(VALUE self)
|
99
|
+
{
|
100
|
+
CvChain *chain = CVCHAIN(self);
|
101
|
+
CvChainPtReader reader;
|
102
|
+
CvPoint p = chain->origin;
|
103
|
+
VALUE ary = rb_ary_new2(chain->total);
|
104
|
+
cvStartReadChainPoints(chain, &reader);
|
105
|
+
for (int i = 0; i < chain->total; i++) {
|
106
|
+
CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
|
107
|
+
rb_ary_store(ary, i, CHR2FIX(reader.code));
|
108
|
+
}
|
109
|
+
return ary;
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* points -> array(contain cvpoint)
|
115
|
+
*
|
116
|
+
* Return points that represent by Freeman chain code.
|
117
|
+
*/
|
118
|
+
VALUE
|
119
|
+
rb_points(VALUE self)
|
120
|
+
{
|
121
|
+
CvChain *chain = CVCHAIN(self);
|
122
|
+
CvChainPtReader reader;
|
123
|
+
CvPoint p = chain->origin;
|
124
|
+
VALUE ary = rb_ary_new2(chain->total);
|
125
|
+
cvStartReadChainPoints(chain, &reader);
|
126
|
+
for (int i = 0; i < chain->total; i++) {
|
127
|
+
CV_READ_CHAIN_POINT(p, reader);
|
128
|
+
rb_ary_store(ary, i, cCvPoint::new_object(p));
|
129
|
+
}
|
130
|
+
return ary;
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* call-seq:
|
135
|
+
* approx_chain(<i>[approx_chain_option]</i>) -> cvcontour
|
136
|
+
*
|
137
|
+
* Approximates Freeman chain(s) with polygonal curve.
|
138
|
+
* <i>approx_chain_option</i> should be Hash include these keys.
|
139
|
+
* :method - Approximation method.
|
140
|
+
* :approx_none - translate all the points from the chain code into points;
|
141
|
+
* :approx_simple(default) - compress horizontal, vertical, and diagonal segments, that is,
|
142
|
+
* the function leaves only their ending points.
|
143
|
+
* :approx_tc89_l1
|
144
|
+
* :approx_tc89_kcos - apply one of the flavors of Teh-Chin chain approximation algorithm.
|
145
|
+
* If set the difference between the current pixel and seed pixel is considered,
|
146
|
+
* otherwise difference between neighbor pixels is considered (the range is floating).
|
147
|
+
* :parameter - Method parameter (not used now).
|
148
|
+
* :minimal_perimeter (default 0)
|
149
|
+
* Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure.
|
150
|
+
* :recursive (default false)
|
151
|
+
* If not nil or false, the function approximates all chains that access can be obtained to
|
152
|
+
* from self by h_next or v_next links. If 0, the single chain is approximated.
|
153
|
+
*
|
154
|
+
*/
|
155
|
+
VALUE
|
156
|
+
rb_approx_chain(int argc, VALUE *argv, VALUE self)
|
157
|
+
{
|
158
|
+
VALUE approx_chain_option, storage;
|
159
|
+
rb_scan_args(argc, argv, "01", &approx_chain_option);
|
160
|
+
approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
|
161
|
+
/* can't compile VC
|
162
|
+
storage = cCvMemStorage::new_object();
|
163
|
+
CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
|
164
|
+
APPROX_CHAIN_METHOD(approx_chain_option),
|
165
|
+
APPROX_CHAIN_PARAMETER(approx_chain_option),
|
166
|
+
APPROX_CHAIN_MINIMAL_PARAMETER(approx_chain_option),
|
167
|
+
APPROX_CHAIN_RECURSIVE(approx_chain_option));
|
168
|
+
|
169
|
+
return cCvSeq::new_sequence(cCvContour::rb_class(), seq, cCvPoint::rb_class(), storage);
|
170
|
+
*/
|
171
|
+
return Qnil;
|
172
|
+
}
|
173
|
+
|
174
|
+
VALUE
|
175
|
+
new_object()
|
176
|
+
{
|
177
|
+
VALUE storage = cCvMemStorage::new_object();
|
178
|
+
CvSeq *seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(CvChainCode), CVMEMSTORAGE(storage));
|
179
|
+
VALUE object = cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvChainCode::rb_class(), storage);
|
180
|
+
return object;
|
181
|
+
}
|
182
|
+
|
183
|
+
__NAMESPACE_END_CVCHAIN
|
184
|
+
__NAMESPACE_END_OPENCV
|