opencv 0.0.6

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.
Files changed (117) hide show
  1. data/History.txt +5 -0
  2. data/License.txt +30 -0
  3. data/Manifest.txt +115 -0
  4. data/README.txt +47 -0
  5. data/Rakefile +34 -0
  6. data/examples/convexhull.rb +41 -0
  7. data/examples/face_detect.rb +25 -0
  8. data/examples/houghcircle.rb +23 -0
  9. data/examples/inpaint.png +0 -0
  10. data/examples/inpaint.rb +43 -0
  11. data/examples/paint.rb +72 -0
  12. data/examples/snake.rb +43 -0
  13. data/examples/stuff.jpg +0 -0
  14. data/ext/curve.cpp +103 -0
  15. data/ext/curve.h +34 -0
  16. data/ext/cvavgcomp.cpp +67 -0
  17. data/ext/cvavgcomp.h +39 -0
  18. data/ext/cvbox2d.cpp +114 -0
  19. data/ext/cvbox2d.h +53 -0
  20. data/ext/cvcapture.cpp +276 -0
  21. data/ext/cvcapture.h +54 -0
  22. data/ext/cvchain.cpp +184 -0
  23. data/ext/cvchain.h +43 -0
  24. data/ext/cvchaincode.cpp +49 -0
  25. data/ext/cvchaincode.h +43 -0
  26. data/ext/cvcircle32f.cpp +90 -0
  27. data/ext/cvcircle32f.h +53 -0
  28. data/ext/cvcondensation.cpp +230 -0
  29. data/ext/cvcondensation.h +49 -0
  30. data/ext/cvconnectedcomp.cpp +115 -0
  31. data/ext/cvconnectedcomp.h +46 -0
  32. data/ext/cvcontour.cpp +219 -0
  33. data/ext/cvcontour.h +47 -0
  34. data/ext/cvcontourtree.cpp +86 -0
  35. data/ext/cvcontourtree.h +41 -0
  36. data/ext/cvconvexitydefect.cpp +103 -0
  37. data/ext/cvconvexitydefect.h +42 -0
  38. data/ext/cverror.cpp +140 -0
  39. data/ext/cverror.h +79 -0
  40. data/ext/cvfont.cpp +173 -0
  41. data/ext/cvfont.h +56 -0
  42. data/ext/cvhaarclassifiercascade.cpp +159 -0
  43. data/ext/cvhaarclassifiercascade.h +41 -0
  44. data/ext/cvhistogram.cpp +200 -0
  45. data/ext/cvhistogram.h +51 -0
  46. data/ext/cvindex.cpp +73 -0
  47. data/ext/cvindex.h +40 -0
  48. data/ext/cvline.cpp +106 -0
  49. data/ext/cvline.h +52 -0
  50. data/ext/cvmat.cpp +4809 -0
  51. data/ext/cvmat.h +286 -0
  52. data/ext/cvmatnd.cpp +44 -0
  53. data/ext/cvmatnd.h +28 -0
  54. data/ext/cvmemstorage.cpp +64 -0
  55. data/ext/cvmemstorage.h +53 -0
  56. data/ext/cvmoments.cpp +204 -0
  57. data/ext/cvmoments.h +48 -0
  58. data/ext/cvpoint.cpp +229 -0
  59. data/ext/cvpoint.h +59 -0
  60. data/ext/cvpoint2d32f.cpp +213 -0
  61. data/ext/cvpoint2d32f.h +61 -0
  62. data/ext/cvpoint3d32f.cpp +245 -0
  63. data/ext/cvpoint3d32f.h +64 -0
  64. data/ext/cvrect.cpp +340 -0
  65. data/ext/cvrect.h +79 -0
  66. data/ext/cvscalar.cpp +227 -0
  67. data/ext/cvscalar.h +63 -0
  68. data/ext/cvseq.cpp +583 -0
  69. data/ext/cvseq.h +71 -0
  70. data/ext/cvset.cpp +63 -0
  71. data/ext/cvset.h +39 -0
  72. data/ext/cvsize.cpp +223 -0
  73. data/ext/cvsize.h +63 -0
  74. data/ext/cvsize2d32f.cpp +180 -0
  75. data/ext/cvsize2d32f.h +59 -0
  76. data/ext/cvslice.cpp +82 -0
  77. data/ext/cvslice.h +53 -0
  78. data/ext/cvsparsemat.cpp +44 -0
  79. data/ext/cvsparsemat.h +28 -0
  80. data/ext/cvtermcriteria.cpp +183 -0
  81. data/ext/cvtermcriteria.h +71 -0
  82. data/ext/cvtwopoints.cpp +98 -0
  83. data/ext/cvtwopoints.h +50 -0
  84. data/ext/cvvector.cpp +206 -0
  85. data/ext/cvvector.h +54 -0
  86. data/ext/cvvideowriter.cpp +116 -0
  87. data/ext/cvvideowriter.h +41 -0
  88. data/ext/extconf.rb +61 -0
  89. data/ext/gui.cpp +65 -0
  90. data/ext/gui.h +33 -0
  91. data/ext/iplconvkernel.cpp +177 -0
  92. data/ext/iplconvkernel.h +52 -0
  93. data/ext/iplimage.cpp +238 -0
  94. data/ext/iplimage.h +54 -0
  95. data/ext/mouseevent.cpp +184 -0
  96. data/ext/mouseevent.h +59 -0
  97. data/ext/opencv.cpp +481 -0
  98. data/ext/opencv.h +356 -0
  99. data/ext/point3dset.cpp +41 -0
  100. data/ext/point3dset.h +31 -0
  101. data/ext/pointset.cpp +238 -0
  102. data/ext/pointset.h +69 -0
  103. data/ext/trackbar.cpp +122 -0
  104. data/ext/trackbar.h +65 -0
  105. data/ext/window.cpp +368 -0
  106. data/ext/window.h +56 -0
  107. data/images/CvMat_sobel.png +0 -0
  108. data/images/CvMat_sub_rect.png +0 -0
  109. data/images/CvSeq_relationmap.png +0 -0
  110. data/images/face_detect_from_lena.jpg +0 -0
  111. data/lib/opencv.rb +3 -0
  112. data/lib/version.rb +3 -0
  113. data/setup/setup.cygwin.rb +120 -0
  114. data/setup/setup.mingw.rb +99 -0
  115. data/setup/setup.mswin32.rb +103 -0
  116. data/test/test_opencv.rb +4 -0
  117. metadata +191 -0
@@ -0,0 +1,173 @@
1
+ /************************************************************
2
+
3
+ cvfont.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvfont.h"
11
+ /*
12
+ * Document-class: OpenCV::CvFont
13
+ *
14
+ * Font structure that can be passed to text rendering functions.
15
+ * see CvMat#put_text, CvMat#put_text!
16
+ */
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVFONT
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, "CvFont", rb_cObject);
42
+ rb_define_alloc_func(rb_klass, rb_allocate);
43
+ VALUE face = rb_hash_new();
44
+ rb_define_const(rb_klass, "FACE", face);
45
+ rb_hash_aset(face, ID2SYM(rb_intern("simplex")), INT2FIX(CV_FONT_HERSHEY_SIMPLEX));
46
+ rb_hash_aset(face, ID2SYM(rb_intern("plain")), INT2FIX(CV_FONT_HERSHEY_PLAIN));
47
+ rb_hash_aset(face, ID2SYM(rb_intern("duplex")), INT2FIX(CV_FONT_HERSHEY_DUPLEX));
48
+ rb_hash_aset(face, ID2SYM(rb_intern("triplex")), INT2FIX(CV_FONT_HERSHEY_TRIPLEX));
49
+ rb_hash_aset(face, ID2SYM(rb_intern("complex_small")), INT2FIX(CV_FONT_HERSHEY_COMPLEX_SMALL));
50
+ rb_hash_aset(face, ID2SYM(rb_intern("script_simplex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_SIMPLEX));
51
+ rb_hash_aset(face, ID2SYM(rb_intern("script_complex")), INT2FIX(CV_FONT_HERSHEY_SCRIPT_COMPLEX));
52
+
53
+ VALUE default_option = rb_hash_new();
54
+ rb_define_const(rb_klass, "FONT_OPTION", default_option);
55
+ rb_hash_aset(default_option, ID2SYM(rb_intern("hscale")), rb_float_new(1.0));
56
+ rb_hash_aset(default_option, ID2SYM(rb_intern("vscale")), rb_float_new(1.0));
57
+ rb_hash_aset(default_option, ID2SYM(rb_intern("shear")), INT2FIX(0));
58
+ rb_hash_aset(default_option, ID2SYM(rb_intern("thickness")), INT2FIX(1));
59
+ rb_hash_aset(default_option, ID2SYM(rb_intern("line_type")), INT2FIX(8));
60
+
61
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
62
+ }
63
+
64
+ VALUE
65
+ rb_allocate(VALUE klass)
66
+ {
67
+ CvFont *ptr;
68
+ return Data_Make_Struct(klass, CvFont, 0, -1, ptr);
69
+ }
70
+
71
+
72
+ /*
73
+ * call-seq:
74
+ * CvFont.new(<i>face[,font_option]</i>) -> font
75
+ *
76
+ * Create font object.
77
+ * <i>face</i> is font name identifier.
78
+ *
79
+ * Only a subset of Hershey fonts (http://sources.isc.org/utils/misc/hershey-font.txt) are supported now:
80
+ * * :simplex - normal size sans-serif font
81
+ * * :plain - small size sans-serif font
82
+ * * :duplex - normal size sans-serif font (more complex than :simplex)
83
+ * * :complex - normal size serif font
84
+ * * :triplex - normal size serif font (more complex than :complex)
85
+ * * :complex_small - smaller version of :complex
86
+ * * :script_simplex - hand-writing style font
87
+ * * :script_complex - more complex variant of :script_simplex
88
+ *
89
+ * <i>font_option</i> should be Hash include these keys.
90
+ * :hscale
91
+ * Horizontal scale. If equal to 1.0, the characters have the original width depending on the font type.
92
+ * If equal to 0.5, the characters are of half the original width.
93
+ * :vscale
94
+ * Vertical scale. If equal to 1.0, the characters have the original height depending on the font type.
95
+ * If equal to 0.5, the characters are of half the original height.
96
+ * :shear
97
+ * Approximate tangent of the character slope relative to the vertical line.
98
+ * Zero value means a non-italic font, 1.0f means ~45degree slope, etc.
99
+ * :thickness
100
+ * Thickness of the text strokes.
101
+ * :line_type
102
+ * Type of the strokes, see CvMat#Line description.
103
+ * :italic
104
+ * If value is not nil or false that means italic or oblique font.
105
+ *
106
+ * note: <i>font_option</i>'s default value is CvFont::FONT_OPTION.
107
+ *
108
+ * e.g. Create Font
109
+ * OpenCV::CvFont.new(:simplex, :hscale => 2, :vslace => 2, :italic => true)
110
+ * # create 2x bigger than normal, italic type font.
111
+ */
112
+ VALUE
113
+ rb_initialize(int argc, VALUE *argv, VALUE self)
114
+ {
115
+ VALUE face, font_option;
116
+ rb_scan_args(argc, argv, "11", &face, &font_option);
117
+ Check_Type(face, T_SYMBOL);
118
+ face = rb_hash_aref(rb_const_get(cCvFont::rb_class(), rb_intern("FACE")), face);
119
+ if (NIL_P(face)) {
120
+ rb_raise(rb_eArgError, "undefined face.");
121
+ }
122
+ font_option = FONT_OPTION(font_option);
123
+ /*
124
+ cvInitFont(CVFONT(self),
125
+ (FIX2INT(face) | FO_ITALIC(font_option)),
126
+ FO_HSCALE(font_option),
127
+ FO_VSCALE(font_option),
128
+ FO_SHEAR(font_option),
129
+ FO_THICKNESS(font_option),
130
+ FO_LINE_TYPE(font_option));
131
+ */
132
+ return self;
133
+ }
134
+
135
+
136
+ VALUE
137
+ rb_face(VALUE self)
138
+ {
139
+ return FIX2INT(CVFONT(self)->font_face);
140
+ }
141
+
142
+ VALUE
143
+ rb_hscale(VALUE self)
144
+ {
145
+ return rb_float_new(CVFONT(self)->hscale);
146
+ }
147
+
148
+ VALUE
149
+ rb_vscale(VALUE self)
150
+ {
151
+ return rb_float_new(CVFONT(self)->vscale);
152
+ }
153
+
154
+ VALUE
155
+ rb_shear(VALUE self)
156
+ {
157
+ return rb_float_new(CVFONT(self)->shear);
158
+ }
159
+
160
+ VALUE
161
+ rb_thickness(VALUE self)
162
+ {
163
+ return FIX2INT(CVFONT(self)->thickness);
164
+ }
165
+
166
+ VALUE
167
+ rb_line_type(VALUE self)
168
+ {
169
+ return FIX2INT(CVFONT(self)->line_type);
170
+ }
171
+
172
+ __NAMESPACE_END_CVFONT
173
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,56 @@
1
+ /************************************************************
2
+
3
+ cvfont.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVFONT_H
11
+ #define RUBY_OPENCV_CVFONT_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVFONT namespace cCvFont{
16
+ #define __NAMESPACE_END_CVFONT }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVFONT
20
+
21
+ #define FONT_OPTION(op) NIL_P(op) ? rb_const_get(rb_class(), rb_intern("FONT_OPTION")) : rb_funcall(rb_const_get(rb_class(), rb_intern("FONT_OPTION")), rb_intern("merge"), 1, font_option)
22
+ #define FO_ITALIC(op) ({VALUE _italic = rb_hash_aref(op, ID2SYM(rb_intern("italic"))); NIL_P(_italic) ? 0 : _italic == Qfalse ? 0 : 1;})
23
+ #define FO_HSCALE(op) NUM2DBL(rb_hash_aref(op, ID2SYM(rb_intern("hscale"))))
24
+ #define FO_VSCALE(op) NUM2DBL(rb_hash_aref(op, ID2SYM(rb_intern("vscale"))))
25
+ #define FO_SHEAR(op) NUM2DBL(rb_hash_aref(op, ID2SYM(rb_intern("shear"))))
26
+ #define FO_THICKNESS(op) FIX2INT(rb_hash_aref(op, ID2SYM(rb_intern("thickness"))))
27
+ #define FO_LINE_TYPE(op) FIX2INT(rb_hash_aref(op, ID2SYM(rb_intern("line_type"))) == ID2SYM("aa") ? INT2FIX(CV_AA) : rb_hash_aref(op, ID2SYM(rb_intern("line_type"))))
28
+
29
+
30
+ VALUE rb_class();
31
+
32
+ void define_ruby_class();
33
+
34
+ VALUE rb_allocate(VALUE klass);
35
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
36
+
37
+ VALUE rb_face(VALUE self);
38
+ VALUE rb_hscale(VALUE self);
39
+ VALUE rb_vscale(VALUE self);
40
+ VALUE rb_shear(VALUE self);
41
+ VALUE rb_thickness(VALUE self);
42
+ VALUE rb_line_type(VALUE self);
43
+
44
+ __NAMESPACE_END_CVFONT
45
+
46
+ inline CvFont*
47
+ CVFONT(VALUE object)
48
+ {
49
+ CvFont *ptr;
50
+ Data_Get_Struct(object, CvFont, ptr);
51
+ return ptr;
52
+ }
53
+
54
+ __NAMESPACE_END_OPENCV
55
+
56
+ #endif // RUBY_OPENCV_CVFONT_H
@@ -0,0 +1,159 @@
1
+ /************************************************************
2
+
3
+ cvhaarclassifercascade.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvhaarclassifiercascade.h"
11
+ /*
12
+ * Document-class: OpenCV::CvHaarClassifierCascade
13
+ *
14
+ * CvHaarClassifierCascade object is "fast-object-detector".
15
+ * This detector can discover object (e.g. human's face) from image.
16
+ *
17
+ * Find face-area from picture "lena"...
18
+ * link:../images/face_detect_from_lena.jpg
19
+ */
20
+ __NAMESPACE_BEGIN_OPENCV
21
+ __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
22
+
23
+ VALUE rb_klass;
24
+
25
+ VALUE
26
+ rb_class()
27
+ {
28
+ return rb_klass;
29
+ }
30
+
31
+ void define_ruby_class()
32
+ {
33
+ if (rb_klass)
34
+ return;
35
+ /*
36
+ * opencv = rb_define_module("OpenCV");
37
+ *
38
+ * note: this comment is used by rdoc.
39
+ */
40
+ VALUE opencv = rb_module_opencv();
41
+
42
+ rb_klass = rb_define_class_under(opencv, "CvHaarClassifierCascade", rb_cObject);
43
+ rb_define_alloc_func(rb_klass, rb_allocate);
44
+ rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
45
+ rb_define_method(rb_klass, "detect_objects", RUBY_METHOD_FUNC(rb_detect_objects), -1);
46
+ rb_define_method(rb_klass, "detect_objects_with_pruning", RUBY_METHOD_FUNC(rb_detect_objects_with_pruning), -1);
47
+ }
48
+
49
+ VALUE
50
+ rb_allocate(VALUE klass)
51
+ {
52
+ return OPENCV_OBJECT(klass, 0);
53
+ }
54
+
55
+ /*
56
+ * call-seq:
57
+ * CvHaarClassiferCascade.load(<i>path</i>) -> object-detector
58
+ *
59
+ * Load trained cascade of haar classifers from file.
60
+ * Object detection classifiers are stored in XML or YAML files.
61
+ * sample of object detection classifier files is included by OpenCV.
62
+ *
63
+ * You can found these at
64
+ * C:\Program Files\OpenCV\data\haarcascades\*.xml (Windows, default install path)
65
+ *
66
+ * e.g. you want to try to detect human's face.
67
+ * detector = CvHaarClassiferCascade.load("haarcascade_frontalface_alt.xml")
68
+ */
69
+ VALUE
70
+ rb_load(VALUE klass, VALUE path)
71
+ {
72
+ CvHaarClassifierCascade *cascade = (CvHaarClassifierCascade*)cvLoad(StringValueCStr(path), 0, 0, 0);
73
+ if(!CV_IS_HAAR_CLASSIFIER(cascade))
74
+ rb_raise(rb_eTypeError, "invalid format haar classifier cascade file.");
75
+ return OPENCV_OBJECT(rb_klass, cascade);
76
+ }
77
+
78
+ VALUE
79
+ rb_save(VALUE self, VALUE path)
80
+ {
81
+ rb_raise(rb_eNotImpError, "");
82
+ }
83
+
84
+ /*
85
+ * call-seq:
86
+ * detect_objects(image[,scale_factor = 1.1, min_neighbor = 3, min_size = CvSize.new(0,0)]) -> cvseq(include CvAvgComp object)
87
+ * detect_objects(image[,scale_factor = 1.1, min_neighbor = 3, min_size = CvSize.new(0,0)]){|cmp| ... } -> cvseq(include CvAvgComp object)
88
+ *
89
+ * Detects objects in the image. This method finds rectangular regions in the
90
+ * given image that are likely to contain objects the cascade has been trained
91
+ * for and return those regions as a sequence of rectangles.
92
+ *
93
+ * * scale_factor (should be > 1.0)
94
+ * The factor by which the search window is scaled between the subsequent scans, for example, 1.1 mean increasing window by 10%.
95
+ * * min_neighbors
96
+ * Minimum number (minus 1) of neighbor rectangles that makes up an object.
97
+ * All the groups of a smaller number of rectangles than min_neighbors - 1 are rejected.
98
+ * If min_neighbors is 0, the function does not any grouping at all and returns all the detected
99
+ * candidate rectangles, whitch many be useful if the user wants to apply a customized grouping procedure.
100
+ * * min_size
101
+ * Minimum window size. By default, it is set to size of samples the classifier has been trained on.
102
+ */
103
+ VALUE
104
+ rb_detect_objects(int argc, VALUE *argv, VALUE self)
105
+ {
106
+ VALUE image, storage, scale_factor, min_neighbors, min_size, result;
107
+ rb_scan_args(argc, argv, "14", &image, &storage, &scale_factor, &min_neighbors, &min_size);
108
+ if (!rb_obj_is_kind_of(image, cCvMat::rb_class()))
109
+ rb_raise(rb_eTypeError, "argument 1(target-image) should be %s.", rb_class2name(cCvMat::rb_class()));
110
+ double scale = IF_DBL(scale_factor, 1.1);
111
+ if (!(scale > 1.0))
112
+ rb_raise(rb_eArgError, "argument 2 (scale factor) must > 1.0.");
113
+ storage = CHECK_CVMEMSTORAGE(storage);
114
+ CvSeq *seq = cvHaarDetectObjects(CVMAT(image), CVHAARCLASSIFIERCASCADE(self), CVMEMSTORAGE(storage),
115
+ scale, IF_INT(min_neighbors, 3), 0, NIL_P(min_size) ? cvSize(0,0) : VALUE_TO_CVSIZE(min_size));
116
+ result = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvAvgComp::rb_class(), storage);
117
+ if (rb_block_given_p()) {
118
+ for(int i = 0; i < seq->total; i++)
119
+ rb_yield(REFER_OBJECT(cCvAvgComp::rb_class(), cvGetSeqElem(seq, i), storage));
120
+ }
121
+ return result;
122
+ }
123
+
124
+ /*
125
+ * call-seq:
126
+ * detect_objects_with_pruning(image[,scale_factor = 1.1, min_neighbor = 3, min_size = CvSize.new(0,0)]) -> cvseq(include CvAvgComp object)
127
+ * detect_objects_with_pruning(image[,scale_factor = 1.1, min_neighbor = 3, min_size = CvSize.new(0,0)]){|cmp| ... } -> cvseq(include CvAvgComp object)
128
+ *
129
+ * Almost same to #detect_objects (Return detected objects).
130
+ *
131
+ * Before scanning to image, Canny edge detector to reject some image regions
132
+ * that contain too few or too much edges, and thus can not contain the searched object.
133
+ *
134
+ * note: The particular threshold values are tuned for face detection.
135
+ * And in this case the pruning speeds up the processing.
136
+ */
137
+ VALUE
138
+ rb_detect_objects_with_pruning(int argc, VALUE *argv, VALUE self)
139
+ {
140
+ VALUE image, storage, scale_factor, min_neighbors, min_size, result;
141
+ rb_scan_args(argc, argv, "14", &image, &storage, &scale_factor, &min_neighbors, &min_size);
142
+ if (!rb_obj_is_kind_of(image, cCvMat::rb_class()))
143
+ rb_raise(rb_eTypeError, "argument 1(target-image) should be %s.", rb_class2name(cCvMat::rb_class()));
144
+ double scale = IF_DBL(scale_factor, 1.1);
145
+ if (!(scale > 1.0))
146
+ rb_raise(rb_eArgError, "argument 2 (scale factor) must > 1.0.");
147
+ storage = CHECK_CVMEMSTORAGE(storage);
148
+ CvSeq *seq = cvHaarDetectObjects(CVMAT(image), CVHAARCLASSIFIERCASCADE(self), CVMEMSTORAGE(storage),
149
+ scale, IF_INT(min_neighbors, 3), CV_HAAR_DO_CANNY_PRUNING, NIL_P(min_size) ? cvSize(0,0) : VALUE_TO_CVSIZE(min_size));
150
+ result = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvAvgComp::rb_class(), storage);
151
+ if (rb_block_given_p()) {
152
+ for(int i = 0; i < seq->total; i++)
153
+ rb_yield(REFER_OBJECT(cCvAvgComp::rb_class(), cvGetSeqElem(seq, i), storage));
154
+ }
155
+ return result;
156
+ }
157
+
158
+ __NAMESPACE_END_CVHAARCLASSIFERCASCADE
159
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,41 @@
1
+ /************************************************************
2
+
3
+ cvhaarclassifiercascade.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
11
+ #define RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
12
+
13
+ #define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade{
14
+ #define __NAMESPACE_END_CVHAARCLASSIFERCASCADE }
15
+
16
+ #include"opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
27
+
28
+ VALUE rb_load(VALUE klass, VALUE path);
29
+ VALUE rb_save(VALUE self, VALUE name);
30
+ VALUE rb_detect_objects(int argc, VALUE *argv, VALUE self);
31
+ VALUE rb_detect_objects_with_pruning(int argc, VALUE *argv, VALUE self);
32
+
33
+ __NAMESPACE_END_CVHAARCLASSIFERCASCADE
34
+ inline CvHaarClassifierCascade *CVHAARCLASSIFIERCASCADE(VALUE object){
35
+ CvHaarClassifierCascade *ptr;
36
+ Data_Get_Struct(object, CvHaarClassifierCascade, ptr);
37
+ return ptr;
38
+ }
39
+ __NAMESPACE_END_OPENCV
40
+
41
+ #endif // RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
@@ -0,0 +1,200 @@
1
+ /************************************************************
2
+
3
+ cvhistogram.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2008 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvhistogram.h"
11
+ /*
12
+ * Document-class: OpenCV::CvHistogram
13
+ *
14
+ * Muti-dimensional histogram.
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CVHISTOGRAM
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ void
28
+ define_ruby_class()
29
+ {
30
+ if (rb_klass)
31
+ return;
32
+ /*
33
+ * opencv = rb_define_module("OpenCV");
34
+ *
35
+ * note: this comment is used by rdoc.
36
+ */
37
+ VALUE opencv = rb_module_opencv();
38
+
39
+ rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
40
+
41
+ rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
42
+ rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
43
+ rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
44
+ rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
45
+
46
+ rb_define_method(rb_klass, "normalize", RUBY_METHOD_FUNC(rb_normalize), 1);
47
+ rb_define_method(rb_klass, "normalize!", RUBY_METHOD_FUNC(rb_normalize_bang), 1);
48
+ rb_define_method(rb_klass, "thresh", RUBY_METHOD_FUNC(rb_thresh), 1);
49
+ rb_define_alias(rb_klass, "threshold", "thresh");
50
+ rb_define_method(rb_klass, "thresh!", RUBY_METHOD_FUNC(rb_thresh_bang), 1);
51
+ rb_define_alias(rb_klass, "threshold!", "thresh!");
52
+ }
53
+
54
+ VALUE
55
+ rb_allocate(VALUE klass)
56
+ {
57
+ // not yet
58
+ return Qnil;
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * is_uniform? -> true or false
64
+ *
65
+ */
66
+ VALUE
67
+ rb_is_uniform(VALUE self)
68
+ {
69
+ return CV_IS_UNIFORM_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
70
+ }
71
+
72
+ /*
73
+ * call-seq:
74
+ * is_sparse? -> true or false
75
+ *
76
+ */
77
+ VALUE
78
+ rb_is_sparse(VALUE self)
79
+ {
80
+ return CV_IS_SPARSE_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * has_range? -> true or false
86
+ */
87
+ VALUE
88
+ rb_has_range(VALUE self)
89
+ {
90
+ return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
91
+ }
92
+
93
+ /*
94
+ * call-seq:
95
+ * dims -> [int[,int...]]
96
+ */
97
+ VALUE
98
+ rb_dims(VALUE self)
99
+ {
100
+ int size[CV_MAX_DIM];
101
+ int dims = cvGetDims(CVHISTOGRAM(self)->bins, size);
102
+ VALUE result = rb_ary_new2(dims);
103
+ for(int i = 0; i < dims; i++){
104
+ rb_ary_store(result, i, INT2FIX(size[i]));
105
+ }
106
+ return result;
107
+ }
108
+
109
+ /*
110
+ * call-seq:
111
+ * bins -> cvmatnd or cvsparsemat
112
+ */
113
+ VALUE
114
+ rb_bins(VALUE self)
115
+ {
116
+ CvHistogram *hist = CVHISTOGRAM(self);
117
+ return REFER_OBJECT(CV_IS_SPARSE_HIST(hist) ? cCvSparseMat::rb_class() : cCvMatND::rb_class(), hist->bins, self);
118
+ }
119
+
120
+ /*
121
+ * call-seq:
122
+ * copy -> cvhist
123
+ *
124
+ * Clone histogram.
125
+ */
126
+ VALUE
127
+ rb_copy(VALUE self)
128
+ {
129
+ VALUE dest = 0;
130
+ CvHistogram *hist = CVHISTOGRAM(dest);
131
+ cvCopyHist(CVHISTOGRAM(self), &hist);
132
+ return dest;
133
+ }
134
+
135
+ /*
136
+ * call-seq:
137
+ * clear!
138
+ *
139
+ * Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
140
+ */
141
+ VALUE
142
+ rb_clear_bang(VALUE self)
143
+ {
144
+ cvClearHist(CVHISTOGRAM(self));
145
+ return self;
146
+ }
147
+
148
+ /*
149
+ * call-seq:
150
+ * normalize(<i>factor</i>) -> cvhist
151
+ *
152
+ * Return normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
153
+ */
154
+ VALUE
155
+ rb_normalize(VALUE self, VALUE factor)
156
+ {
157
+ return rb_normalize_bang(rb_copy(self), factor);
158
+ }
159
+
160
+ /*
161
+ * call-seq:
162
+ * normalize!(<i>factor</i>) -> self
163
+ *
164
+ * normalizes the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
165
+ */
166
+ VALUE
167
+ rb_normalize_bang(VALUE self, VALUE factor)
168
+ {
169
+ cvNormalizeHist(CVHISTOGRAM(self), NUM2DBL(factor));
170
+ return self;
171
+ }
172
+
173
+ /*
174
+ * call-seq:
175
+ * thresh(<i>factor</i>) -> cvhist
176
+ *
177
+ * Return cleared histogram bins that are below the specified threshold.
178
+ */
179
+ VALUE
180
+ rb_thresh(VALUE self, VALUE factor)
181
+ {
182
+ return rb_thresh_bang(rb_copy(self), factor);
183
+ }
184
+
185
+ /*
186
+ * call-seq:
187
+ * thresh!(<i>factor</i>) -> self
188
+ *
189
+ * Cleares histogram bins that are below the specified threshold.
190
+ */
191
+ VALUE
192
+ rb_thresh_bang(VALUE self, VALUE factor)
193
+ {
194
+ cvThreshHist(CVHISTOGRAM(self), NUM2DBL(factor));
195
+ return self;
196
+ }
197
+
198
+
199
+ __NAMESPACE_END_CVHISTOGRAM
200
+ __NAMESPACE_END_OPENCV