bantic-ruby-opencv 0.0.8
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/CHANGELOG +2 -0
- data/License.txt +30 -0
- data/README.rdoc +90 -0
- data/Rakefile +15 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +24 -0
- data/examples/houghcircle.rb +23 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +42 -0
- data/examples/paint.rb +71 -0
- data/examples/snake.rb +42 -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 +217 -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 +58 -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/metadata +191 -0
- data/ruby-opencv.gemspec +33 -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 +6 -0
- metadata +272 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvconnectedcomp.h -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2005-2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#ifndef RUBY_OPENCV_CVCONNECTEDCOMP_H
|
|
11
|
+
#define RUBY_OPENCV_CVCONNECTEDCOMP_H
|
|
12
|
+
|
|
13
|
+
#include "opencv.h"
|
|
14
|
+
|
|
15
|
+
#define __NAMESPACE_BEGIN_CVCONNECTEDCOMP namespace cCvConnectedComp{
|
|
16
|
+
#define __NAMESPACE_END_CVCONNECTEDCOMP }
|
|
17
|
+
|
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
19
|
+
__NAMESPACE_BEGIN_CVCONNECTEDCOMP
|
|
20
|
+
|
|
21
|
+
VALUE rb_class();
|
|
22
|
+
|
|
23
|
+
void define_ruby_class();
|
|
24
|
+
|
|
25
|
+
VALUE rb_allocate(VALUE klass);
|
|
26
|
+
|
|
27
|
+
VALUE rb_area(VALUE self);
|
|
28
|
+
VALUE rb_value(VALUE self);
|
|
29
|
+
VALUE rb_rect(VALUE self);
|
|
30
|
+
VALUE rb_set_rect(VALUE self, VALUE rect);
|
|
31
|
+
VALUE rb_contour(VALUE self);
|
|
32
|
+
|
|
33
|
+
VALUE new_object();
|
|
34
|
+
VALUE new_object(CvConnectedComp comp);
|
|
35
|
+
|
|
36
|
+
__NAMESPACE_END_CVCONNECTEDCOMP
|
|
37
|
+
|
|
38
|
+
inline CvConnectedComp *CVCONNECTEDCOMP(VALUE object){
|
|
39
|
+
CvConnectedComp *ptr;
|
|
40
|
+
Data_Get_Struct(object, CvConnectedComp, ptr);
|
|
41
|
+
return ptr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
__NAMESPACE_END_OPENCV
|
|
45
|
+
|
|
46
|
+
#endif // RUBY_OPENCV_CVCONNECTEDCOMP_H
|
data/ext/cvcontour.cpp
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvcontour.cpp -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#include "cvcontour.h"
|
|
11
|
+
/*
|
|
12
|
+
* Document-class: OpenCV::CvContour
|
|
13
|
+
*
|
|
14
|
+
* Contour.
|
|
15
|
+
* CvMat#find_contours
|
|
16
|
+
*/
|
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
18
|
+
__NAMESPACE_BEGIN_CVCONTOUR
|
|
19
|
+
|
|
20
|
+
#define APPROX_POLY_OPTION(op) NIL_P(op) ? rb_const_get(rb_class(), rb_intern("APPROX_OPTION")) : rb_funcall(rb_const_get(rb_class(), rb_intern("APPROX_OPTION")), rb_intern("merge"), 1, op)
|
|
21
|
+
#define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", rb_hash_aref(op, ID2SYM(rb_intern("method"))), CV_POLY_APPROX_DP)
|
|
22
|
+
#define APPROX_POLY_ACCURACY(op) NUM2DBL(rb_hash_aref(op, ID2SYM(rb_intern("accuracy"))))
|
|
23
|
+
#define APPROX_POLY_RECURSIVE(op) ({VALUE _recursive = rb_hash_aref(op, ID2SYM(rb_intern("recursive"))); NIL_P(_recursive) ? 0 : _recursive == Qfalse ? 0 : 1;})
|
|
24
|
+
|
|
25
|
+
VALUE rb_klass;
|
|
26
|
+
|
|
27
|
+
VALUE
|
|
28
|
+
rb_class()
|
|
29
|
+
{
|
|
30
|
+
return rb_klass;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void
|
|
34
|
+
define_ruby_class()
|
|
35
|
+
{
|
|
36
|
+
if (rb_klass)
|
|
37
|
+
return;
|
|
38
|
+
/*
|
|
39
|
+
* opencv = rb_define_module("OpenCV");
|
|
40
|
+
* cvseq = rb_define_class_under(opencv, "CvSeq");
|
|
41
|
+
* curve = rb_define_module_under(opencv, "Curve");
|
|
42
|
+
* pointset = rb_define_module_under(opencv, "PointSet");
|
|
43
|
+
*
|
|
44
|
+
* note: this comment is used by rdoc.
|
|
45
|
+
*/
|
|
46
|
+
VALUE opencv = rb_module_opencv();
|
|
47
|
+
VALUE cvseq = cCvSeq::rb_class();
|
|
48
|
+
VALUE curve = mCurve::rb_module();
|
|
49
|
+
VALUE pointset = mPointSet::rb_module();
|
|
50
|
+
|
|
51
|
+
rb_klass = rb_define_class_under(opencv, "CvContour", cvseq);
|
|
52
|
+
rb_include_module(rb_klass, curve);
|
|
53
|
+
rb_include_module(rb_klass, pointset);
|
|
54
|
+
|
|
55
|
+
VALUE approx_option = rb_hash_new();
|
|
56
|
+
rb_define_const(rb_klass, "APPROX_OPTION", approx_option);
|
|
57
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("method")), INT2FIX(CV_POLY_APPROX_DP));
|
|
58
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("accuracy")), rb_float_new(1.0));
|
|
59
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
|
60
|
+
|
|
61
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
|
62
|
+
rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
|
|
63
|
+
rb_define_method(rb_klass, "color", RUBY_METHOD_FUNC(rb_color), 0);
|
|
64
|
+
rb_define_method(rb_klass, "color=", RUBY_METHOD_FUNC(rb_set_color), 1);
|
|
65
|
+
rb_define_method(rb_klass, "reserved", RUBY_METHOD_FUNC(rb_reserved), 0);
|
|
66
|
+
rb_define_method(rb_klass, "approx_poly", RUBY_METHOD_FUNC(rb_approx_poly), -1);
|
|
67
|
+
rb_define_alias(rb_klass, "approx", "approx_poly");
|
|
68
|
+
rb_define_method(rb_klass, "bounding_rect", RUBY_METHOD_FUNC(rb_bounding_rect), 0);
|
|
69
|
+
rb_define_method(rb_klass, "create_tree", RUBY_METHOD_FUNC(rb_create_tree), -1);
|
|
70
|
+
rb_define_method(rb_klass, "in?", RUBY_METHOD_FUNC(rb_in_q), 1);
|
|
71
|
+
rb_define_method(rb_klass, "measure_distance", RUBY_METHOD_FUNC(rb_measure_distance), 1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
VALUE
|
|
75
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
|
76
|
+
{
|
|
77
|
+
/*
|
|
78
|
+
VALUE storage;
|
|
79
|
+
CvSeq *seq = 0;
|
|
80
|
+
rb_scan_args(argc, argv, "01", &storage);
|
|
81
|
+
|
|
82
|
+
storage = CHECK_CVMEMSTORAGE(storage);
|
|
83
|
+
seq = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), CVMEMSTORAGE(storage));
|
|
84
|
+
DATA_PTR(self) = seq;
|
|
85
|
+
resist_root_object(seq, storage);
|
|
86
|
+
st_insert(cCvSeq::seqblock_klass, (st_data_t)seq, (st_data_t)klass);
|
|
87
|
+
*/
|
|
88
|
+
return self;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
VALUE
|
|
92
|
+
rb_rect(VALUE self)
|
|
93
|
+
{
|
|
94
|
+
return cCvRect::new_object(CVCONTOUR(self)->rect);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
VALUE
|
|
98
|
+
rb_color(VALUE self)
|
|
99
|
+
{
|
|
100
|
+
return INT2NUM(CVCONTOUR(self)->color);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
VALUE
|
|
104
|
+
rb_set_color(VALUE self, VALUE color)
|
|
105
|
+
{
|
|
106
|
+
CVCONTOUR(self)->color = NUM2INT(color);
|
|
107
|
+
return self;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
VALUE
|
|
111
|
+
rb_reserved(VALUE self)
|
|
112
|
+
{
|
|
113
|
+
return rb_ary_new3(3,
|
|
114
|
+
INT2NUM(CVCONTOUR(self)->reserved[0]),
|
|
115
|
+
INT2NUM(CVCONTOUR(self)->reserved[1]),
|
|
116
|
+
INT2NUM(CVCONTOUR(self)->reserved[2]));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* call-seq:
|
|
121
|
+
* approx_poly(<i>approx_poly_option</i>) -> cvcontour
|
|
122
|
+
*
|
|
123
|
+
* Approximates polygonal curve(s) with desired precision.
|
|
124
|
+
* <i>approx_poly_option</i> should be Hash include these keys.
|
|
125
|
+
* :method - Approximation method.
|
|
126
|
+
* :dp - corresponds to Douglas-Peucker algorithm.
|
|
127
|
+
* :accuracy - approximation accuracy. (high-accuracy will create more simple contours)
|
|
128
|
+
* :recursive - (default false)
|
|
129
|
+
* If not nil or false, the function approximates all chains that access can be obtained to
|
|
130
|
+
* from self by h_next or v_next links. If 0, approximated this one.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
VALUE
|
|
134
|
+
rb_approx_poly(int argc, VALUE *argv, VALUE self)
|
|
135
|
+
{
|
|
136
|
+
VALUE approx_poly_option, storage;
|
|
137
|
+
rb_scan_args(argc, argv, "01", &approx_poly_option);
|
|
138
|
+
approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
|
|
139
|
+
storage = cCvMemStorage::new_object();
|
|
140
|
+
|
|
141
|
+
CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
|
|
142
|
+
APPROX_POLY_METHOD(approx_poly_option),
|
|
143
|
+
APPROX_POLY_ACCURACY(approx_poly_option),
|
|
144
|
+
APPROX_POLY_RECURSIVE(approx_poly_option));
|
|
145
|
+
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* call-seq:
|
|
150
|
+
* bounding_rect -> rect
|
|
151
|
+
*
|
|
152
|
+
* Calculates up-right bounding rectangle of point set.
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
VALUE
|
|
156
|
+
rb_bounding_rect(VALUE self)
|
|
157
|
+
{
|
|
158
|
+
return cCvRect::new_object(cvBoundingRect(CVCONTOUR(self), 1));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*
|
|
162
|
+
* call-seq:
|
|
163
|
+
* create_tree([threshold = 0.0]) -> cvcontourtree
|
|
164
|
+
*
|
|
165
|
+
* Creates hierarchical representation of contour.
|
|
166
|
+
* If the parameter <i>threshold</i> is less than or equal to 0,
|
|
167
|
+
* the method creates full binary tree representation.
|
|
168
|
+
* If the threshold is greater than 0, the function creates
|
|
169
|
+
* representation with the precision threshold:
|
|
170
|
+
*/
|
|
171
|
+
VALUE
|
|
172
|
+
rb_create_tree(int argc, VALUE *argv, VALUE self)
|
|
173
|
+
{
|
|
174
|
+
VALUE threshold, storage;
|
|
175
|
+
rb_scan_args(argc, argv, "01", &threshold);
|
|
176
|
+
storage = cCvMemStorage::new_object();
|
|
177
|
+
CvContourTree *tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
|
|
178
|
+
return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/*
|
|
182
|
+
* call-seq:
|
|
183
|
+
* in?(<i>point</i>) -> true or nil or false
|
|
184
|
+
*
|
|
185
|
+
* Determines whether the <i>point</i> is inside contour(true), outside(false), or lies on an edge(nil).
|
|
186
|
+
*/
|
|
187
|
+
VALUE
|
|
188
|
+
rb_in_q(VALUE self, VALUE point)
|
|
189
|
+
{
|
|
190
|
+
double n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
|
|
191
|
+
return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* call-seq:
|
|
196
|
+
* measure_distance(<i>point</i>) -> float
|
|
197
|
+
*
|
|
198
|
+
* Return distance between the point and the nearest contour edge.
|
|
199
|
+
*/
|
|
200
|
+
VALUE
|
|
201
|
+
rb_measure_distance(VALUE self, VALUE point)
|
|
202
|
+
{
|
|
203
|
+
return rb_float_new(cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
VALUE new_object()
|
|
208
|
+
{
|
|
209
|
+
VALUE storage = cCvMemStorage::new_object();
|
|
210
|
+
CvSeq *seq = cvCreateSeq(CV_SEQ_CONTOUR, sizeof(CvContour), sizeof(CvPoint), CVMEMSTORAGE(storage));
|
|
211
|
+
VALUE object = cCvSeq::new_sequence(cCvContour::rb_class(), seq, cCvPoint::rb_class(), storage);
|
|
212
|
+
return object;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
__NAMESPACE_END_CVCONTOUR
|
|
216
|
+
__NAMESPACE_END_OPENCV
|
|
217
|
+
|
data/ext/cvcontour.h
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvcontour.h -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#ifndef RUBY_OPENCV_CVCONTOUR_H
|
|
11
|
+
#define RUBY_OPENCV_CVCONTOUR_H
|
|
12
|
+
#include "opencv.h"
|
|
13
|
+
|
|
14
|
+
#define __NAMESPACE_BEGIN_CVCONTOUR namespace cCvContour{
|
|
15
|
+
#define __NAMESPACE_END_CVCONTOUR }
|
|
16
|
+
|
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
18
|
+
__NAMESPACE_BEGIN_CVCONTOUR
|
|
19
|
+
|
|
20
|
+
VALUE rb_class();
|
|
21
|
+
|
|
22
|
+
void define_ruby_class();
|
|
23
|
+
|
|
24
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
|
25
|
+
VALUE rb_rect(VALUE self);
|
|
26
|
+
VALUE rb_color(VALUE self);
|
|
27
|
+
VALUE rb_set_color(VALUE self, VALUE color);
|
|
28
|
+
VALUE rb_reserved(VALUE self);
|
|
29
|
+
VALUE rb_approx_poly(int argc, VALUE *argv, VALUE self);
|
|
30
|
+
VALUE rb_bounding_rect(VALUE self);
|
|
31
|
+
VALUE rb_create_tree(int argc, VALUE *argv, VALUE self);
|
|
32
|
+
VALUE rb_in_q(VALUE self, VALUE point);
|
|
33
|
+
VALUE rb_measure_distance(VALUE self, VALUE point);
|
|
34
|
+
|
|
35
|
+
VALUE new_object();
|
|
36
|
+
__NAMESPACE_END_CVCONTOUR
|
|
37
|
+
|
|
38
|
+
inline CvContour*
|
|
39
|
+
CVCONTOUR(VALUE object){
|
|
40
|
+
CvContour *ptr;
|
|
41
|
+
Data_Get_Struct(object, CvContour, ptr);
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
__NAMESPACE_END_OPENCV
|
|
46
|
+
|
|
47
|
+
#endif // RUBY_OPENCV_CVCONTOUR_H
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvcontourtree.cpp -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#include "cvcontour.h"
|
|
11
|
+
/*
|
|
12
|
+
* Document-class: OpenCV::CvContourTree
|
|
13
|
+
*
|
|
14
|
+
* Contour tree. CvContour#create_tree
|
|
15
|
+
*
|
|
16
|
+
* C structure is here.
|
|
17
|
+
* typedef struct CvContourTree{
|
|
18
|
+
* CV_SEQUENCE_FIELDS()
|
|
19
|
+
* CvPoint p1;
|
|
20
|
+
* CvPoint p2;
|
|
21
|
+
* }CvContourTree;
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
25
|
+
__NAMESPACE_BEGIN_CVCONTOURTREE
|
|
26
|
+
|
|
27
|
+
VALUE rb_klass;
|
|
28
|
+
|
|
29
|
+
VALUE
|
|
30
|
+
rb_class()
|
|
31
|
+
{
|
|
32
|
+
return rb_klass;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void
|
|
36
|
+
define_ruby_class()
|
|
37
|
+
{
|
|
38
|
+
if (rb_klass)
|
|
39
|
+
return;
|
|
40
|
+
/*
|
|
41
|
+
* opencv = rb_define_module("OpenCV");
|
|
42
|
+
* cvseq = rb_define_class_under(opencv, "CvSeq");
|
|
43
|
+
*
|
|
44
|
+
* note: this comment is used by rdoc.
|
|
45
|
+
*/
|
|
46
|
+
VALUE opencv = rb_module_opencv();
|
|
47
|
+
VALUE cvseq = cCvSeq::rb_class();
|
|
48
|
+
|
|
49
|
+
rb_klass = rb_define_class_under(opencv, "CvContourTree", cvseq);
|
|
50
|
+
rb_define_method(rb_klass, "p1", RUBY_METHOD_FUNC(rb_p1), 0);
|
|
51
|
+
rb_define_method(rb_klass, "p2", RUBY_METHOD_FUNC(rb_p2), 0);
|
|
52
|
+
rb_define_method(rb_klass, "contour", RUBY_METHOD_FUNC(rb_contour), 0);
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
VALUE
|
|
57
|
+
rb_p1(VALUE self)
|
|
58
|
+
{
|
|
59
|
+
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p1, self);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
VALUE
|
|
63
|
+
rb_p2(VALUE self)
|
|
64
|
+
{
|
|
65
|
+
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p2, self);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* call-seq:
|
|
70
|
+
* contour(<i>[criteria = 0]</i>) -> cvcontour
|
|
71
|
+
*
|
|
72
|
+
* Restores the contour from its binary tree representation.
|
|
73
|
+
* The parameter criteria determines the accuracy and/or the number of tree levels
|
|
74
|
+
* used for reconstruction, so it is possible to build approximated contour.
|
|
75
|
+
*/
|
|
76
|
+
VALUE
|
|
77
|
+
rb_contour(int argc, VALUE *argv, VALUE self)
|
|
78
|
+
{
|
|
79
|
+
VALUE criteria, storage;
|
|
80
|
+
rb_scan_args(argc, argv, "01", &criteria);
|
|
81
|
+
CvSeq *contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage), VALUE_TO_CVTERMCRITERIA(criteria));
|
|
82
|
+
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
__NAMESPACE_END_CVCONTOURTREE
|
|
86
|
+
__NAMESPACE_END_OPENCV
|
data/ext/cvcontourtree.h
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvcontourtree.h -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#ifndef RUBY_OPENCV_CVCONTOURTREE_H
|
|
11
|
+
#define RUBY_OPENCV_CVCONTOURTREE_H
|
|
12
|
+
#include "opencv.h"
|
|
13
|
+
|
|
14
|
+
#define __NAMESPACE_BEGIN_CVCONTOURTREE namespace cCvContourTree{
|
|
15
|
+
#define __NAMESPACE_END_CVCONTOURTREE }
|
|
16
|
+
|
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
18
|
+
__NAMESPACE_BEGIN_CVCONTOURTREE
|
|
19
|
+
|
|
20
|
+
VALUE rb_class();
|
|
21
|
+
|
|
22
|
+
void define_ruby_class();
|
|
23
|
+
|
|
24
|
+
VALUE rb_p1(VALUE self);
|
|
25
|
+
VALUE rb_p2(VALUE self);
|
|
26
|
+
VALUE rb_contour(int argc, VALUE *argv, VALUE self);
|
|
27
|
+
|
|
28
|
+
VALUE new_object();
|
|
29
|
+
|
|
30
|
+
__NAMESPACE_END_CVCONTOURTREE
|
|
31
|
+
|
|
32
|
+
inline CvContourTree*
|
|
33
|
+
CVCONTOURTREE(VALUE object){
|
|
34
|
+
CvContourTree *ptr;
|
|
35
|
+
Data_Get_Struct(object, CvContourTree, ptr);
|
|
36
|
+
return ptr;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
__NAMESPACE_END_OPENCV
|
|
40
|
+
|
|
41
|
+
#endif // RUBY_OPENCV_CVCONTOUR_H
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
cvconvexitydefect.cpp -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#include "cvconvexitydefect.h"
|
|
11
|
+
/*
|
|
12
|
+
* Document-class: OpenCV::CvConvexityDefect
|
|
13
|
+
*
|
|
14
|
+
* Convexity.
|
|
15
|
+
* C structure is here.
|
|
16
|
+
* typedef struct CvConvexityDefect {
|
|
17
|
+
* CvPoint* start;
|
|
18
|
+
* CvPoint* end;
|
|
19
|
+
* CvPoint* depth_point;
|
|
20
|
+
* float depth;
|
|
21
|
+
* }CvConvexityDefect;
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
25
|
+
__NAMESPACE_BEGIN_CVCONVEXITYDEFECT
|
|
26
|
+
|
|
27
|
+
VALUE rb_klass;
|
|
28
|
+
|
|
29
|
+
VALUE
|
|
30
|
+
rb_class()
|
|
31
|
+
{
|
|
32
|
+
return rb_klass;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void
|
|
36
|
+
define_ruby_class()
|
|
37
|
+
{
|
|
38
|
+
if (rb_klass)
|
|
39
|
+
return;
|
|
40
|
+
/*
|
|
41
|
+
* opencv = rb_define_module("OpenCV");
|
|
42
|
+
*
|
|
43
|
+
* note: this comment is used by rdoc.
|
|
44
|
+
*/
|
|
45
|
+
VALUE opencv = rb_module_opencv();
|
|
46
|
+
|
|
47
|
+
rb_klass = rb_define_class_under(opencv, "CvConvexityDefect", rb_cObject);
|
|
48
|
+
rb_define_method(rb_klass, "start", RUBY_METHOD_FUNC(rb_start), 0);
|
|
49
|
+
rb_define_method(rb_klass, "end", RUBY_METHOD_FUNC(rb_end), 0);
|
|
50
|
+
rb_define_method(rb_klass, "depth_point", RUBY_METHOD_FUNC(rb_depth_point), 0);
|
|
51
|
+
rb_define_method(rb_klass, "depth", RUBY_METHOD_FUNC(rb_depth), 0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* call-seq:
|
|
56
|
+
* start -> cvpoint
|
|
57
|
+
*
|
|
58
|
+
* Return start point as CvPoint.
|
|
59
|
+
*/
|
|
60
|
+
VALUE
|
|
61
|
+
rb_start(VALUE self)
|
|
62
|
+
{
|
|
63
|
+
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->start);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* call-seq:
|
|
68
|
+
* end -> cvpoint
|
|
69
|
+
*
|
|
70
|
+
* Return end point as CvPoint.
|
|
71
|
+
*/
|
|
72
|
+
VALUE
|
|
73
|
+
rb_end(VALUE self)
|
|
74
|
+
{
|
|
75
|
+
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->end);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* call-seq:
|
|
80
|
+
* depth_point -> cvpoint
|
|
81
|
+
*
|
|
82
|
+
* Return depth point as CvPoint.
|
|
83
|
+
*/
|
|
84
|
+
VALUE
|
|
85
|
+
rb_depth_point(VALUE self)
|
|
86
|
+
{
|
|
87
|
+
return cCvPoint::new_object(*CVCONVEXITYDEFECT(self)->depth_point);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* call-seq:
|
|
92
|
+
* depth -> float
|
|
93
|
+
*
|
|
94
|
+
* Return depth.
|
|
95
|
+
*/
|
|
96
|
+
VALUE
|
|
97
|
+
rb_depth(VALUE self)
|
|
98
|
+
{
|
|
99
|
+
return rb_float_new(CVCONVEXITYDEFECT(self)->depth);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
__NAMESPACE_END_CVCONVEXITYDEFECT
|
|
103
|
+
__NAMESPACE_END_OPENCV
|