bonanza-ruby-opencv 0.0.13.20140330211753
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.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -0
- data/ext/opencv/window.h +66 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/chessboard.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -0
@@ -0,0 +1,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 init_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
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CVCHAIN
|
18
|
+
|
19
|
+
#define APPROX_CHAIN_OPTION(op) rb_get_option_table(rb_klass, "APPROX_CHAIN_OPTION", op)
|
20
|
+
#define APPROX_CHAIN_METHOD(op) CVMETHOD("APPROX_CHAIN_METHOD", LOOKUP_HASH(op, "method"), CV_CHAIN_APPROX_SIMPLE)
|
21
|
+
#define APPROX_CHAIN_PARAMETER(op) NUM2INT(LOOKUP_HASH(op, "parameter"))
|
22
|
+
#define APPROX_CHAIN_MINIMAL_PERIMETER(op) NUM2INT(LOOKUP_HASH(op, "minimal_perimeter"))
|
23
|
+
#define APPROX_CHAIN_RECURSIVE(op) TRUE_OR_FALSE(LOOKUP_HASH(op, "recursive"))
|
24
|
+
|
25
|
+
VALUE rb_klass;
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_class()
|
29
|
+
{
|
30
|
+
return rb_klass;
|
31
|
+
}
|
32
|
+
|
33
|
+
VALUE
|
34
|
+
rb_allocate(VALUE klass)
|
35
|
+
{
|
36
|
+
return Data_Wrap_Struct(klass, mark_root_object, unregister_object, NULL);
|
37
|
+
}
|
38
|
+
|
39
|
+
/*
|
40
|
+
* Create a new chain code
|
41
|
+
* @overload new(storage=nil)
|
42
|
+
* @param storage [CvMemStorage,nil] Sequence location (If storage is nil, allocates a new storage automatically)
|
43
|
+
* @return [CvChain] New CvChain instance
|
44
|
+
* @opencv_func cvCreateSeq (seq_flags=CV_SEQ_ELTYPE_CODE)
|
45
|
+
*/
|
46
|
+
VALUE
|
47
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
48
|
+
{
|
49
|
+
CvMemStorage *storage;
|
50
|
+
VALUE storage_value;
|
51
|
+
if (rb_scan_args(argc, argv, "01", &storage_value) > 0) {
|
52
|
+
storage_value = CHECK_CVMEMSTORAGE(storage_value);
|
53
|
+
storage = CVMEMSTORAGE(storage_value);
|
54
|
+
}
|
55
|
+
else
|
56
|
+
storage = rb_cvCreateMemStorage(0);
|
57
|
+
try {
|
58
|
+
DATA_PTR(self) = (CvChain*)cvCreateSeq(CV_SEQ_ELTYPE_CODE, sizeof(CvChain),
|
59
|
+
sizeof(int), storage);
|
60
|
+
}
|
61
|
+
catch (cv::Exception& e) {
|
62
|
+
raise_cverror(e);
|
63
|
+
}
|
64
|
+
CvSeq* self_ptr = CVSEQ(self);
|
65
|
+
cCvSeq::register_elem_class(self_ptr, rb_cFixnum);
|
66
|
+
register_root_object(self_ptr, storage_value);
|
67
|
+
|
68
|
+
return self;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* Returns Freeman chain code origin
|
73
|
+
* @overload origin
|
74
|
+
* @return [CvPoint] Origin of the chain code
|
75
|
+
*/
|
76
|
+
VALUE
|
77
|
+
rb_origin(VALUE self)
|
78
|
+
{
|
79
|
+
return cCvPoint::new_object(CVCHAIN(self)->origin);
|
80
|
+
}
|
81
|
+
|
82
|
+
/*
|
83
|
+
* Set Freeman chain code origin
|
84
|
+
* @overload origin=value
|
85
|
+
* @param value [CvPoint] Origin of the chain code
|
86
|
+
* @return [CvChain] self
|
87
|
+
*/
|
88
|
+
VALUE
|
89
|
+
rb_set_origin(VALUE self, VALUE origin)
|
90
|
+
{
|
91
|
+
CVCHAIN(self)->origin = VALUE_TO_CVPOINT(origin);
|
92
|
+
return self;
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
* Returns the chain codes
|
97
|
+
* @overload codes
|
98
|
+
* @return [Array<Fixnum>] Chain codes
|
99
|
+
* @opencv_func cvStartReadChainPoints
|
100
|
+
* @opencv_func CV_READ_SEQ_ELEM
|
101
|
+
*/
|
102
|
+
VALUE
|
103
|
+
rb_codes(VALUE self)
|
104
|
+
{
|
105
|
+
CvChain *chain = CVCHAIN(self);
|
106
|
+
CvChainPtReader reader;
|
107
|
+
int total = chain->total;
|
108
|
+
VALUE ary = rb_ary_new2(total);
|
109
|
+
try {
|
110
|
+
cvStartReadChainPoints(chain, &reader);
|
111
|
+
for (int i = 0; i < total; ++i) {
|
112
|
+
CV_READ_SEQ_ELEM(reader.code, (*((CvSeqReader*)&(reader))));
|
113
|
+
rb_ary_store(ary, i, INT2FIX(reader.code));
|
114
|
+
}
|
115
|
+
}
|
116
|
+
catch (cv::Exception& e) {
|
117
|
+
raise_cverror(e);
|
118
|
+
}
|
119
|
+
return ary;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Returns the points of the chain codes
|
124
|
+
* @overload points
|
125
|
+
* @return [Array<CvPoint>] Points of the chain codes
|
126
|
+
* @opencv_func cvStartReadChainPoints
|
127
|
+
* @opencv_func CV_READ_CHAIN_POINT
|
128
|
+
*/
|
129
|
+
VALUE
|
130
|
+
rb_points(VALUE self)
|
131
|
+
{
|
132
|
+
CvChain *chain = CVCHAIN(self);
|
133
|
+
CvChainPtReader reader;
|
134
|
+
CvPoint p = chain->origin;
|
135
|
+
int total = chain->total;
|
136
|
+
VALUE ary = rb_ary_new2(total);
|
137
|
+
try {
|
138
|
+
cvStartReadChainPoints(chain, &reader);
|
139
|
+
for (int i = 0; i < total; ++i) {
|
140
|
+
CV_READ_CHAIN_POINT(p, reader);
|
141
|
+
rb_ary_store(ary, i, cCvPoint::new_object(p));
|
142
|
+
}
|
143
|
+
}
|
144
|
+
catch (cv::Exception& e) {
|
145
|
+
raise_cverror(e);
|
146
|
+
}
|
147
|
+
return ary;
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
* Approximates Freeman chains with a polygonal curve
|
152
|
+
* @overload approx_chain(options)
|
153
|
+
* @param options [Hash] Parameters
|
154
|
+
* @option options [Symbol] :method Approximation method (see the description of CvMat#find_contours)
|
155
|
+
* @option options [Number] :minimal_perimeter Approximates only those contours whose perimeters
|
156
|
+
* are not less than minimal_perimeter. Other chains are removed from the resulting structure.
|
157
|
+
* @option options [Boolean] :recursive Recursion flag. If it is true, the function approximates
|
158
|
+
* all chains that can be obtained from chain by using the h_next or v_next links.
|
159
|
+
* Otherwise, the single input chain is approximated.
|
160
|
+
* @return [CvSeq<CvPoint>] Polygonal curve
|
161
|
+
* @opencv_func cvApproxChains
|
162
|
+
*/
|
163
|
+
VALUE
|
164
|
+
rb_approx_chains(int argc, VALUE *argv, VALUE self)
|
165
|
+
{
|
166
|
+
VALUE approx_chain_option;
|
167
|
+
rb_scan_args(argc, argv, "01", &approx_chain_option);
|
168
|
+
|
169
|
+
approx_chain_option = APPROX_CHAIN_OPTION(approx_chain_option);
|
170
|
+
VALUE storage = cCvMemStorage::new_object();
|
171
|
+
CvSeq *seq = cvApproxChains(CVSEQ(self), CVMEMSTORAGE(storage),
|
172
|
+
APPROX_CHAIN_METHOD(approx_chain_option),
|
173
|
+
APPROX_CHAIN_PARAMETER(approx_chain_option),
|
174
|
+
APPROX_CHAIN_MINIMAL_PERIMETER(approx_chain_option),
|
175
|
+
APPROX_CHAIN_RECURSIVE(approx_chain_option));
|
176
|
+
|
177
|
+
if (seq && seq->total > 0) {
|
178
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, cCvPoint::rb_class(), storage);
|
179
|
+
}
|
180
|
+
return Qnil;
|
181
|
+
}
|
182
|
+
|
183
|
+
VALUE
|
184
|
+
new_object()
|
185
|
+
{
|
186
|
+
VALUE storage = cCvMemStorage::new_object();
|
187
|
+
CvSeq *seq = NULL;
|
188
|
+
try {
|
189
|
+
seq = cvCreateSeq(CV_SEQ_CHAIN_CONTOUR, sizeof(CvChain), sizeof(int), CVMEMSTORAGE(storage));
|
190
|
+
}
|
191
|
+
catch (cv::Exception& e) {
|
192
|
+
raise_cverror(e);
|
193
|
+
}
|
194
|
+
return cCvSeq::new_sequence(cCvChain::rb_class(), seq, T_FIXNUM, storage);
|
195
|
+
}
|
196
|
+
|
197
|
+
void
|
198
|
+
init_ruby_class()
|
199
|
+
{
|
200
|
+
#if 0
|
201
|
+
// For documentation using YARD
|
202
|
+
VALUE opencv = rb_define_module("OpenCV");
|
203
|
+
VALUE cvseq = rb_define_class_under(opencv, "CvSeq");
|
204
|
+
VALUE curve = rb_define_module_under(opencv, "Curve");
|
205
|
+
#endif
|
206
|
+
|
207
|
+
if (rb_klass)
|
208
|
+
return;
|
209
|
+
|
210
|
+
VALUE opencv = rb_module_opencv();
|
211
|
+
VALUE cvseq = cCvSeq::rb_class();
|
212
|
+
VALUE curve = mCurve::rb_module();
|
213
|
+
|
214
|
+
rb_klass = rb_define_class_under(opencv, "CvChain", cvseq);
|
215
|
+
rb_include_module(rb_klass, curve);
|
216
|
+
VALUE approx_chain_option = rb_hash_new();
|
217
|
+
rb_define_const(rb_klass, "APPROX_CHAIN_OPTION", approx_chain_option);
|
218
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("approx_simple")));
|
219
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("parameter")), rb_float_new(0));
|
220
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("minimal_perimeter")), INT2FIX(0));
|
221
|
+
rb_hash_aset(approx_chain_option, ID2SYM(rb_intern("recursive")), Qfalse);
|
222
|
+
|
223
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
224
|
+
rb_define_method(rb_klass, "origin", RUBY_METHOD_FUNC(rb_origin), 0);
|
225
|
+
rb_define_method(rb_klass, "origin=", RUBY_METHOD_FUNC(rb_set_origin), 1);
|
226
|
+
rb_define_method(rb_klass, "codes", RUBY_METHOD_FUNC(rb_codes), 0);
|
227
|
+
rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
|
228
|
+
rb_define_method(rb_klass, "approx_chains", RUBY_METHOD_FUNC(rb_approx_chains), -1);
|
229
|
+
rb_define_alias(rb_klass, "approx", "approx_chains");
|
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 init_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,126 @@
|
|
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
|
+
VALUE
|
30
|
+
rb_allocate(VALUE klass)
|
31
|
+
{
|
32
|
+
CvCircle32f *ptr;
|
33
|
+
return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
* Returns center point of the circle
|
38
|
+
* @overload center
|
39
|
+
* @return [CvPoint2D32f] Center point of the circle
|
40
|
+
*/
|
41
|
+
VALUE
|
42
|
+
rb_center(VALUE self)
|
43
|
+
{
|
44
|
+
return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
|
45
|
+
}
|
46
|
+
|
47
|
+
/*
|
48
|
+
* Returns radius of the circle
|
49
|
+
* @overload radius
|
50
|
+
* @return [Number] Radius of the circle
|
51
|
+
*/
|
52
|
+
VALUE
|
53
|
+
rb_radius(VALUE self)
|
54
|
+
{
|
55
|
+
return rb_float_new(CVCIRCLE32F(self)->radius);
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Accesses to parameters of the circle by array-like interface ([X-coordinate, Y-coordinate, radius])
|
60
|
+
* @overload []
|
61
|
+
* @param index [Integer] Index
|
62
|
+
* @return [Number] X-coordinate, Y-coordinate or radius of the circle
|
63
|
+
*/
|
64
|
+
VALUE
|
65
|
+
rb_aref(VALUE self, VALUE index)
|
66
|
+
{
|
67
|
+
switch (NUM2INT(index)) {
|
68
|
+
case 0:
|
69
|
+
return DBL2NUM(CVCIRCLE32F(self)->center.x);
|
70
|
+
break;
|
71
|
+
case 1:
|
72
|
+
return DBL2NUM(CVCIRCLE32F(self)->center.y);
|
73
|
+
break;
|
74
|
+
case 2:
|
75
|
+
return DBL2NUM(CVCIRCLE32F(self)->radius);
|
76
|
+
break;
|
77
|
+
default:
|
78
|
+
rb_raise(rb_eIndexError, "index should be 0...3");
|
79
|
+
break;
|
80
|
+
}
|
81
|
+
return Qnil;
|
82
|
+
}
|
83
|
+
|
84
|
+
/*
|
85
|
+
* Returns parameters of the circle as an array which contains [center<CvPoint2D32f>, radius<Number>]
|
86
|
+
* @overload to_ary
|
87
|
+
* @return [Array<CvPoint2D32f,Number>] An array which contains [center, radius]
|
88
|
+
*/
|
89
|
+
VALUE
|
90
|
+
rb_to_ary(VALUE self)
|
91
|
+
{
|
92
|
+
return rb_ary_new3(2, rb_center(self), rb_radius(self));
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE
|
96
|
+
new_object(CvCircle32f circle32f)
|
97
|
+
{
|
98
|
+
VALUE object = rb_allocate(rb_klass);
|
99
|
+
*CVCIRCLE32F(object) = circle32f;
|
100
|
+
return object;
|
101
|
+
}
|
102
|
+
|
103
|
+
void
|
104
|
+
init_ruby_class()
|
105
|
+
{
|
106
|
+
#if 0
|
107
|
+
// For documentation using YARD
|
108
|
+
VALUE opencv = rb_define_module("OpenCV");
|
109
|
+
#endif
|
110
|
+
|
111
|
+
if (rb_klass)
|
112
|
+
return;
|
113
|
+
|
114
|
+
VALUE opencv = rb_module_opencv();
|
115
|
+
|
116
|
+
rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
|
117
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
118
|
+
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
|
119
|
+
rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
|
120
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
121
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
122
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
123
|
+
}
|
124
|
+
|
125
|
+
__NAMESPACE_END_CVCIRCLE32F
|
126
|
+
__NAMESPACE_END_OPENCV
|