bonanza-ruby-opencv 0.0.13.20140330211753
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -0
- data/ext/opencv/window.h +66 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/chessboard.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -0
@@ -0,0 +1,605 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvseq.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvseq.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvSeq
|
13
|
+
*
|
14
|
+
* Generic Sequence class. CvSeq has the method like Array (push, pop, select, etc...).
|
15
|
+
* But, CvSeq cannot store the object of a different class.
|
16
|
+
* When storing object in CvSeq, conversion is automatically tried,
|
17
|
+
* and the object occurs the error if it cannot be done.
|
18
|
+
*
|
19
|
+
* e.g.
|
20
|
+
* seq = CvSeq.new(CvPoint) # Argument mean "this sequence contain only this class's object"
|
21
|
+
* seq.push(CvPoint.new(0, 0)) # => it's ok
|
22
|
+
* seq.push("hello") # => try convert "hello" to CvPoint. but can't do it. raise error.
|
23
|
+
*
|
24
|
+
* If the sequecne contain object of class A.
|
25
|
+
* When storing object(named "obj") of class B to the sequence.
|
26
|
+
* Try automatically : A.from_B(obj) => object of class A.
|
27
|
+
*
|
28
|
+
* The sequence might have another sequence outside. see below.
|
29
|
+
* Each sequece has h_prev, h_next, v_prev, v_next method.
|
30
|
+
* If the adjoining sequence exists, each method return the adjoining sequence.
|
31
|
+
* Otherwise return nil.
|
32
|
+
*
|
33
|
+
* link:../images/CvSeq_relationmap.png
|
34
|
+
*/
|
35
|
+
__NAMESPACE_BEGIN_OPENCV
|
36
|
+
__NAMESPACE_BEGIN_CVSEQ
|
37
|
+
|
38
|
+
VALUE rb_allocate(VALUE klass);
|
39
|
+
void cvseq_free(void *ptr);
|
40
|
+
|
41
|
+
VALUE rb_klass;
|
42
|
+
// contain sequence-block class
|
43
|
+
st_table *seqblock_klass_table = st_init_numtable();
|
44
|
+
|
45
|
+
VALUE
|
46
|
+
rb_class()
|
47
|
+
{
|
48
|
+
return rb_klass;
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE
|
52
|
+
seqblock_class(void *ptr)
|
53
|
+
{
|
54
|
+
VALUE klass;
|
55
|
+
if (!st_lookup(seqblock_klass_table, (st_data_t)ptr, (st_data_t*)&klass)) {
|
56
|
+
rb_raise(rb_eTypeError, "Invalid sequence error.");
|
57
|
+
}
|
58
|
+
return klass;
|
59
|
+
}
|
60
|
+
|
61
|
+
void
|
62
|
+
register_elem_class(CvSeq *seq, VALUE klass)
|
63
|
+
{
|
64
|
+
st_insert(seqblock_klass_table, (st_data_t)seq, (st_data_t)klass);
|
65
|
+
}
|
66
|
+
|
67
|
+
void
|
68
|
+
unregister_elem_class(void *ptr)
|
69
|
+
{
|
70
|
+
if (ptr) {
|
71
|
+
st_delete(seqblock_klass_table, (st_data_t*)&ptr, NULL);
|
72
|
+
unregister_object(ptr);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
VALUE
|
77
|
+
rb_allocate(VALUE klass)
|
78
|
+
{
|
79
|
+
CvSeq *ptr = ALLOC(CvSeq);
|
80
|
+
return Data_Wrap_Struct(klass, 0, unregister_elem_class, ptr);
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* CvSeq.new(type[,storage])
|
86
|
+
*
|
87
|
+
* Return a new CvSeq. <i>type</i> should be following classes.
|
88
|
+
*
|
89
|
+
* * CvIndex
|
90
|
+
* * CvPoint
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
94
|
+
{
|
95
|
+
VALUE klass, storage_value;
|
96
|
+
|
97
|
+
rb_scan_args(argc, argv, "11", &klass, &storage_value);
|
98
|
+
if (!rb_obj_is_kind_of(klass, rb_cClass))
|
99
|
+
raise_typeerror(klass, rb_cClass);
|
100
|
+
|
101
|
+
int type = 0, size = 0;
|
102
|
+
if (klass == rb_cFixnum) {
|
103
|
+
type = CV_SEQ_ELTYPE_INDEX;
|
104
|
+
size = sizeof(int);
|
105
|
+
}
|
106
|
+
else if (klass == cCvPoint::rb_class()) {
|
107
|
+
type = CV_SEQ_ELTYPE_POINT;
|
108
|
+
size = sizeof(CvPoint);
|
109
|
+
}
|
110
|
+
else if (klass == cCvPoint2D32f::rb_class()) {
|
111
|
+
type = CV_SEQ_ELTYPE_POINT;
|
112
|
+
size = sizeof(CvPoint2D32f);
|
113
|
+
}
|
114
|
+
else if (klass == cCvPoint3D32f::rb_class()) {
|
115
|
+
type = CV_SEQ_ELTYPE_POINT3D;
|
116
|
+
size = sizeof(CvPoint3D32f);
|
117
|
+
}
|
118
|
+
else
|
119
|
+
rb_raise(rb_eArgError, "unsupport %s class for sequence-block.", rb_class2name(klass));
|
120
|
+
|
121
|
+
CvSeq* seq = NULL;
|
122
|
+
if (NIL_P(storage_value)) {
|
123
|
+
storage_value = cCvMemStorage::new_object(0);
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
127
|
+
}
|
128
|
+
|
129
|
+
try {
|
130
|
+
seq = cvCreateSeq(type, sizeof(CvSeq), size, CVMEMSTORAGE(storage_value));
|
131
|
+
}
|
132
|
+
catch (cv::Exception& e) {
|
133
|
+
raise_cverror(e);
|
134
|
+
}
|
135
|
+
DATA_PTR(self) = seq;
|
136
|
+
register_elem_class(seq, klass);
|
137
|
+
register_root_object(seq, storage_value);
|
138
|
+
|
139
|
+
return self;
|
140
|
+
}
|
141
|
+
|
142
|
+
/*
|
143
|
+
* call-seq:
|
144
|
+
* total -> int
|
145
|
+
*
|
146
|
+
* Return total number of sequence-block.
|
147
|
+
*/
|
148
|
+
VALUE
|
149
|
+
rb_total(VALUE self)
|
150
|
+
{
|
151
|
+
return INT2NUM(CVSEQ(self)->total);
|
152
|
+
}
|
153
|
+
|
154
|
+
/*
|
155
|
+
* call-seq:
|
156
|
+
* empty? -> true or false.
|
157
|
+
*
|
158
|
+
* Return <tt>true</tt> if contain no object, otherwize return <tt>false</tt>.
|
159
|
+
*/
|
160
|
+
VALUE
|
161
|
+
rb_empty_q(VALUE self)
|
162
|
+
{
|
163
|
+
return CVSEQ(self)->total == 0 ? Qtrue : Qfalse;
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq:
|
168
|
+
* [<i>index</i>] -> obj or nil
|
169
|
+
*
|
170
|
+
* Return sequence-block at <i>index</i>.
|
171
|
+
*/
|
172
|
+
VALUE
|
173
|
+
rb_aref(VALUE self, VALUE index)
|
174
|
+
{
|
175
|
+
CvSeq *seq = CVSEQ(self);
|
176
|
+
int idx = NUM2INT(index);
|
177
|
+
if (seq->total == 0)
|
178
|
+
return Qnil;
|
179
|
+
if (idx >= seq->total)
|
180
|
+
rb_raise(rb_eIndexError, "index %d out of sequence", idx);
|
181
|
+
|
182
|
+
VALUE result = Qnil;
|
183
|
+
try {
|
184
|
+
if (seqblock_class(seq) == rb_cFixnum)
|
185
|
+
result = INT2NUM(*CV_GET_SEQ_ELEM(int, seq, idx));
|
186
|
+
else
|
187
|
+
result = REFER_OBJECT(seqblock_class(seq), cvGetSeqElem(seq, idx), self);
|
188
|
+
}
|
189
|
+
catch (cv::Exception& e) {
|
190
|
+
raise_cverror(e);
|
191
|
+
}
|
192
|
+
return result;
|
193
|
+
}
|
194
|
+
|
195
|
+
/*
|
196
|
+
* call-seq:
|
197
|
+
* first -> obj or nil
|
198
|
+
*
|
199
|
+
* Return first sequence-block.
|
200
|
+
*/
|
201
|
+
VALUE
|
202
|
+
rb_first(VALUE self)
|
203
|
+
{
|
204
|
+
return rb_aref(self, INT2FIX(0));
|
205
|
+
}
|
206
|
+
|
207
|
+
/*
|
208
|
+
* call-seq:
|
209
|
+
* last -> obj or nil
|
210
|
+
*
|
211
|
+
* Return last sequence-block.
|
212
|
+
*/
|
213
|
+
VALUE
|
214
|
+
rb_last(VALUE self)
|
215
|
+
{
|
216
|
+
return rb_aref(self, INT2FIX(-1));
|
217
|
+
}
|
218
|
+
|
219
|
+
/*
|
220
|
+
* call-seq:
|
221
|
+
* h_prev -> seq or nil
|
222
|
+
*
|
223
|
+
* Return the sequence horizontally located in previous.
|
224
|
+
* Return <tt>nil</tt> if not existing.
|
225
|
+
*/
|
226
|
+
VALUE
|
227
|
+
rb_h_prev(VALUE self)
|
228
|
+
{
|
229
|
+
CvSeq *seq = CVSEQ(self);
|
230
|
+
if (seq->h_prev)
|
231
|
+
return new_sequence(CLASS_OF(self), seq->h_prev, seqblock_class(seq), lookup_root_object(seq));
|
232
|
+
else
|
233
|
+
return Qnil;
|
234
|
+
}
|
235
|
+
|
236
|
+
/*
|
237
|
+
* call-seq:
|
238
|
+
* h_next -> seq or nil
|
239
|
+
*
|
240
|
+
* Return the sequence horizontally located in next.
|
241
|
+
* Return <tt>nil</tt> if not existing.
|
242
|
+
*/
|
243
|
+
VALUE
|
244
|
+
rb_h_next(VALUE self)
|
245
|
+
{
|
246
|
+
CvSeq *seq = CVSEQ(self);
|
247
|
+
if (seq->h_next)
|
248
|
+
return new_sequence(CLASS_OF(self), seq->h_next, seqblock_class(seq), lookup_root_object(seq));
|
249
|
+
else
|
250
|
+
return Qnil;
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* v_prev -> seq or nil
|
256
|
+
*
|
257
|
+
* Return the sequence vertically located in previous.
|
258
|
+
* Return <tt>nil</tt> if not existing.
|
259
|
+
*/
|
260
|
+
VALUE
|
261
|
+
rb_v_prev(VALUE self)
|
262
|
+
{
|
263
|
+
CvSeq *seq = CVSEQ(self);
|
264
|
+
if (seq->v_prev)
|
265
|
+
return new_sequence(CLASS_OF(self), seq->v_prev, seqblock_class(seq), lookup_root_object(seq));
|
266
|
+
else
|
267
|
+
return Qnil;
|
268
|
+
}
|
269
|
+
|
270
|
+
/*
|
271
|
+
* call-seq:
|
272
|
+
* v_next -> seq or nil
|
273
|
+
*
|
274
|
+
* Return the sequence vertically located in next.
|
275
|
+
* Return <tt>nil</tt> if not existing.
|
276
|
+
*/
|
277
|
+
VALUE
|
278
|
+
rb_v_next(VALUE self)
|
279
|
+
{
|
280
|
+
CvSeq *seq = CVSEQ(self);
|
281
|
+
if (seq->v_next)
|
282
|
+
return new_sequence(CLASS_OF(self), seq->v_next, seqblock_class(seq), lookup_root_object(seq));
|
283
|
+
else
|
284
|
+
return Qnil;
|
285
|
+
}
|
286
|
+
|
287
|
+
VALUE
|
288
|
+
rb_seq_push(VALUE self, VALUE args, int flag)
|
289
|
+
{
|
290
|
+
CvSeq *seq = CVSEQ(self);
|
291
|
+
VALUE klass = seqblock_class(seq), object;
|
292
|
+
volatile void *elem = NULL;
|
293
|
+
int len = RARRAY_LEN(args);
|
294
|
+
for (int i = 0; i < len; ++i) {
|
295
|
+
object = RARRAY_PTR(args)[i];
|
296
|
+
if (CLASS_OF(object) == klass) {
|
297
|
+
if (TYPE(object) == T_FIXNUM) {
|
298
|
+
volatile int int_elem = FIX2INT(object);
|
299
|
+
elem = &int_elem;
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
elem = (void*)DATA_PTR(object);
|
303
|
+
}
|
304
|
+
try {
|
305
|
+
if (flag == CV_FRONT)
|
306
|
+
cvSeqPushFront(seq, (const void*)elem);
|
307
|
+
else
|
308
|
+
cvSeqPush(seq, (const void*)elem);
|
309
|
+
}
|
310
|
+
catch (cv::Exception& e) {
|
311
|
+
raise_cverror(e);
|
312
|
+
}
|
313
|
+
}
|
314
|
+
else if (rb_obj_is_kind_of(object, rb_klass) && CLASS_OF(rb_first(object)) == klass) { // object is CvSeq
|
315
|
+
void *buffer = NULL;
|
316
|
+
try {
|
317
|
+
buffer = cvCvtSeqToArray(CVSEQ(object), rb_cvAlloc(CVSEQ(object)->total * CVSEQ(object)->elem_size));
|
318
|
+
cvSeqPushMulti(seq, buffer, CVSEQ(object)->total, flag);
|
319
|
+
cvFree(&buffer);
|
320
|
+
}
|
321
|
+
catch (cv::Exception& e) {
|
322
|
+
if (buffer != NULL)
|
323
|
+
cvFree(&buffer);
|
324
|
+
raise_cverror(e);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
else {
|
328
|
+
rb_raise(rb_eTypeError, "arguments should be %s or %s which includes %s.",
|
329
|
+
rb_class2name(klass), rb_class2name(rb_klass), rb_class2name(klass));
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
return self;
|
334
|
+
}
|
335
|
+
|
336
|
+
/*
|
337
|
+
* call-seq:
|
338
|
+
* push(obj, ...) -> self
|
339
|
+
*
|
340
|
+
* Append - Pushes the given object(s) on the end of this sequence. This expression return the sequence itself,
|
341
|
+
* so several append may be chained together.
|
342
|
+
*/
|
343
|
+
VALUE
|
344
|
+
rb_push(VALUE self, VALUE args)
|
345
|
+
{
|
346
|
+
return rb_seq_push(self, args, CV_BACK);
|
347
|
+
}
|
348
|
+
|
349
|
+
/*
|
350
|
+
* call-seq:
|
351
|
+
* pop -> obj or nil
|
352
|
+
*
|
353
|
+
* Remove the last sequence-block from <i>self</i> and return it,
|
354
|
+
* or <tt>nil</tt> if the sequence is empty.
|
355
|
+
*/
|
356
|
+
VALUE
|
357
|
+
rb_pop(VALUE self)
|
358
|
+
{
|
359
|
+
CvSeq *seq = CVSEQ(self);
|
360
|
+
if (seq->total == 0)
|
361
|
+
return Qnil;
|
362
|
+
|
363
|
+
VALUE object = Qnil;
|
364
|
+
VALUE klass = seqblock_class(seq);
|
365
|
+
try {
|
366
|
+
if (klass == rb_cFixnum) {
|
367
|
+
int n = 0;
|
368
|
+
cvSeqPop(seq, &n);
|
369
|
+
object = INT2FIX(n);
|
370
|
+
}
|
371
|
+
else {
|
372
|
+
object = GENERIC_OBJECT(klass, malloc(seq->elem_size));
|
373
|
+
cvSeqPop(seq, DATA_PTR(object));
|
374
|
+
}
|
375
|
+
}
|
376
|
+
catch (cv::Exception& e) {
|
377
|
+
raise_cverror(e);
|
378
|
+
}
|
379
|
+
return object;
|
380
|
+
}
|
381
|
+
|
382
|
+
/*
|
383
|
+
* call-seq:
|
384
|
+
* clear -> self
|
385
|
+
*
|
386
|
+
* Clears sequence. Removes all elements from the sequence.
|
387
|
+
*/
|
388
|
+
VALUE
|
389
|
+
rb_clear(VALUE self)
|
390
|
+
{
|
391
|
+
try {
|
392
|
+
cvClearSeq(CVSEQ(self));
|
393
|
+
}
|
394
|
+
catch (cv::Exception& e) {
|
395
|
+
raise_cverror(e);
|
396
|
+
}
|
397
|
+
return self;
|
398
|
+
}
|
399
|
+
|
400
|
+
/*
|
401
|
+
* call-seq:
|
402
|
+
* unshift -> self
|
403
|
+
*
|
404
|
+
* Prepends objects to the front of sequence. other elements up one.
|
405
|
+
*/
|
406
|
+
VALUE
|
407
|
+
rb_unshift(VALUE self, VALUE args)
|
408
|
+
{
|
409
|
+
VALUE result = Qnil;
|
410
|
+
try {
|
411
|
+
result = rb_seq_push(self, args, CV_FRONT);
|
412
|
+
}
|
413
|
+
catch (cv::Exception& e) {
|
414
|
+
raise_cverror(e);
|
415
|
+
}
|
416
|
+
return result;
|
417
|
+
}
|
418
|
+
|
419
|
+
/*
|
420
|
+
* call-seq:
|
421
|
+
* shift -> obj or nil
|
422
|
+
*
|
423
|
+
* Returns the first element of <i>self</i> and removes it (shifting all other elements down by one). Returns <tt>nil</tt> if the array is empty.
|
424
|
+
*/
|
425
|
+
VALUE
|
426
|
+
rb_shift(VALUE self)
|
427
|
+
{
|
428
|
+
CvSeq *seq = CVSEQ(self);
|
429
|
+
if (seq->total == 0)
|
430
|
+
return Qnil;
|
431
|
+
|
432
|
+
VALUE object = Qnil;
|
433
|
+
try {
|
434
|
+
if (seqblock_class(seq) == rb_cFixnum) {
|
435
|
+
int n = 0;
|
436
|
+
cvSeqPopFront(seq, &n);
|
437
|
+
object = INT2NUM(n);
|
438
|
+
}
|
439
|
+
else {
|
440
|
+
object = GENERIC_OBJECT(seqblock_class(seq), malloc(seq->elem_size));
|
441
|
+
cvSeqPopFront(seq, DATA_PTR(object));
|
442
|
+
}
|
443
|
+
}
|
444
|
+
catch (cv::Exception& e) {
|
445
|
+
raise_cverror(e);
|
446
|
+
}
|
447
|
+
|
448
|
+
return object;
|
449
|
+
}
|
450
|
+
|
451
|
+
/*
|
452
|
+
* call-seq:
|
453
|
+
* each {|obj| ... } -> self
|
454
|
+
*
|
455
|
+
* Calls block once for each sequence-block in <i>self</i>,
|
456
|
+
* passing that sequence-block as a parameter.
|
457
|
+
* seq = CvSeq.new(CvIndex)
|
458
|
+
* seq.push(5, 6, 7)
|
459
|
+
* seq.each {|x| print x, " -- " }
|
460
|
+
* produces:
|
461
|
+
* 5 -- 6 -- 7 --
|
462
|
+
*/
|
463
|
+
VALUE
|
464
|
+
rb_each(VALUE self)
|
465
|
+
{
|
466
|
+
CvSeq *seq = CVSEQ(self);
|
467
|
+
if (seq->total > 0) {
|
468
|
+
VALUE klass = seqblock_class(seq);
|
469
|
+
try {
|
470
|
+
if (klass == rb_cFixnum)
|
471
|
+
for (int i = 0; i < seq->total; ++i)
|
472
|
+
rb_yield(INT2NUM(*CV_GET_SEQ_ELEM(int, seq, i)));
|
473
|
+
else
|
474
|
+
for (int i = 0; i < seq->total; ++i)
|
475
|
+
rb_yield(REFER_OBJECT(klass, cvGetSeqElem(seq, i), self));
|
476
|
+
}
|
477
|
+
catch (cv::Exception& e) {
|
478
|
+
raise_cverror(e);
|
479
|
+
}
|
480
|
+
}
|
481
|
+
return self;
|
482
|
+
}
|
483
|
+
|
484
|
+
/*
|
485
|
+
* call-seq:
|
486
|
+
* each_index {|index| ... } -> self
|
487
|
+
*
|
488
|
+
* Same as CvSeq#each, but passes the index of the element instead of the element itself.
|
489
|
+
*/
|
490
|
+
VALUE
|
491
|
+
rb_each_index(VALUE self)
|
492
|
+
{
|
493
|
+
CvSeq *seq = CVSEQ(self);
|
494
|
+
for(int i = 0; i < seq->total; ++i)
|
495
|
+
rb_yield(INT2NUM(i));
|
496
|
+
return self;
|
497
|
+
}
|
498
|
+
|
499
|
+
|
500
|
+
/*
|
501
|
+
* call-seq:
|
502
|
+
* insert(index,obj) -> self
|
503
|
+
*
|
504
|
+
* Inserts the given values before element with the given index (which may be negative).
|
505
|
+
*/
|
506
|
+
VALUE
|
507
|
+
rb_insert(VALUE self, VALUE index, VALUE object)
|
508
|
+
{
|
509
|
+
Check_Type(index, T_FIXNUM);
|
510
|
+
CvSeq *seq = CVSEQ(self);
|
511
|
+
VALUE klass = seqblock_class(seq);
|
512
|
+
if (CLASS_OF(object) != klass)
|
513
|
+
rb_raise(rb_eTypeError, "arguments should be %s.", rb_class2name(klass));
|
514
|
+
try {
|
515
|
+
if (klass == rb_cFixnum) {
|
516
|
+
int n = NUM2INT(object);
|
517
|
+
cvSeqInsert(seq, NUM2INT(index), &n);
|
518
|
+
}
|
519
|
+
else
|
520
|
+
cvSeqInsert(seq, NUM2INT(index), DATA_PTR(object));
|
521
|
+
}
|
522
|
+
catch (cv::Exception& e) {
|
523
|
+
raise_cverror(e);
|
524
|
+
}
|
525
|
+
return self;
|
526
|
+
}
|
527
|
+
|
528
|
+
/*
|
529
|
+
* call-seq:
|
530
|
+
* remove(index) -> obj or nil
|
531
|
+
*
|
532
|
+
* Deletes the elements at the specified index.
|
533
|
+
*/
|
534
|
+
VALUE
|
535
|
+
rb_remove(VALUE self, VALUE index)
|
536
|
+
{
|
537
|
+
try {
|
538
|
+
cvSeqRemove(CVSEQ(self), NUM2INT(index));
|
539
|
+
}
|
540
|
+
catch (cv::Exception& e) {
|
541
|
+
raise_cverror(e);
|
542
|
+
}
|
543
|
+
return self;
|
544
|
+
}
|
545
|
+
|
546
|
+
VALUE
|
547
|
+
new_sequence(VALUE klass, CvSeq *seq, VALUE element_klass, VALUE storage)
|
548
|
+
{
|
549
|
+
register_root_object(seq, storage);
|
550
|
+
if (!NIL_P(element_klass))
|
551
|
+
register_elem_class(seq, element_klass);
|
552
|
+
return Data_Wrap_Struct(klass, mark_root_object, unregister_elem_class, seq);
|
553
|
+
}
|
554
|
+
|
555
|
+
void
|
556
|
+
init_ruby_class()
|
557
|
+
{
|
558
|
+
#if 0
|
559
|
+
// For documentation using YARD
|
560
|
+
VALUE opencv = rb_define_module("OpenCV");
|
561
|
+
#endif
|
562
|
+
|
563
|
+
if (rb_klass)
|
564
|
+
return;
|
565
|
+
/*
|
566
|
+
* opencv = rb_define_module("OpenCV");
|
567
|
+
*
|
568
|
+
* note: this comment is used by rdoc.
|
569
|
+
*/
|
570
|
+
VALUE opencv = rb_module_opencv();
|
571
|
+
rb_klass = rb_define_class_under(opencv, "CvSeq", rb_cObject);
|
572
|
+
rb_include_module(rb_klass, rb_mEnumerable);
|
573
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
574
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
575
|
+
rb_define_method(rb_klass, "total", RUBY_METHOD_FUNC(rb_total), 0);
|
576
|
+
rb_define_alias(rb_klass, "length", "total");
|
577
|
+
rb_define_alias(rb_klass, "size", "total");
|
578
|
+
rb_define_method(rb_klass, "empty?", RUBY_METHOD_FUNC(rb_empty_q), 0);
|
579
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
580
|
+
rb_define_method(rb_klass, "first", RUBY_METHOD_FUNC(rb_first), 0);
|
581
|
+
rb_define_method(rb_klass, "last", RUBY_METHOD_FUNC(rb_last), 0);
|
582
|
+
|
583
|
+
rb_define_method(rb_klass, "h_prev", RUBY_METHOD_FUNC(rb_h_prev), 0);
|
584
|
+
rb_define_method(rb_klass, "h_next", RUBY_METHOD_FUNC(rb_h_next), 0);
|
585
|
+
rb_define_method(rb_klass, "v_prev", RUBY_METHOD_FUNC(rb_v_prev), 0);
|
586
|
+
rb_define_method(rb_klass, "v_next", RUBY_METHOD_FUNC(rb_v_next), 0);
|
587
|
+
|
588
|
+
rb_define_method(rb_klass, "push", RUBY_METHOD_FUNC(rb_push), -2);
|
589
|
+
rb_define_alias(rb_klass, "<<", "push");
|
590
|
+
rb_define_method(rb_klass, "pop", RUBY_METHOD_FUNC(rb_pop), 0);
|
591
|
+
rb_define_method(rb_klass, "unshift", RUBY_METHOD_FUNC(rb_unshift), -2);
|
592
|
+
rb_define_alias(rb_klass, "push_front", "unshift");
|
593
|
+
rb_define_method(rb_klass, "shift", RUBY_METHOD_FUNC(rb_shift), 0);
|
594
|
+
rb_define_alias(rb_klass, "pop_front", "shift");
|
595
|
+
rb_define_method(rb_klass, "each", RUBY_METHOD_FUNC(rb_each), 0);
|
596
|
+
rb_define_method(rb_klass, "each_index", RUBY_METHOD_FUNC(rb_each_index), 0);
|
597
|
+
rb_define_method(rb_klass, "insert", RUBY_METHOD_FUNC(rb_insert), 2);
|
598
|
+
rb_define_method(rb_klass, "remove", RUBY_METHOD_FUNC(rb_remove), 1);
|
599
|
+
rb_define_alias(rb_klass, "delete_at", "remove");
|
600
|
+
rb_define_method(rb_klass, "clear", RUBY_METHOD_FUNC(rb_clear), 0);
|
601
|
+
}
|
602
|
+
|
603
|
+
__NAMESPACE_END_CVSEQ
|
604
|
+
__NAMESPACE_END_OPENCV
|
605
|
+
|