bonanza-ruby-opencv 0.0.13.20140330211753
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/ext/opencv/cvrect.h
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvrect.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVRECT_H
|
11
|
+
#define RUBY_OPENCV_CVRECT_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVRECT namespace cCvRect {
|
16
|
+
#define __NAMESPACE_END_CVRECT }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVRECT
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
26
|
+
VALUE rb_max_rect(VALUE klass, VALUE rect1, VALUE rect2);
|
27
|
+
|
28
|
+
VALUE rb_allocate(VALUE klass);
|
29
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
30
|
+
VALUE rb_check_equality(VALUE self, VALUE compare_to);
|
31
|
+
VALUE rb_check_inequality(VALUE self, VALUE compare_to);
|
32
|
+
VALUE rb_hash(VALUE self);
|
33
|
+
VALUE rb_to_s(VALUE self);
|
34
|
+
VALUE rb_x(VALUE self);
|
35
|
+
VALUE rb_set_x(VALUE self, VALUE x);
|
36
|
+
VALUE rb_y(VALUE self);
|
37
|
+
VALUE rb_set_y(VALUE self, VALUE y);
|
38
|
+
VALUE rb_width(VALUE self);
|
39
|
+
VALUE rb_set_width(VALUE self, VALUE width);
|
40
|
+
VALUE rb_height(VALUE self);
|
41
|
+
VALUE rb_set_height(VALUE self, VALUE height);
|
42
|
+
|
43
|
+
VALUE rb_center(VALUE self);
|
44
|
+
VALUE rb_points(VALUE self);
|
45
|
+
VALUE rb_top_left(VALUE self);
|
46
|
+
VALUE rb_set_top_left(VALUE self, VALUE point);
|
47
|
+
VALUE rb_top_right(VALUE self);
|
48
|
+
VALUE rb_set_top_right(VALUE self, VALUE point);
|
49
|
+
VALUE rb_bottom_left(VALUE self);
|
50
|
+
VALUE rb_set_bottom_left(VALUE self, VALUE point);
|
51
|
+
VALUE rb_bottom_right(VALUE self);
|
52
|
+
VALUE rb_set_bottom_right(VALUE self, VALUE point);
|
53
|
+
|
54
|
+
VALUE rb_top_center(VALUE self);
|
55
|
+
VALUE rb_bottom_center(VALUE self);
|
56
|
+
VALUE rb_center_right(VALUE self);
|
57
|
+
VALUE rb_center_left(VALUE self);
|
58
|
+
|
59
|
+
VALUE new_object(CvRect rect);
|
60
|
+
|
61
|
+
__NAMESPACE_END_CVRECT
|
62
|
+
|
63
|
+
inline CvRect*
|
64
|
+
CVRECT(VALUE object)
|
65
|
+
{
|
66
|
+
CvRect *ptr;
|
67
|
+
Data_Get_Struct(object, CvRect, ptr);
|
68
|
+
return ptr;
|
69
|
+
}
|
70
|
+
|
71
|
+
inline CvRect
|
72
|
+
VALUE_TO_CVRECT(VALUE object)
|
73
|
+
{
|
74
|
+
if (cCvRect::rb_compatible_q(cCvRect::rb_class(), object)) {
|
75
|
+
return cvRect(NUM2INT(rb_funcall(object, rb_intern("x"), 0)),
|
76
|
+
NUM2INT(rb_funcall(object, rb_intern("y"), 0)),
|
77
|
+
NUM2INT(rb_funcall(object, rb_intern("width"), 0)),
|
78
|
+
NUM2INT(rb_funcall(object, rb_intern("height"), 0)));
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
raise_compatible_typeerror(object, cCvRect::rb_class());
|
82
|
+
}
|
83
|
+
throw "Should never reach here";
|
84
|
+
}
|
85
|
+
|
86
|
+
__NAMESPACE_END_OPENCV
|
87
|
+
|
88
|
+
#endif // RUBY_OPENCV_CVRECT_H
|
@@ -0,0 +1,301 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvscalar.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvscalar.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvScalar
|
13
|
+
*
|
14
|
+
* Element-value of one pixel.
|
15
|
+
* OpenCV supports the image of 4-channels in the maximum.
|
16
|
+
* Therefore, CvScalar has 4-values.
|
17
|
+
*
|
18
|
+
* C structure is here, very simple.
|
19
|
+
* typdef struct CvScalar {
|
20
|
+
* double val[4];
|
21
|
+
* } CvScalar;
|
22
|
+
*
|
23
|
+
* If obtain CvScalar-object from the method of CvMat(or IplImage),
|
24
|
+
* the channel outside the range is obtained as all 0.
|
25
|
+
*
|
26
|
+
* image = IplImage::load("opencv.jpg") #=> 3-channel 8bit-depth BGR image
|
27
|
+
* pixel = image[10, 20] #=> Get pixel value of (10, 20) of image. pixel is CvScalar-object.
|
28
|
+
* blue, green, red = pixel[0], pixel[1], pixel[2]
|
29
|
+
* # pixel[3] always 0.
|
30
|
+
*
|
31
|
+
* CvColor is alias of CvScalar.
|
32
|
+
*/
|
33
|
+
__NAMESPACE_BEGIN_OPENCV
|
34
|
+
__NAMESPACE_BEGIN_CVSCALAR
|
35
|
+
|
36
|
+
|
37
|
+
VALUE rb_klass;
|
38
|
+
|
39
|
+
VALUE
|
40
|
+
rb_class()
|
41
|
+
{
|
42
|
+
return rb_klass;
|
43
|
+
}
|
44
|
+
|
45
|
+
VALUE
|
46
|
+
rb_allocate(VALUE klass)
|
47
|
+
{
|
48
|
+
CvScalar *ptr;
|
49
|
+
return Data_Make_Struct(klass, CvScalar, 0, -1, ptr);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* new([d1][,d2][,d3][,d4])
|
55
|
+
*
|
56
|
+
* Create new Scalar. Argument should be Fixnum (or nil as 0).
|
57
|
+
*/
|
58
|
+
VALUE
|
59
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
60
|
+
{
|
61
|
+
VALUE val[4];
|
62
|
+
rb_scan_args(argc, argv, "04", &val[0], &val[1], &val[2], &val[3]);
|
63
|
+
CvScalar* self_ptr = CVSCALAR(self);
|
64
|
+
for (int i = 0; i < 4; ++i) {
|
65
|
+
self_ptr->val[i] = NIL_P(val[i]) ? 0 : NUM2DBL(val[i]);
|
66
|
+
}
|
67
|
+
return self;
|
68
|
+
}
|
69
|
+
|
70
|
+
/*
|
71
|
+
* call-seq:
|
72
|
+
* [<i>index</i>]
|
73
|
+
*
|
74
|
+
* Return value of <i>index</i> dimension.
|
75
|
+
*/
|
76
|
+
VALUE
|
77
|
+
rb_aref(VALUE self, VALUE index)
|
78
|
+
{
|
79
|
+
int idx = NUM2INT(index);
|
80
|
+
if (idx < 0 || idx >= 4) {
|
81
|
+
rb_raise(rb_eIndexError, "scalar index should be 0...4");
|
82
|
+
}
|
83
|
+
return rb_float_new(CVSCALAR(self)->val[idx]);
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* call-seq:
|
88
|
+
* [<i>index</i>] = <i>value</i>
|
89
|
+
*
|
90
|
+
* Set value of <i>index</i> dimension to <i>value</i>
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
rb_aset(VALUE self, VALUE index, VALUE value)
|
94
|
+
{
|
95
|
+
int idx = NUM2INT(index);
|
96
|
+
if (idx < 0 || idx >= 4) {
|
97
|
+
rb_raise(rb_eIndexError, "scalar index should be 0...4");
|
98
|
+
}
|
99
|
+
CVSCALAR(self)->val[idx] = NUM2DBL(value);
|
100
|
+
return self;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* rb_check_equality(val[,mask])
|
106
|
+
*
|
107
|
+
* Return true CvScalar if has same values as we do
|
108
|
+
*/
|
109
|
+
VALUE
|
110
|
+
rb_check_equality(VALUE self, VALUE compare_to) {
|
111
|
+
CvScalar compare = VALUE_TO_CVSCALAR(compare_to);
|
112
|
+
CvScalar* self_ptr = CVSCALAR(self);
|
113
|
+
|
114
|
+
return (self_ptr->val[0] == compare.val[0] && self_ptr->val[1] == compare.val[1] && self_ptr->val[2] == compare.val[2] && self_ptr->val[3] == compare.val[3]) ? Qtrue : Qfalse;
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE
|
118
|
+
rb_check_inequality(VALUE self, VALUE compare_to) {
|
119
|
+
CvScalar compare = VALUE_TO_CVSCALAR(compare_to);
|
120
|
+
CvScalar* self_ptr = CVSCALAR(self);
|
121
|
+
|
122
|
+
return (self_ptr->val[0] != compare.val[0] || self_ptr->val[1] != compare.val[1] || self_ptr->val[2] != compare.val[2] || self_ptr->val[3] != compare.val[3]) ? Qtrue : Qfalse;
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* sub(val[,mask])
|
128
|
+
*
|
129
|
+
* Return new CvScalar if <i>val</i> is CvScalar or compatible object.
|
130
|
+
* self[I] - val[I]
|
131
|
+
* Or return new CvMat if <i>val</i> is CvMat or subclass.
|
132
|
+
*/
|
133
|
+
VALUE
|
134
|
+
rb_sub(int argc, VALUE *argv, VALUE self)
|
135
|
+
{
|
136
|
+
VALUE val, mask;
|
137
|
+
rb_scan_args(argc, argv, "11", &val, &mask);
|
138
|
+
if (rb_obj_is_kind_of(val, cCvMat::rb_class())) {
|
139
|
+
CvArr *val_ptr = CVARR(val);
|
140
|
+
VALUE dest = Qnil;
|
141
|
+
try {
|
142
|
+
dest = cCvMat::new_object(cvGetSize(val_ptr), cvGetElemType(val_ptr));
|
143
|
+
cvSubRS(val_ptr, *CVSCALAR(self), CVARR(dest), MASK(mask));
|
144
|
+
}
|
145
|
+
catch (cv::Exception& e) {
|
146
|
+
raise_cverror(e);
|
147
|
+
}
|
148
|
+
return dest;
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
CvScalar *src = CVSCALAR(self);
|
152
|
+
CvScalar scl = VALUE_TO_CVSCALAR(val);
|
153
|
+
return new_object(cvScalar(src->val[0] - scl.val[0],
|
154
|
+
src->val[1] - scl.val[1],
|
155
|
+
src->val[2] - scl.val[2],
|
156
|
+
src->val[3] - scl.val[3]));
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
/*
|
161
|
+
* call-seq:
|
162
|
+
* add(val[,mask])
|
163
|
+
*
|
164
|
+
* Return new CvScalar self[I] + val[I]
|
165
|
+
*
|
166
|
+
* Or return new CvMat if <i>val</i> is CvMat or subclass.
|
167
|
+
*/
|
168
|
+
VALUE
|
169
|
+
rb_add(int argc, VALUE *argv, VALUE self)
|
170
|
+
{
|
171
|
+
VALUE val, mask;
|
172
|
+
rb_scan_args(argc, argv, "11", &val, &mask);
|
173
|
+
CvScalar *src = CVSCALAR(self);
|
174
|
+
CvScalar scl = VALUE_TO_CVSCALAR(val);
|
175
|
+
return new_object(cvScalar(src->val[0] + scl.val[0],
|
176
|
+
src->val[1] + scl.val[1],
|
177
|
+
src->val[2] + scl.val[2],
|
178
|
+
src->val[3] + scl.val[3]));
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* call-seq:
|
183
|
+
* zero? -> true (all elements equal zero) or false
|
184
|
+
*/
|
185
|
+
VALUE
|
186
|
+
rb_zero_q(VALUE self)
|
187
|
+
{
|
188
|
+
CvScalar* self_ptr = CVSCALAR(self);
|
189
|
+
return (self_ptr->val[0] == 0 && self_ptr->val[1] == 0 && self_ptr->val[2] == 0 && self_ptr->val[3] == 0) ? Qtrue : Qfalse;
|
190
|
+
}
|
191
|
+
|
192
|
+
/*
|
193
|
+
* call-seq:
|
194
|
+
* to_s -> "<OpeCV::CvScalar:#{self[0]},#{self[1]},#{self[2]},#{self[3]}>"
|
195
|
+
*
|
196
|
+
* Return values by String.
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
rb_to_s(VALUE self)
|
200
|
+
{
|
201
|
+
const int i = 6;
|
202
|
+
VALUE str[i];
|
203
|
+
str[0] = rb_str_new2("<%s:%g,%g,%g,%g>");
|
204
|
+
str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
|
205
|
+
str[2] = rb_aref(self, INT2FIX(0));
|
206
|
+
str[3] = rb_aref(self, INT2FIX(1));
|
207
|
+
str[4] = rb_aref(self, INT2FIX(2));
|
208
|
+
str[5] = rb_aref(self, INT2FIX(3));
|
209
|
+
return rb_f_sprintf(i, str);
|
210
|
+
}
|
211
|
+
|
212
|
+
/*
|
213
|
+
* call-seq:
|
214
|
+
* to_ary -> [self[0],self[1],self[2],self[3]]
|
215
|
+
*
|
216
|
+
* Return values by Array.
|
217
|
+
*/
|
218
|
+
VALUE
|
219
|
+
rb_to_ary(VALUE self)
|
220
|
+
{
|
221
|
+
return rb_ary_new3(4,
|
222
|
+
rb_aref(self, INT2FIX(0)),
|
223
|
+
rb_aref(self, INT2FIX(1)),
|
224
|
+
rb_aref(self, INT2FIX(2)),
|
225
|
+
rb_aref(self, INT2FIX(3)));
|
226
|
+
}
|
227
|
+
|
228
|
+
VALUE
|
229
|
+
new_object()
|
230
|
+
{
|
231
|
+
VALUE object = rb_allocate(rb_klass);
|
232
|
+
*CVSCALAR(object) = cvScalar(0);
|
233
|
+
return object;
|
234
|
+
}
|
235
|
+
|
236
|
+
VALUE
|
237
|
+
new_object(CvScalar scalar)
|
238
|
+
{
|
239
|
+
VALUE object = rb_allocate(rb_klass);
|
240
|
+
*CVSCALAR(object) = scalar;
|
241
|
+
return object;
|
242
|
+
}
|
243
|
+
|
244
|
+
void
|
245
|
+
init_ruby_class()
|
246
|
+
{
|
247
|
+
#if 0
|
248
|
+
// For documentation using YARD
|
249
|
+
VALUE opencv = rb_define_module("OpenCV");
|
250
|
+
#endif
|
251
|
+
|
252
|
+
if (rb_klass)
|
253
|
+
return;
|
254
|
+
/*
|
255
|
+
* opencv = rb_define_module("OpenCV");
|
256
|
+
*
|
257
|
+
* note: this comment is used by rdoc.
|
258
|
+
*/
|
259
|
+
VALUE opencv = rb_module_opencv();
|
260
|
+
|
261
|
+
rb_klass = rb_define_class_under(opencv, "CvScalar", rb_cObject);
|
262
|
+
/* CvScalar: class */
|
263
|
+
rb_define_const(opencv, "CvColor", rb_klass);
|
264
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
265
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
266
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
|
267
|
+
rb_define_method(rb_klass, "==", RUBY_METHOD_FUNC(rb_check_equality), 1);
|
268
|
+
rb_define_method(rb_klass, "!=", RUBY_METHOD_FUNC(rb_check_inequality), 1);
|
269
|
+
rb_define_method(rb_klass, "[]=", RUBY_METHOD_FUNC(rb_aset), 2);
|
270
|
+
rb_define_method(rb_klass, "add", RUBY_METHOD_FUNC(rb_add), -1);
|
271
|
+
rb_define_alias(rb_klass, "+", "add");
|
272
|
+
rb_define_method(rb_klass, "sub", RUBY_METHOD_FUNC(rb_sub), -1);
|
273
|
+
rb_define_alias(rb_klass, "-", "sub");
|
274
|
+
|
275
|
+
rb_define_method(rb_klass, "zero?", RUBY_METHOD_FUNC(rb_zero_q), 0);
|
276
|
+
|
277
|
+
rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
|
278
|
+
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
279
|
+
rb_define_alias(rb_klass, "to_a", "to_ary");
|
280
|
+
|
281
|
+
rb_define_const(rb_klass, "Black", cCvScalar::new_object(cvScalar(0x0,0x0,0x0)));
|
282
|
+
rb_define_const(rb_klass, "Silver", cCvScalar::new_object(cvScalar(0x0c,0x0c,0x0c)));
|
283
|
+
rb_define_const(rb_klass, "Gray", cCvScalar::new_object(cvScalar(0x80,0x80,0x80)));
|
284
|
+
rb_define_const(rb_klass, "White", cCvScalar::new_object(cvScalar(0xff,0xff,0xff)));
|
285
|
+
rb_define_const(rb_klass, "Maroon", cCvScalar::new_object(cvScalar(0x0,0x0,0x80)));
|
286
|
+
rb_define_const(rb_klass, "Red", cCvScalar::new_object(cvScalar(0x0,0x0,0xff)));
|
287
|
+
rb_define_const(rb_klass, "Purple", cCvScalar::new_object(cvScalar(0x80,0x0,0x80)));
|
288
|
+
rb_define_const(rb_klass, "Fuchsia", cCvScalar::new_object(cvScalar(0xff,0x0,0xff)));
|
289
|
+
rb_define_const(rb_klass, "Green", cCvScalar::new_object(cvScalar(0x0,0x80,0x0)));
|
290
|
+
rb_define_const(rb_klass, "Lime", cCvScalar::new_object(cvScalar(0x0,0xff,0x0)));
|
291
|
+
rb_define_const(rb_klass, "Olive", cCvScalar::new_object(cvScalar(0x0,0x80,0x80)));
|
292
|
+
rb_define_const(rb_klass, "Yellow", cCvScalar::new_object(cvScalar(0x0,0xff,0xff)));
|
293
|
+
rb_define_const(rb_klass, "Navy", cCvScalar::new_object(cvScalar(0x80,0x0,0x0)));
|
294
|
+
rb_define_const(rb_klass, "Blue", cCvScalar::new_object(cvScalar(0xff,0x0,0x0)));
|
295
|
+
rb_define_const(rb_klass, "Teal", cCvScalar::new_object(cvScalar(0x80,0x80,0x0)));
|
296
|
+
rb_define_const(rb_klass, "Aqua", cCvScalar::new_object(cvScalar(0xff,0xff,0x0)));
|
297
|
+
}
|
298
|
+
|
299
|
+
__NAMESPACE_END_CVSCALAR
|
300
|
+
__NAMESPACE_END_OPENCV
|
301
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvscalar.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVSCALAR_H
|
11
|
+
#define RUBY_OPENCV_CVSCALAR_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVSCALAR namespace cCvScalar {
|
16
|
+
#define __NAMESPACE_END_CVSCALAR }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVSCALAR
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
26
|
+
|
27
|
+
VALUE rb_allocate(VALUE klass);
|
28
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
29
|
+
|
30
|
+
VALUE rb_aref(VALUE self, VALUE index);
|
31
|
+
VALUE rb_aset(VALUE self, VALUE index, VALUE value);
|
32
|
+
VALUE rb_check_equality(VALUE self, VALUE compare_to);
|
33
|
+
VALUE rb_check_inequality(VALUE self, VALUE compare_to);
|
34
|
+
VALUE rb_sub(int argc, VALUE *argv, VALUE self);
|
35
|
+
VALUE rb_add(int argc, VALUE *argv, VALUE self);
|
36
|
+
|
37
|
+
VALUE rb_zero_q(VALUE self);
|
38
|
+
|
39
|
+
VALUE rb_to_s(VALUE self);
|
40
|
+
VALUE rb_to_ary(VALUE self);
|
41
|
+
|
42
|
+
VALUE new_object();
|
43
|
+
VALUE new_object(CvScalar scalar);
|
44
|
+
|
45
|
+
__NAMESPACE_END_CVSCALAR
|
46
|
+
|
47
|
+
inline CvScalar*
|
48
|
+
CVSCALAR(VALUE object)
|
49
|
+
{
|
50
|
+
CvScalar *ptr;
|
51
|
+
Data_Get_Struct(object, CvScalar, ptr);
|
52
|
+
return ptr;
|
53
|
+
}
|
54
|
+
|
55
|
+
inline CvScalar
|
56
|
+
VALUE_TO_CVSCALAR(VALUE object)
|
57
|
+
{
|
58
|
+
ID aref_id;
|
59
|
+
if (FIXNUM_P(object)) {
|
60
|
+
return cvScalarAll(FIX2INT(object));
|
61
|
+
}
|
62
|
+
else if (rb_respond_to(object, (aref_id = rb_intern("[]")))) {
|
63
|
+
return cvScalar(NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(0))),
|
64
|
+
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(1))),
|
65
|
+
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(2))),
|
66
|
+
NUM2DBL(rb_funcall(object, aref_id, 1, INT2FIX(3))));
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
raise_compatible_typeerror(object, cCvScalar::rb_class());
|
70
|
+
}
|
71
|
+
throw "Should never reach here";
|
72
|
+
}
|
73
|
+
|
74
|
+
__NAMESPACE_END_OPENCV
|
75
|
+
|
76
|
+
#endif // RUBY_OPENCV_CVSCALAR_H
|