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,72 @@
|
|
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 cvcapture_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_get_millisecond(VALUE self);
|
34
|
+
VALUE rb_set_millisecond(VALUE self, VALUE value);
|
35
|
+
VALUE rb_get_frames(VALUE self);
|
36
|
+
VALUE rb_set_frames(VALUE self, VALUE value);
|
37
|
+
VALUE rb_get_avi_ratio(VALUE self);
|
38
|
+
VALUE rb_set_avi_ratio(VALUE self, VALUE value);
|
39
|
+
VALUE rb_get_size(VALUE self);
|
40
|
+
VALUE rb_set_size(VALUE self, VALUE value);
|
41
|
+
VALUE rb_get_width(VALUE self);
|
42
|
+
VALUE rb_set_width(VALUE self, VALUE value);
|
43
|
+
VALUE rb_get_height(VALUE self);
|
44
|
+
VALUE rb_set_height(VALUE self, VALUE value);
|
45
|
+
VALUE rb_get_fps(VALUE self);
|
46
|
+
VALUE rb_set_fps(VALUE self, VALUE value);
|
47
|
+
VALUE rb_get_fourcc(VALUE self);
|
48
|
+
VALUE rb_get_frame_count(VALUE self);
|
49
|
+
VALUE rb_get_format(VALUE self);
|
50
|
+
VALUE rb_get_mode(VALUE self);
|
51
|
+
VALUE rb_get_brightness(VALUE self);
|
52
|
+
VALUE rb_get_contrast(VALUE self);
|
53
|
+
VALUE rb_get_saturation(VALUE self);
|
54
|
+
VALUE rb_get_hue(VALUE self);
|
55
|
+
VALUE rb_get_gain(VALUE self);
|
56
|
+
VALUE rb_get_exposure(VALUE self);
|
57
|
+
VALUE rb_get_convert_rgb(VALUE self);
|
58
|
+
VALUE rb_get_rectification(VALUE self);
|
59
|
+
|
60
|
+
__NAMESPACE_END_CVCAPTURE
|
61
|
+
|
62
|
+
|
63
|
+
inline CvCapture*
|
64
|
+
CVCAPTURE(VALUE object) {
|
65
|
+
CvCapture *ptr;
|
66
|
+
Data_Get_Struct(object, CvCapture, ptr);
|
67
|
+
return ptr;
|
68
|
+
}
|
69
|
+
|
70
|
+
__NAMESPACE_END_OPENCV
|
71
|
+
|
72
|
+
#endif // RUBY_OPENCV_CVCAPTURE_H
|
@@ -0,0 +1,230 @@
|
|
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) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
|
21
|
+
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_CVMETHOD(op, "method"), CV_CHAIN_APPROX_SIMPLE)
|
22
|
+
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "parameter"))
|
23
|
+
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_CVMETHOD(op, "minimal_perimeter"))
|
24
|
+
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_CVMETHOD(op, "recursive"))
|
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_perimeter")), INT2FIX(0));
|
56
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
57
|
+
|
58
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
59
|
+
rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
|
60
|
+
rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 1);
|
61
|
+
rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
|
62
|
+
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
63
|
+
rb_define_method(rb_klass, "approx_chains", RUBY_METHOD_FUNC(rb_approx_chains), -1);
|
64
|
+
rb_define_alias(rb_klass, "approx", "approx_chains");
|
65
|
+
}
|
66
|
+
|
67
|
+
VALUE
|
68
|
+
rb_allocate(VALUE klass)
|
69
|
+
{
|
70
|
+
CvChain *ptr;
|
71
|
+
return Data_Make_Struct(klass, CvChain, 0, 0, ptr);
|
72
|
+
}
|
73
|
+
|
74
|
+
VALUE
|
75
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
76
|
+
{
|
77
|
+
CvMemStorage *storage;
|
78
|
+
VALUE storage_value;
|
79
|
+
if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
|
80
|
+
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
81
|
+
storage = CVMEMSTORAGE(storage_value);
|
82
|
+
}
|
83
|
+
else
|
84
|
+
storage = rb_cvCreateMemStorage(0);
|
85
|
+
try {
|
86
|
+
DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
|
87
|
+
sizeof(char), storage);
|
88
|
+
}
|
89
|
+
catch (cv::Exception& e) {
|
90
|
+
raise_cverror(e);
|
91
|
+
}
|
92
|
+
return self;
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
* call-seq:
|
97
|
+
* origin -> cvpoint
|
98
|
+
*
|
99
|
+
* Return Freeman chain code origin.
|
100
|
+
*/
|
101
|
+
VALUE
|
102
|
+
rb_origin(VALUE self)
|
103
|
+
{
|
104
|
+
return cCvPoint::new_object(CVCHAIN(self)->origin);
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* origin = point -> self
|
110
|
+
*
|
111
|
+
* Set Freeman chain code origin.
|
112
|
+
*/
|
113
|
+
VALUE
|
114
|
+
rb_set_origin(VALUE self, VALUE origin)
|
115
|
+
{
|
116
|
+
CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
|
117
|
+
return self;
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* call-seq:
|
122
|
+
* codes -> array(contain fixnum)
|
123
|
+
*
|
124
|
+
* Return Freeman chain codes.
|
125
|
+
*/
|
126
|
+
VALUE
|
127
|
+
rb_codes(VALUE self)
|
128
|
+
{
|
129
|
+
CvChain *chain = CVCHAIN(self);
|
130
|
+
CvChainPtReader reader;
|
131
|
+
int total = chain->total;
|
132
|
+
VALUE ary = rb_ary_new2(total);
|
133
|
+
try {
|
134
|
+
cvStartReadChainPoints(chain, &reader);
|
135
|
+
for (int i = 0; i < total; ++i) {
|
136
|
+
CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
|
137
|
+
rb_ary_store(ary, i, CHR2FIX(reader.code));
|
138
|
+
}
|
139
|
+
}
|
140
|
+
catch (cv::Exception& e) {
|
141
|
+
raise_cverror(e);
|
142
|
+
}
|
143
|
+
return ary;
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
* call-seq:
|
148
|
+
* points -> array(contain cvpoint)
|
149
|
+
*
|
150
|
+
* Return points that represent by Freeman chain code.
|
151
|
+
*/
|
152
|
+
VALUE
|
153
|
+
rb_points(VALUE self)
|
154
|
+
{
|
155
|
+
CvChain *chain = CVCHAIN(self);
|
156
|
+
CvChainPtReader reader;
|
157
|
+
CvPoint p = chain->origin;
|
158
|
+
int total = chain->total;
|
159
|
+
VALUE ary = rb_ary_new2(total);
|
160
|
+
try {
|
161
|
+
cvStartReadChainPoints(chain, &reader);
|
162
|
+
for (int i = 0; i < total; ++i) {
|
163
|
+
CV_READ_CHAIN_POINT(p, reader);
|
164
|
+
rb_ary_store(ary, i, cCvPoint::new_object(p));
|
165
|
+
}
|
166
|
+
}
|
167
|
+
catch (cv::Exception& e) {
|
168
|
+
raise_cverror(e);
|
169
|
+
}
|
170
|
+
return ary;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* call-seq:
|
175
|
+
* approx_chains(<i>[approx_chain_option]</i>) -> cvcontour
|
176
|
+
*
|
177
|
+
* Approximates Freeman chain(s) with polygonal curve.
|
178
|
+
* <i>approx_chain_option</i> should be Hash include these keys.
|
179
|
+
* :method - Approximation method.
|
180
|
+
* :approx_none - translate all the points from the chain code into points;
|
181
|
+
* :approx_simple(default) - compress horizontal, vertical, and diagonal segments, that is,
|
182
|
+
* the function leaves only their ending points.
|
183
|
+
* :approx_tc89_l1
|
184
|
+
* :approx_tc89_kcos - apply one of the flavors of Teh-Chin chain approximation algorithm.
|
185
|
+
* If set the difference between the current pixel and seed pixel is considered,
|
186
|
+
* otherwise difference between neighbor pixels is considered (the range is floating).
|
187
|
+
* :parameter - Method parameter (not used now).
|
188
|
+
* :minimal_perimeter (default 0)
|
189
|
+
* Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure.
|
190
|
+
* :recursive (default false)
|
191
|
+
* If not nil or false, the function approximates all chains that access can be obtained to
|
192
|
+
* from self by h_next or v_next links. If 0, the single chain is approximated.
|
193
|
+
*
|
194
|
+
*/
|
195
|
+
VALUE
|
196
|
+
rb_approx_chains(int argc, VALUE *argv, VALUE self)
|
197
|
+
{
|
198
|
+
VALUE approx_chain_option;
|
199
|
+
rb_scan_args(argc, argv, "01", &approx_chain_option);
|
200
|
+
|
201
|
+
approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
|
202
|
+
VALUE storage = cCvMemStorage::new_object();
|
203
|
+
CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
|
204
|
+
APPROX_CHAIN_METHOD(approx_chain_option),
|
205
|
+
APPROX_CHAIN_PARAMETER(approx_chain_option),
|
206
|
+
APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
|
207
|
+
APPROX_CHAIN_RECURSIVE(approx_chain_option));
|
208
|
+
|
209
|
+
if (seq && seq->total > 0) {
|
210
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
|
211
|
+
}
|
212
|
+
return Qnil;
|
213
|
+
}
|
214
|
+
|
215
|
+
VALUE
|
216
|
+
new_object()
|
217
|
+
{
|
218
|
+
VALUE storage = cCvMemStorage::new_object();
|
219
|
+
CvSeq *seq = NULL;
|
220
|
+
try {
|
221
|
+
seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(char), CVMEMSTORAGE(storage));
|
222
|
+
}
|
223
|
+
catch (cv::Exception& e) {
|
224
|
+
raise_cverror(e);
|
225
|
+
}
|
226
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
|
227
|
+
}
|
228
|
+
|
229
|
+
__NAMESPACE_END_CVCHAIN
|
230
|
+
__NAMESPACE_END_OPENCV
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvchain.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVCHAIN_H
|
11
|
+
#define RUBY_OPENCV_CVCHAIN_H
|
12
|
+
#include "opencv.h"
|
13
|
+
|
14
|
+
#define __NAMESPACE_BEGIN_CVCHAIN namespace cCvChain {
|
15
|
+
#define __NAMESPACE_END_CVCHAIN }
|
16
|
+
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
18
|
+
__NAMESPACE_BEGIN_CVCHAIN
|
19
|
+
|
20
|
+
VALUE rb_class();
|
21
|
+
|
22
|
+
void define_ruby_class();
|
23
|
+
|
24
|
+
VALUE rb_allocate(VALUE klass);
|
25
|
+
|
26
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
27
|
+
VALUE rb_origin(VALUE self);
|
28
|
+
VALUE rb_set_origin(VALUE self, VALUE origin);
|
29
|
+
VALUE rb_codes(VALUE self);
|
30
|
+
VALUE rb_points(VALUE self);
|
31
|
+
VALUE rb_approx_chains(int argc, VALUE *argv, VALUE self);
|
32
|
+
|
33
|
+
VALUE new_object();
|
34
|
+
|
35
|
+
__NAMESPACE_END_CVCHAIN
|
36
|
+
|
37
|
+
inline CvChain*
|
38
|
+
CVCHAIN(VALUE object){
|
39
|
+
CvChain *ptr;
|
40
|
+
Data_Get_Struct(object, CvChain, ptr);
|
41
|
+
return ptr;
|
42
|
+
}
|
43
|
+
|
44
|
+
__NAMESPACE_END_OPENCV
|
45
|
+
|
46
|
+
#endif // RUBY_OPENCV_CVCHAIN_H
|
@@ -0,0 +1,116 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvcircle32f.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvcircle32f.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvCircle32f
|
13
|
+
*
|
14
|
+
* Combination of center and radius.
|
15
|
+
*
|
16
|
+
* see CvMat#hough_circles
|
17
|
+
*/
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVCIRCLE32F
|
20
|
+
|
21
|
+
VALUE rb_klass;
|
22
|
+
|
23
|
+
VALUE
|
24
|
+
rb_class()
|
25
|
+
{
|
26
|
+
return rb_klass;
|
27
|
+
}
|
28
|
+
|
29
|
+
void
|
30
|
+
define_ruby_class()
|
31
|
+
{
|
32
|
+
if (rb_klass)
|
33
|
+
return;
|
34
|
+
/*
|
35
|
+
* opencv = rb_define_module("OpenCV");
|
36
|
+
*
|
37
|
+
* note: this comment is used by rdoc.
|
38
|
+
*/
|
39
|
+
VALUE opencv = rb_module_opencv();
|
40
|
+
|
41
|
+
rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
|
42
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
43
|
+
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
44
|
+
rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
|
45
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
46
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
47
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE
|
51
|
+
rb_allocate(VALUE klass)
|
52
|
+
{
|
53
|
+
CvCircle32f *ptr;
|
54
|
+
return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* Return parameter on center.
|
59
|
+
*/
|
60
|
+
VALUE
|
61
|
+
rb_center(VALUE self)
|
62
|
+
{
|
63
|
+
return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Return parameter on radius.
|
68
|
+
*/
|
69
|
+
VALUE
|
70
|
+
rb_radius(VALUE self)
|
71
|
+
{
|
72
|
+
return rb_float_new(CVCIRCLE32F(self)->radius);
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
* call-seq:
|
77
|
+
* [<i>index</i>]
|
78
|
+
*
|
79
|
+
* Return value of <i>index</i> dimension.
|
80
|
+
*/
|
81
|
+
VALUE
|
82
|
+
rb_aref(VALUE self, VALUE index)
|
83
|
+
{
|
84
|
+
switch (NUM2INT(index)) {
|
85
|
+
case 0:
|
86
|
+
return DBL2NUM(CVCIRCLE32F(self)->center.x);
|
87
|
+
break;
|
88
|
+
case 1:
|
89
|
+
return DBL2NUM(CVCIRCLE32F(self)->center.y);
|
90
|
+
break;
|
91
|
+
case 2:
|
92
|
+
return DBL2NUM(CVCIRCLE32F(self)->radius);
|
93
|
+
break;
|
94
|
+
default:
|
95
|
+
rb_raise(rb_eIndexError, "index should be 0...3");
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
return Qnil;
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE
|
102
|
+
rb_to_ary(VALUE self)
|
103
|
+
{
|
104
|
+
return rb_ary_new3(2, rb_center(self), rb_radius(self));
|
105
|
+
}
|
106
|
+
|
107
|
+
VALUE
|
108
|
+
new_object(CvCircle32f circle32f)
|
109
|
+
{
|
110
|
+
VALUE object = rb_allocate(rb_klass);
|
111
|
+
*CVCIRCLE32F(object) = circle32f;
|
112
|
+
return object;
|
113
|
+
}
|
114
|
+
|
115
|
+
__NAMESPACE_END_CVCIRCLE32F
|
116
|
+
__NAMESPACE_END_OPENCV
|