afeld-opencv 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/Gemfile +6 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +217 -0
- data/README.rdoc +161 -0
- data/Rakefile +52 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -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/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +499 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +230 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +297 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5627 -0
- data/ext/opencv/cvmat.h +280 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +246 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +72 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +194 -0
- data/ext/opencv/cvutils.h +29 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +576 -0
- data/ext/opencv/iplimage.h +70 -0
- data/ext/opencv/lib/opencv.rb +3 -0
- data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
- data/ext/opencv/lib/opencv/version.rb +3 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +710 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +284 -0
- data/ext/opencv/pointset.h +69 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/extconf.rb +65 -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/test/helper.rb +146 -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/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 +2752 -0
- data/test/test_cvmat_drawing.rb +318 -0
- data/test/test_cvmat_dxt.rb +147 -0
- data/test/test_cvmat_imageprocessing.rb +1943 -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_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +156 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +340 -0
- data/test/test_pointset.rb +130 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +399 -0
@@ -0,0 +1,49 @@
|
|
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_initialize(int argc, VALUE *argv, VALUE self);
|
28
|
+
VALUE rb_area(VALUE self);
|
29
|
+
VALUE rb_value(VALUE self);
|
30
|
+
VALUE rb_rect(VALUE self);
|
31
|
+
VALUE rb_set_rect(VALUE self, VALUE rect);
|
32
|
+
VALUE rb_contour(VALUE self);
|
33
|
+
|
34
|
+
VALUE new_object();
|
35
|
+
VALUE new_object(CvConnectedComp comp);
|
36
|
+
|
37
|
+
__NAMESPACE_END_CVCONNECTEDCOMP
|
38
|
+
|
39
|
+
inline CvConnectedComp*
|
40
|
+
CVCONNECTEDCOMP(VALUE object)
|
41
|
+
{
|
42
|
+
CvConnectedComp *ptr;
|
43
|
+
Data_Get_Struct(object, CvConnectedComp, ptr);
|
44
|
+
return ptr;
|
45
|
+
}
|
46
|
+
|
47
|
+
__NAMESPACE_END_OPENCV
|
48
|
+
|
49
|
+
#endif // RUBY_OPENCV_CVCONNECTEDCOMP_H
|
@@ -0,0 +1,297 @@
|
|
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) rb_get_option_table(rb_klass, "APPROX_OPTION", op)
|
21
|
+
#define APPROX_POLY_METHOD(op) CVMETHOD("APPROX_POLY_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_POLY_APPROX_DP)
|
22
|
+
#define APPROX_POLY_ACCURACY(op) NUM2DBL(LOOKUP_CVMETHOD(op, "accuracy"))
|
23
|
+
#define APPROX_POLY_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
|
24
|
+
|
25
|
+
VALUE rb_allocate(VALUE klass);
|
26
|
+
void cvcontour_free(void *ptr);
|
27
|
+
|
28
|
+
VALUE rb_klass;
|
29
|
+
|
30
|
+
VALUE
|
31
|
+
rb_class()
|
32
|
+
{
|
33
|
+
return rb_klass;
|
34
|
+
}
|
35
|
+
|
36
|
+
void
|
37
|
+
define_ruby_class()
|
38
|
+
{
|
39
|
+
if (rb_klass)
|
40
|
+
return;
|
41
|
+
/*
|
42
|
+
* opencv = rb_define_module("OpenCV");
|
43
|
+
* cvseq = rb_define_class_under(opencv, "CvSeq");
|
44
|
+
* curve = rb_define_module_under(opencv, "Curve");
|
45
|
+
* pointset = rb_define_module_under(opencv, "PointSet");
|
46
|
+
*
|
47
|
+
* note: this comment is used by rdoc.
|
48
|
+
*/
|
49
|
+
VALUE opencv = rb_module_opencv();
|
50
|
+
VALUE cvseq = cCvSeq::rb_class();
|
51
|
+
VALUE curve = mCurve::rb_module();
|
52
|
+
VALUE pointset = mPointSet::rb_module();
|
53
|
+
|
54
|
+
rb_klass = rb_define_class_under(opencv, "CvContour", cvseq);
|
55
|
+
rb_include_module(rb_klass, curve);
|
56
|
+
rb_include_module(rb_klass, pointset);
|
57
|
+
|
58
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
59
|
+
|
60
|
+
VALUE approx_option = rb_hash_new();
|
61
|
+
rb_define_const(rb_klass, "APPROX_OPTION", approx_option);
|
62
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("method")), INT2FIX(CV_POLY_APPROX_DP));
|
63
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("accuracy")), rb_float_new(1.0));
|
64
|
+
rb_hash_aset(approx_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
65
|
+
|
66
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
67
|
+
rb_define_method(rb_klass, "rect", RUBY_METHOD_FUNC(rb_rect), 0);
|
68
|
+
rb_define_method(rb_klass, "color", RUBY_METHOD_FUNC(rb_color), 0);
|
69
|
+
rb_define_method(rb_klass, "color=", RUBY_METHOD_FUNC(rb_set_color), 1);
|
70
|
+
rb_define_method(rb_klass, "reserved", RUBY_METHOD_FUNC(rb_reserved), 0);
|
71
|
+
rb_define_method(rb_klass, "approx_poly", RUBY_METHOD_FUNC(rb_approx_poly), -1);
|
72
|
+
rb_define_alias(rb_klass, "approx", "approx_poly");
|
73
|
+
rb_define_method(rb_klass, "bounding_rect", RUBY_METHOD_FUNC(rb_bounding_rect), 0);
|
74
|
+
rb_define_method(rb_klass, "create_tree", RUBY_METHOD_FUNC(rb_create_tree), -1);
|
75
|
+
rb_define_method(rb_klass, "in?", RUBY_METHOD_FUNC(rb_in_q), 1);
|
76
|
+
rb_define_method(rb_klass, "measure_distance", RUBY_METHOD_FUNC(rb_measure_distance), 1);
|
77
|
+
rb_define_method(rb_klass, "point_polygon_test", RUBY_METHOD_FUNC(rb_point_polygon_test), 2);
|
78
|
+
}
|
79
|
+
|
80
|
+
VALUE
|
81
|
+
rb_allocate(VALUE klass)
|
82
|
+
{
|
83
|
+
CvContour *ptr;
|
84
|
+
return Data_Make_Struct(klass, CvContour, mark_root_object, unregister_object, ptr);
|
85
|
+
}
|
86
|
+
|
87
|
+
VALUE
|
88
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
89
|
+
{
|
90
|
+
VALUE storage;
|
91
|
+
rb_scan_args(argc, argv, "01", &storage);
|
92
|
+
|
93
|
+
if (NIL_P(storage))
|
94
|
+
storage = cCvMemStorage::new_object(0);
|
95
|
+
else
|
96
|
+
storage = CHECK_CVMEMSTORAGE(storage);
|
97
|
+
|
98
|
+
CvContour* contour = (CvContour*)DATA_PTR(self);
|
99
|
+
try {
|
100
|
+
contour = (CvContour*)cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvContour),
|
101
|
+
sizeof(CvPoint), CVMEMSTORAGE(storage));
|
102
|
+
}
|
103
|
+
catch (cv::Exception& e) {
|
104
|
+
raise_cverror(e);
|
105
|
+
}
|
106
|
+
register_root_object((CvSeq*)contour, storage);
|
107
|
+
|
108
|
+
return self;
|
109
|
+
}
|
110
|
+
|
111
|
+
VALUE
|
112
|
+
rb_rect(VALUE self)
|
113
|
+
{
|
114
|
+
return cCvRect::new_object(CVCONTOUR(self)->rect);
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE
|
118
|
+
rb_color(VALUE self)
|
119
|
+
{
|
120
|
+
return INT2NUM(CVCONTOUR(self)->color);
|
121
|
+
}
|
122
|
+
|
123
|
+
VALUE
|
124
|
+
rb_set_color(VALUE self, VALUE color)
|
125
|
+
{
|
126
|
+
CVCONTOUR(self)->color = NUM2INT(color);
|
127
|
+
return self;
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE
|
131
|
+
rb_reserved(VALUE self)
|
132
|
+
{
|
133
|
+
return rb_ary_new3(3,
|
134
|
+
INT2NUM(CVCONTOUR(self)->reserved[0]),
|
135
|
+
INT2NUM(CVCONTOUR(self)->reserved[1]),
|
136
|
+
INT2NUM(CVCONTOUR(self)->reserved[2]));
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* approx_poly(<i>approx_poly_option</i>) -> cvcontour
|
142
|
+
*
|
143
|
+
* Approximates polygonal curve(s) with desired precision.
|
144
|
+
* <i>approx_poly_option</i> should be Hash include these keys.
|
145
|
+
* :method - Approximation method.
|
146
|
+
* :dp - corresponds to Douglas-Peucker algorithm.
|
147
|
+
* :accuracy - approximation accuracy. (high-accuracy will create more simple contours)
|
148
|
+
* :recursive - (default false)
|
149
|
+
* If not nil or false, the function approximates all chains that access can be obtained to
|
150
|
+
* from self by h_next or v_next links. If 0, approximated this one.
|
151
|
+
*/
|
152
|
+
VALUE
|
153
|
+
rb_approx_poly(int argc, VALUE *argv, VALUE self)
|
154
|
+
{
|
155
|
+
VALUE approx_poly_option;
|
156
|
+
rb_scan_args(argc, argv, "01", &approx_poly_option);
|
157
|
+
approx_poly_option = APPROX_POLY_OPTION(approx_poly_option);
|
158
|
+
VALUE storage = cCvMemStorage::new_object();
|
159
|
+
CvSeq *contour = cvApproxPoly(CVCONTOUR(self), sizeof(CvContour), CVMEMSTORAGE(storage),
|
160
|
+
APPROX_POLY_METHOD(approx_poly_option),
|
161
|
+
APPROX_POLY_ACCURACY(approx_poly_option),
|
162
|
+
APPROX_POLY_RECURSIVE(approx_poly_option));
|
163
|
+
|
164
|
+
if (contour && contour->total > 0) {
|
165
|
+
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
166
|
+
}
|
167
|
+
return Qnil;
|
168
|
+
}
|
169
|
+
|
170
|
+
/*
|
171
|
+
* call-seq:
|
172
|
+
* bounding_rect -> rect
|
173
|
+
*
|
174
|
+
* Calculates up-right bounding rectangle of point set.
|
175
|
+
*
|
176
|
+
*/
|
177
|
+
VALUE
|
178
|
+
rb_bounding_rect(VALUE self)
|
179
|
+
{
|
180
|
+
CvRect rect;
|
181
|
+
try {
|
182
|
+
rect = cvBoundingRect(CVCONTOUR(self), 1);
|
183
|
+
}
|
184
|
+
catch (cv::Exception& e) {
|
185
|
+
raise_cverror(e);
|
186
|
+
}
|
187
|
+
return cCvRect::new_object(rect);
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* call-seq:
|
192
|
+
* create_tree([threshold = 0.0]) -> cvcontourtree
|
193
|
+
*
|
194
|
+
* Creates hierarchical representation of contour.
|
195
|
+
* If the parameter <i>threshold</i> is less than or equal to 0,
|
196
|
+
* the method creates full binary tree representation.
|
197
|
+
* If the threshold is greater than 0, the function creates
|
198
|
+
* representation with the precision threshold:
|
199
|
+
*/
|
200
|
+
VALUE
|
201
|
+
rb_create_tree(int argc, VALUE *argv, VALUE self)
|
202
|
+
{
|
203
|
+
VALUE threshold, storage;
|
204
|
+
rb_scan_args(argc, argv, "01", &threshold);
|
205
|
+
storage = cCvMemStorage::new_object();
|
206
|
+
CvContourTree *tree = NULL;
|
207
|
+
try {
|
208
|
+
tree = cvCreateContourTree(CVSEQ(self), CVMEMSTORAGE(storage), IF_DBL(threshold, 0.0));
|
209
|
+
}
|
210
|
+
catch (cv::Exception& e) {
|
211
|
+
raise_cverror(e);
|
212
|
+
}
|
213
|
+
return cCvSeq::new_sequence(cCvContourTree::rb_class(), (CvSeq*)tree, cCvPoint::rb_class(), storage);
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* call-seq:
|
218
|
+
* in?(<i>point</i>) -> true or nil or false
|
219
|
+
*
|
220
|
+
* Determines whether the <i>point</i> is inside contour(true), outside(false) or lies on an edge(nil).
|
221
|
+
*/
|
222
|
+
VALUE
|
223
|
+
rb_in_q(VALUE self, VALUE point)
|
224
|
+
{
|
225
|
+
double n = 0;
|
226
|
+
try {
|
227
|
+
n = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 0);
|
228
|
+
}
|
229
|
+
catch (cv::Exception& e) {
|
230
|
+
raise_cverror(e);
|
231
|
+
}
|
232
|
+
return n == 0 ? Qnil : n > 0 ? Qtrue : Qfalse;
|
233
|
+
}
|
234
|
+
|
235
|
+
/*
|
236
|
+
* call-seq:
|
237
|
+
* measure_distance(<i>point</i>) -> float
|
238
|
+
*
|
239
|
+
* Return distance between the point and the nearest contour edge.
|
240
|
+
*/
|
241
|
+
VALUE
|
242
|
+
rb_measure_distance(VALUE self, VALUE point)
|
243
|
+
{
|
244
|
+
double distance = 0;
|
245
|
+
try {
|
246
|
+
distance = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), 1);
|
247
|
+
}
|
248
|
+
catch (cv::Exception& e) {
|
249
|
+
raise_cverror(e);
|
250
|
+
}
|
251
|
+
return rb_float_new(distance);
|
252
|
+
}
|
253
|
+
|
254
|
+
/*
|
255
|
+
* call-seq:
|
256
|
+
* point_polygon_test(<i>point, measure_dist</i>) -> float
|
257
|
+
*
|
258
|
+
* Determines whether the point is inside a contour, outside, or lies on an edge (or coinsides with a vertex).
|
259
|
+
* It returns positive, negative or zero value, correspondingly. When measure_dist = false or 0, the return value is +1, -1 and 0, respectively. When measure_dist = true or 1, it is a signed distance between the point and the nearest contour edge.
|
260
|
+
*/
|
261
|
+
VALUE
|
262
|
+
rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist)
|
263
|
+
{
|
264
|
+
int measure_dist_flag;
|
265
|
+
|
266
|
+
if (measure_dist == Qtrue)
|
267
|
+
measure_dist_flag = 1;
|
268
|
+
else if (measure_dist == Qfalse)
|
269
|
+
measure_dist_flag = 0;
|
270
|
+
else
|
271
|
+
measure_dist_flag = NUM2INT(measure_dist);
|
272
|
+
|
273
|
+
double dist = Qnil;
|
274
|
+
try {
|
275
|
+
dist = cvPointPolygonTest(CVARR(self), VALUE_TO_CVPOINT2D32F(point), measure_dist_flag);
|
276
|
+
}
|
277
|
+
catch (cv::Exception& e) {
|
278
|
+
raise_cverror(e);
|
279
|
+
}
|
280
|
+
|
281
|
+
/* cvPointPolygonTest returns 100, -100 or 0 when measure_dist = 0 */
|
282
|
+
if ((!measure_dist_flag) && ((int)dist) != 0)
|
283
|
+
dist = (dist > 0) ? 1 : -1;
|
284
|
+
|
285
|
+
return rb_float_new(dist);
|
286
|
+
}
|
287
|
+
|
288
|
+
VALUE new_object()
|
289
|
+
{
|
290
|
+
VALUE object = rb_allocate(rb_klass);
|
291
|
+
rb_initialize(0, NULL, object);
|
292
|
+
return object;
|
293
|
+
}
|
294
|
+
|
295
|
+
__NAMESPACE_END_CVCONTOUR
|
296
|
+
__NAMESPACE_END_OPENCV
|
297
|
+
|
@@ -0,0 +1,48 @@
|
|
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
|
+
VALUE rb_point_polygon_test(VALUE self, VALUE point, VALUE measure_dist);
|
35
|
+
|
36
|
+
VALUE new_object();
|
37
|
+
__NAMESPACE_END_CVCONTOUR
|
38
|
+
|
39
|
+
inline CvContour*
|
40
|
+
CVCONTOUR(VALUE object){
|
41
|
+
CvContour *ptr;
|
42
|
+
Data_Get_Struct(object, CvContour, ptr);
|
43
|
+
return ptr;
|
44
|
+
}
|
45
|
+
|
46
|
+
__NAMESPACE_END_OPENCV
|
47
|
+
|
48
|
+
#endif // RUBY_OPENCV_CVCONTOUR_H
|
@@ -0,0 +1,91 @@
|
|
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), 1);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE
|
56
|
+
rb_p1(VALUE self)
|
57
|
+
{
|
58
|
+
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p1, self);
|
59
|
+
}
|
60
|
+
|
61
|
+
VALUE
|
62
|
+
rb_p2(VALUE self)
|
63
|
+
{
|
64
|
+
return REFER_OBJECT(cCvPoint::rb_class(), &CVCONTOURTREE(self)->p2, self);
|
65
|
+
}
|
66
|
+
|
67
|
+
/*
|
68
|
+
* call-seq:
|
69
|
+
* contour(<i>[criteria = 0]</i>) -> cvcontour
|
70
|
+
*
|
71
|
+
* Restores the contour from its binary tree representation.
|
72
|
+
* The parameter criteria determines the accuracy and/or the number of tree levels
|
73
|
+
* used for reconstruction, so it is possible to build approximated contour.
|
74
|
+
*/
|
75
|
+
VALUE
|
76
|
+
rb_contour(VALUE self, VALUE criteria)
|
77
|
+
{
|
78
|
+
VALUE storage = cCvMemStorage::new_object();
|
79
|
+
CvSeq *contour = NULL;
|
80
|
+
try {
|
81
|
+
contour = cvContourFromContourTree(CVCONTOURTREE(self), CVMEMSTORAGE(storage),
|
82
|
+
VALUE_TO_CVTERMCRITERIA(criteria));
|
83
|
+
}
|
84
|
+
catch (cv::Exception& e) {
|
85
|
+
raise_cverror(e);
|
86
|
+
}
|
87
|
+
return cCvSeq::new_sequence(cCvContour::rb_class(), contour, cCvPoint::rb_class(), storage);
|
88
|
+
}
|
89
|
+
|
90
|
+
__NAMESPACE_END_CVCONTOURTREE
|
91
|
+
__NAMESPACE_END_OPENCV
|