ruby-opencv 0.0.8-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/DEVELOPERS_NOTE.md +120 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +226 -0
- data/README.md +98 -0
- data/Rakefile +32 -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/matching_to_many_images.rb +16 -0
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +3 -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 +233 -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 +296 -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 +5848 -0
- data/ext/opencv/cvmat.h +284 -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 +245 -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 +74 -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 +644 -0
- data/ext/opencv/iplimage.h +73 -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 +722 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +274 -0
- data/ext/opencv/pointset.h +68 -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 +75 -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/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +43 -0
- data/test/helper.rb +166 -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 +2947 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2025 -0
- data/test/test_cvmat_matching.rb +57 -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 +236 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +324 -0
- data/test/test_pointset.rb +126 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +414 -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,233 @@
|
|
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_HASH(op, "method"), CV_CHAIN_APPROX_SIMPLE)
|
22
|
+
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_HASH(op, "parameter"))
|
23
|
+
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_HASH(op, "minimal_perimeter"))
|
24
|
+
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(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
|
+
return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
|
71
|
+
}
|
72
|
+
|
73
|
+
VALUE
|
74
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
75
|
+
{
|
76
|
+
CvMemStorage *storage;
|
77
|
+
VALUE storage_value;
|
78
|
+
if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
|
79
|
+
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
80
|
+
storage = CVMEMSTORAGE(storage_value);
|
81
|
+
}
|
82
|
+
else
|
83
|
+
storage = rb_cvCreateMemStorage(0);
|
84
|
+
try {
|
85
|
+
DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
|
86
|
+
sizeof(int), storage);
|
87
|
+
}
|
88
|
+
catch (cv::Exception& e) {
|
89
|
+
raise_cverror(e);
|
90
|
+
}
|
91
|
+
CvSeq* self_ptr = CVSEQ(self);
|
92
|
+
cCvSeq::register_elem_class(self_ptr, rb_cFixnum);
|
93
|
+
register_root_object(self_ptr, storage_value);
|
94
|
+
|
95
|
+
return self;
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* origin -> cvpoint
|
101
|
+
*
|
102
|
+
* Return Freeman chain code origin.
|
103
|
+
*/
|
104
|
+
VALUE
|
105
|
+
rb_origin(VALUE self)
|
106
|
+
{
|
107
|
+
return cCvPoint::new_object(CVCHAIN(self)->origin);
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* call-seq:
|
112
|
+
* origin = point -> self
|
113
|
+
*
|
114
|
+
* Set Freeman chain code origin.
|
115
|
+
*/
|
116
|
+
VALUE
|
117
|
+
rb_set_origin(VALUE self, VALUE origin)
|
118
|
+
{
|
119
|
+
CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
|
120
|
+
return self;
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* call-seq:
|
125
|
+
* codes -> array(contain fixnum)
|
126
|
+
*
|
127
|
+
* Return Freeman chain codes.
|
128
|
+
*/
|
129
|
+
VALUE
|
130
|
+
rb_codes(VALUE self)
|
131
|
+
{
|
132
|
+
CvChain *chain = CVCHAIN(self);
|
133
|
+
CvChainPtReader reader;
|
134
|
+
int total = chain->total;
|
135
|
+
VALUE ary = rb_ary_new2(total);
|
136
|
+
try {
|
137
|
+
cvStartReadChainPoints(chain, &reader);
|
138
|
+
for (int i = 0; i < total; ++i) {
|
139
|
+
CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
|
140
|
+
rb_ary_store(ary, i, INT2FIX(reader.code));
|
141
|
+
}
|
142
|
+
}
|
143
|
+
catch (cv::Exception& e) {
|
144
|
+
raise_cverror(e);
|
145
|
+
}
|
146
|
+
return ary;
|
147
|
+
}
|
148
|
+
|
149
|
+
/*
|
150
|
+
* call-seq:
|
151
|
+
* points -> array(contain cvpoint)
|
152
|
+
*
|
153
|
+
* Return points that represent by Freeman chain code.
|
154
|
+
*/
|
155
|
+
VALUE
|
156
|
+
rb_points(VALUE self)
|
157
|
+
{
|
158
|
+
CvChain *chain = CVCHAIN(self);
|
159
|
+
CvChainPtReader reader;
|
160
|
+
CvPoint p = chain->origin;
|
161
|
+
int total = chain->total;
|
162
|
+
VALUE ary = rb_ary_new2(total);
|
163
|
+
try {
|
164
|
+
cvStartReadChainPoints(chain, &reader);
|
165
|
+
for (int i = 0; i < total; ++i) {
|
166
|
+
CV_READ_CHAIN_POINT(p, reader);
|
167
|
+
rb_ary_store(ary, i, cCvPoint::new_object(p));
|
168
|
+
}
|
169
|
+
}
|
170
|
+
catch (cv::Exception& e) {
|
171
|
+
raise_cverror(e);
|
172
|
+
}
|
173
|
+
return ary;
|
174
|
+
}
|
175
|
+
|
176
|
+
/*
|
177
|
+
* call-seq:
|
178
|
+
* approx_chains(<i>[approx_chain_option]</i>) -> cvcontour
|
179
|
+
*
|
180
|
+
* Approximates Freeman chain(s) with polygonal curve.
|
181
|
+
* <i>approx_chain_option</i> should be Hash include these keys.
|
182
|
+
* :method - Approximation method.
|
183
|
+
* :approx_none - translate all the points from the chain code into points;
|
184
|
+
* :approx_simple(default) - compress horizontal, vertical, and diagonal segments, that is,
|
185
|
+
* the function leaves only their ending points.
|
186
|
+
* :approx_tc89_l1
|
187
|
+
* :approx_tc89_kcos - apply one of the flavors of Teh-Chin chain approximation algorithm.
|
188
|
+
* If set the difference between the current pixel and seed pixel is considered,
|
189
|
+
* otherwise difference between neighbor pixels is considered (the range is floating).
|
190
|
+
* :parameter - Method parameter (not used now).
|
191
|
+
* :minimal_perimeter (default 0)
|
192
|
+
* Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure.
|
193
|
+
* :recursive (default false)
|
194
|
+
* If not nil or false, the function approximates all chains that access can be obtained to
|
195
|
+
* from self by h_next or v_next links. If 0, the single chain is approximated.
|
196
|
+
*
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
rb_approx_chains(int argc, VALUE *argv, VALUE self)
|
200
|
+
{
|
201
|
+
VALUE approx_chain_option;
|
202
|
+
rb_scan_args(argc, argv, "01", &approx_chain_option);
|
203
|
+
|
204
|
+
approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
|
205
|
+
VALUE storage = cCvMemStorage::new_object();
|
206
|
+
CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
|
207
|
+
APPROX_CHAIN_METHOD(approx_chain_option),
|
208
|
+
APPROX_CHAIN_PARAMETER(approx_chain_option),
|
209
|
+
APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
|
210
|
+
APPROX_CHAIN_RECURSIVE(approx_chain_option));
|
211
|
+
|
212
|
+
if (seq && seq->total > 0) {
|
213
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
|
214
|
+
}
|
215
|
+
return Qnil;
|
216
|
+
}
|
217
|
+
|
218
|
+
VALUE
|
219
|
+
new_object()
|
220
|
+
{
|
221
|
+
VALUE storage = cCvMemStorage::new_object();
|
222
|
+
CvSeq *seq = NULL;
|
223
|
+
try {
|
224
|
+
seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(int), CVMEMSTORAGE(storage));
|
225
|
+
}
|
226
|
+
catch (cv::Exception& e) {
|
227
|
+
raise_cverror(e);
|
228
|
+
}
|
229
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
|
230
|
+
}
|
231
|
+
|
232
|
+
__NAMESPACE_END_CVCHAIN
|
233
|
+
__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
|