ruby-opencv 0.0.11 → 0.0.12.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.yardopts +3 -0
  4. data/Gemfile +1 -0
  5. data/Manifest.txt +2 -14
  6. data/README.md +1 -1
  7. data/Rakefile +10 -1
  8. data/examples/facerec/facerec_lbph.rb +1 -1
  9. data/ext/opencv/algorithm.cpp +6 -1
  10. data/ext/opencv/algorithm.h +1 -1
  11. data/ext/opencv/curve.cpp +48 -33
  12. data/ext/opencv/curve.h +1 -1
  13. data/ext/opencv/cvavgcomp.cpp +22 -25
  14. data/ext/opencv/cvavgcomp.h +1 -1
  15. data/ext/opencv/cvbox2d.cpp +56 -58
  16. data/ext/opencv/cvbox2d.h +1 -1
  17. data/ext/opencv/cvcapture.cpp +210 -109
  18. data/ext/opencv/cvcapture.h +1 -1
  19. data/ext/opencv/cvchain.cpp +71 -71
  20. data/ext/opencv/cvchain.h +1 -1
  21. data/ext/opencv/cvcircle32f.cpp +37 -27
  22. data/ext/opencv/cvcircle32f.h +1 -1
  23. data/ext/opencv/cvconnectedcomp.cpp +49 -36
  24. data/ext/opencv/cvconnectedcomp.h +1 -1
  25. data/ext/opencv/cvcontour.cpp +117 -81
  26. data/ext/opencv/cvcontour.h +1 -1
  27. data/ext/opencv/cvcontourtree.cpp +37 -32
  28. data/ext/opencv/cvcontourtree.h +1 -1
  29. data/ext/opencv/cvconvexitydefect.cpp +33 -44
  30. data/ext/opencv/cvconvexitydefect.h +1 -1
  31. data/ext/opencv/cverror.cpp +22 -66
  32. data/ext/opencv/cverror.h +1 -1
  33. data/ext/opencv/cvfeaturetree.cpp +31 -33
  34. data/ext/opencv/cvfeaturetree.h +1 -1
  35. data/ext/opencv/cvfont.cpp +98 -78
  36. data/ext/opencv/cvfont.h +1 -1
  37. data/ext/opencv/cvhaarclassifiercascade.cpp +39 -59
  38. data/ext/opencv/cvhaarclassifiercascade.h +1 -1
  39. data/ext/opencv/cvhistogram.cpp +259 -90
  40. data/ext/opencv/cvhistogram.h +1 -1
  41. data/ext/opencv/cvhumoments.cpp +99 -60
  42. data/ext/opencv/cvhumoments.h +1 -1
  43. data/ext/opencv/cvline.cpp +45 -40
  44. data/ext/opencv/cvline.h +1 -1
  45. data/ext/opencv/cvmat.cpp +1894 -1829
  46. data/ext/opencv/cvmat.h +2 -3
  47. data/ext/opencv/cvmemstorage.cpp +19 -14
  48. data/ext/opencv/cvmemstorage.h +1 -1
  49. data/ext/opencv/cvmoments.cpp +51 -45
  50. data/ext/opencv/cvmoments.h +1 -1
  51. data/ext/opencv/cvpoint.cpp +32 -26
  52. data/ext/opencv/cvpoint.h +1 -1
  53. data/ext/opencv/cvpoint2d32f.cpp +31 -26
  54. data/ext/opencv/cvpoint2d32f.h +1 -1
  55. data/ext/opencv/cvpoint3d32f.cpp +36 -29
  56. data/ext/opencv/cvpoint3d32f.h +1 -1
  57. data/ext/opencv/cvrect.cpp +38 -33
  58. data/ext/opencv/cvrect.h +1 -1
  59. data/ext/opencv/cvscalar.cpp +50 -45
  60. data/ext/opencv/cvscalar.h +1 -1
  61. data/ext/opencv/cvseq.cpp +53 -47
  62. data/ext/opencv/cvseq.h +1 -1
  63. data/ext/opencv/cvsize.cpp +32 -26
  64. data/ext/opencv/cvsize.h +1 -1
  65. data/ext/opencv/cvsize2d32f.cpp +31 -25
  66. data/ext/opencv/cvsize2d32f.h +1 -1
  67. data/ext/opencv/cvslice.cpp +28 -22
  68. data/ext/opencv/cvslice.h +1 -1
  69. data/ext/opencv/cvsurfparams.cpp +37 -28
  70. data/ext/opencv/cvsurfparams.h +1 -1
  71. data/ext/opencv/cvsurfpoint.cpp +76 -53
  72. data/ext/opencv/cvsurfpoint.h +1 -1
  73. data/ext/opencv/cvtermcriteria.cpp +32 -26
  74. data/ext/opencv/cvtermcriteria.h +1 -1
  75. data/ext/opencv/cvtwopoints.cpp +28 -22
  76. data/ext/opencv/cvtwopoints.h +1 -1
  77. data/ext/opencv/cvvideowriter.cpp +25 -20
  78. data/ext/opencv/cvvideowriter.h +1 -1
  79. data/ext/opencv/eigenfaces.cpp +10 -2
  80. data/ext/opencv/eigenfaces.h +1 -1
  81. data/ext/opencv/facerecognizer.cpp +15 -8
  82. data/ext/opencv/facerecognizer.h +2 -2
  83. data/ext/opencv/fisherfaces.cpp +10 -2
  84. data/ext/opencv/fisherfaces.h +1 -1
  85. data/ext/opencv/gui.cpp +26 -23
  86. data/ext/opencv/gui.h +1 -1
  87. data/ext/opencv/iplconvkernel.cpp +30 -24
  88. data/ext/opencv/iplconvkernel.h +1 -1
  89. data/ext/opencv/iplimage.cpp +49 -42
  90. data/ext/opencv/iplimage.h +1 -1
  91. data/ext/opencv/lbph.cpp +10 -2
  92. data/ext/opencv/lbph.h +1 -1
  93. data/ext/opencv/mouseevent.cpp +30 -25
  94. data/ext/opencv/mouseevent.h +1 -1
  95. data/ext/opencv/opencv.cpp +59 -60
  96. data/ext/opencv/opencv.h +1 -5
  97. data/ext/opencv/pointset.cpp +31 -25
  98. data/ext/opencv/pointset.h +1 -1
  99. data/ext/opencv/trackbar.cpp +27 -21
  100. data/ext/opencv/trackbar.h +1 -1
  101. data/ext/opencv/window.cpp +77 -57
  102. data/ext/opencv/window.h +1 -1
  103. data/lib/opencv/version.rb +2 -1
  104. data/ruby-opencv.gemspec +19 -18
  105. data/test/test_opencv.rb +5 -3
  106. data/yard_extension.rb +5 -0
  107. metadata +13 -27
  108. data/examples/matching_to_many_images/matching_to_many_images.rb +0 -16
  109. data/examples/matching_to_many_images/query.png +0 -0
  110. data/examples/matching_to_many_images/train/1.png +0 -0
  111. data/examples/matching_to_many_images/train/2.png +0 -0
  112. data/examples/matching_to_many_images/train/3.png +0 -0
  113. data/examples/matching_to_many_images/train/trainImages.txt +0 -3
  114. data/ext/opencv/cvcondensation.cpp +0 -282
  115. data/ext/opencv/cvcondensation.h +0 -49
  116. data/ext/opencv/cvmatnd.cpp +0 -44
  117. data/ext/opencv/cvmatnd.h +0 -28
  118. data/ext/opencv/cvsparsemat.cpp +0 -44
  119. data/ext/opencv/cvsparsemat.h +0 -28
  120. data/images/face_detect_from_lena.jpg +0 -0
  121. data/test/test_cvmat_matching.rb +0 -57
@@ -28,7 +28,7 @@ __NAMESPACE_BEGIN_CVFONT
28
28
 
29
29
  VALUE rb_class();
30
30
 
31
- void define_ruby_class();
31
+ void init_ruby_class();
32
32
 
33
33
  VALUE rb_allocate(VALUE klass);
34
34
  VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
@@ -11,11 +11,7 @@
11
11
  /*
12
12
  * Document-class: OpenCV::CvHaarClassifierCascade
13
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
14
+ * Haar Feature-based Cascade Classifier for Object Detection
19
15
  */
20
16
  __NAMESPACE_BEGIN_OPENCV
21
17
  __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
@@ -28,23 +24,6 @@ rb_class()
28
24
  return rb_klass;
29
25
  }
30
26
 
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
- }
47
-
48
27
  VALUE
49
28
  rb_allocate(VALUE klass)
50
29
  {
@@ -61,18 +40,13 @@ cvhaarclassifiercascade_free(void* ptr)
61
40
  }
62
41
 
63
42
  /*
64
- * call-seq:
65
- * CvHaarClassiferCascade.load(<i>path</i>) -> object-detector
66
- *
67
43
  * Load trained cascade of haar classifers from file.
68
- * Object detection classifiers are stored in XML or YAML files.
69
- * sample of object detection classifier files is included by OpenCV.
70
- *
71
- * You can found these at
72
- * C:\Program Files\OpenCV\data\haarcascades\*.xml (Windows, default install path)
73
44
  *
74
- * e.g. you want to try to detect human's face.
75
- * detector = CvHaarClassiferCascade.load("haarcascade_frontalface_alt.xml")
45
+ * @overload load(filename)
46
+ * @param filename [String] Haar classifer file name
47
+ * @return [CvHaarClassifierCascade] Object detector
48
+ * @scope class
49
+ * @opencv_func cvLoad
76
50
  */
77
51
  VALUE
78
52
  rb_load(VALUE klass, VALUE path)
@@ -90,35 +64,23 @@ rb_load(VALUE klass, VALUE path)
90
64
  }
91
65
 
92
66
  /*
93
- * call-seq:
94
- * detect_objects(image[, options]) -> cvseq(include CvAvgComp object)
95
- * detect_objects(image[, options]){|cmp| ... } -> cvseq(include CvAvgComp object)
96
- *
97
- * Detects objects in the image. This method finds rectangular regions in the
98
- * given image that are likely to contain objects the cascade has been trained
99
- * for and return those regions as a sequence of rectangles.
67
+ * Detects objects of different sizes in the input image.
100
68
  *
101
- * * <i>option</i> should be Hash include these keys.
102
- * :scale_factor (should be > 1.0)
103
- * The factor by which the search window is scaled between the subsequent scans,
104
- * 1.1 mean increasing window by 10%.
105
- * :storage
69
+ * @overload detect_objects(image, options = nil)
70
+ * @param image [CvMat,IplImage] Matrix of the type CV_8U containing an image where objects are detected.
71
+ * @param options [Hash] Options
72
+ * @option options [Number] :scale_factor
73
+ * Parameter specifying how much the image size is reduced at each image scale.
74
+ * @option options [Number] :storage
106
75
  * Memory storage to store the resultant sequence of the object candidate rectangles
107
- * :flags
108
- * Mode of operation. Currently the only flag that may be specified is CV_HAAR_DO_CANNY_PRUNING .
109
- * If it is set, the function uses Canny edge detector to reject some image regions that contain
110
- * too few or too much edges and thus can not contain the searched object. The particular threshold
111
- * values are tuned for face detection and in this case the pruning speeds up the processing
112
- * :min_neighbors
113
- * Minimum number (minus 1) of neighbor rectangles that makes up an object.
114
- * All the groups of a smaller number of rectangles than min_neighbors - 1 are rejected.
115
- * If min_neighbors is 0, the function does not any grouping at all and returns all the detected
116
- * candidate rectangles, whitch many be useful if the user wants to apply a customized grouping procedure.
117
- * :min_size
118
- * Minimum window size. By default, it is set to size of samples the classifier has been
119
- * trained on (~20x20 for face detection).
120
- * :max_size
121
- * aximum window size to use. By default, it is set to the size of the image.
76
+ * @option options [Number] :min_neighbors
77
+ * Parameter specifying how many neighbors each candidate rectangle should have to retain it.
78
+ * @option options [CvSize] :min_size
79
+ * Minimum possible object size. Objects smaller than that are ignored.
80
+ * @option options [CvSize] :max_size
81
+ * Maximum possible object size. Objects larger than that are ignored.
82
+ * @return [CvSeq<CvAvgComp>] Detected objects as a list of rectangles
83
+ * @opencv_func cvHaarDetectObjects
122
84
  */
123
85
  VALUE
124
86
  rb_detect_objects(int argc, VALUE *argv, VALUE self)
@@ -164,5 +126,23 @@ rb_detect_objects(int argc, VALUE *argv, VALUE self)
164
126
  return result;
165
127
  }
166
128
 
129
+ void
130
+ init_ruby_class()
131
+ {
132
+ #if 0
133
+ // For documentation using YARD
134
+ VALUE opencv = rb_define_module("OpenCV");
135
+ #endif
136
+
137
+ if (rb_klass)
138
+ return;
139
+
140
+ VALUE opencv = rb_module_opencv();
141
+ rb_klass = rb_define_class_under(opencv, "CvHaarClassifierCascade", rb_cObject);
142
+ rb_define_alloc_func(rb_klass, rb_allocate);
143
+ rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
144
+ rb_define_method(rb_klass, "detect_objects", RUBY_METHOD_FUNC(rb_detect_objects), -1);
145
+ }
146
+
167
147
  __NAMESPACE_END_CVHAARCLASSIFERCASCADE
168
148
  __NAMESPACE_END_OPENCV
@@ -20,7 +20,7 @@ __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
20
20
 
21
21
  VALUE rb_class();
22
22
 
23
- void define_ruby_class();
23
+ void init_ruby_class();
24
24
 
25
25
  VALUE rb_allocate(VALUE klass);
26
26
 
@@ -11,7 +11,7 @@
11
11
  /*
12
12
  * Document-class: OpenCV::CvHistogram
13
13
  *
14
- * Muti-dimensional histogram.
14
+ * Multi-dimensional histogram.
15
15
  */
16
16
  __NAMESPACE_BEGIN_OPENCV
17
17
  __NAMESPACE_BEGIN_CVHISTOGRAM
@@ -24,57 +24,6 @@ rb_class()
24
24
  return rb_klass;
25
25
  }
26
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
- rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
39
-
40
- rb_define_alloc_func(rb_klass, rb_allocate);
41
- rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
42
- rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
43
- rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
44
- rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
45
- rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
46
- rb_define_method(rb_klass, "calc_hist", RUBY_METHOD_FUNC(rb_calc_hist), -1);
47
- rb_define_method(rb_klass, "calc_hist!", RUBY_METHOD_FUNC(rb_calc_hist_bang), -1);
48
- rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), -2);
49
- rb_define_alias(rb_klass, "query_hist_value", "[]");
50
- rb_define_method(rb_klass, "min_max_value", RUBY_METHOD_FUNC(rb_min_max_value), 0);
51
- rb_define_method(rb_klass, "copy_hist", RUBY_METHOD_FUNC(rb_copy_hist), 0);
52
-
53
- rb_define_method(rb_klass, "clear_hist", RUBY_METHOD_FUNC(rb_clear_hist), 0);
54
- rb_define_alias(rb_klass, "clear", "clear_hist");
55
- rb_define_method(rb_klass, "clear_hist!", RUBY_METHOD_FUNC(rb_clear_hist_bang), 0);
56
- rb_define_alias(rb_klass, "clear!", "clear_hist!");
57
-
58
- rb_define_method(rb_klass, "normalize_hist", RUBY_METHOD_FUNC(rb_normalize_hist), 1);
59
- rb_define_alias(rb_klass, "normalize", "normalize_hist");
60
- rb_define_method(rb_klass, "normalize_hist!", RUBY_METHOD_FUNC(rb_normalize_hist_bang), 1);
61
- rb_define_alias(rb_klass, "normalize!", "normalize_hist!");
62
-
63
- rb_define_method(rb_klass, "thresh_hist", RUBY_METHOD_FUNC(rb_thresh_hist), 1);
64
- rb_define_alias(rb_klass, "thresh", "thresh_hist");
65
- rb_define_method(rb_klass, "thresh_hist!", RUBY_METHOD_FUNC(rb_thresh_hist_bang), 1);
66
- rb_define_alias(rb_klass, "thresh!", "thresh_hist!");
67
-
68
- rb_define_method(rb_klass, "set_hist_bin_ranges", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges), -1);
69
- rb_define_method(rb_klass, "set_hist_bin_ranges!", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges_bang), -1);
70
-
71
- rb_define_method(rb_klass, "calc_back_project", RUBY_METHOD_FUNC(rb_calc_back_project), 1);
72
- rb_define_method(rb_klass, "calc_back_project_patch", RUBY_METHOD_FUNC(rb_calc_back_project_patch), 4);
73
-
74
- rb_define_singleton_method(rb_klass, "calc_prob_density", RUBY_METHOD_FUNC(rb_calc_prob_density), -1);
75
- rb_define_singleton_method(rb_klass, "compare_hist", RUBY_METHOD_FUNC(rb_compare_hist), 3);
76
- }
77
-
78
27
  void
79
28
  release_hist(void* ptr)
80
29
  {
@@ -119,6 +68,23 @@ ary2intptr(VALUE ary, int* buff)
119
68
  return buff;
120
69
  }
121
70
 
71
+ /*
72
+ * Creates a histogram
73
+ * @overload new(dims, sizes, type, ranges=nil, uniform=true)
74
+ * @param dims [Integer] Number of histogram dimensions
75
+ * @param sizes [Array<Integer>] Array of the histogram dimension sizes
76
+ * @param type [Integer]
77
+ * Histogram representation format. CV_HIST_ARRAY means that the histogram data is represented
78
+ * as a multi-dimensional dense array CvMatND. CV_HIST_SPARSE means that histogram data is
79
+ * represented as a multi-dimensional sparse array CvSparseMat.
80
+ * @param ranges [Array<Integer>]
81
+ * Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
82
+ * The ranges are used when the histogram is calculated or backprojected to determine which
83
+ * histogram bin corresponds to which value/tuple of values from the input image(s).
84
+ * @param uniform [Boolean] Uniformity flag.
85
+ * @return [CvHistogram] Histogram
86
+ * @opencv_func cvCreateHist
87
+ */
122
88
  VALUE
123
89
  rb_initialize(int argc, VALUE *argv, VALUE self)
124
90
  {
@@ -157,9 +123,10 @@ rb_initialize(int argc, VALUE *argv, VALUE self)
157
123
  }
158
124
 
159
125
  /*
160
- * call-seq:
161
- * is_uniform? -> true or false
162
- *
126
+ * Returns <tt>self</tt> is uniform histogram or not
127
+ * @overload is_uniform?
128
+ * @return [Boolean] Uniform or not
129
+ * @opencv_func CV_IS_UNIFORM_HIST
163
130
  */
164
131
  VALUE
165
132
  rb_is_uniform(VALUE self)
@@ -168,9 +135,10 @@ rb_is_uniform(VALUE self)
168
135
  }
169
136
 
170
137
  /*
171
- * call-seq:
172
- * is_sparse? -> true or false
173
- *
138
+ * Returns <tt>self</tt> is sparse histogram or not
139
+ * @overload is_sparse?
140
+ * @return [Boolean] Sparse or not
141
+ * @opencv_func CV_IS_SPARSE_HIST
174
142
  */
175
143
  VALUE
176
144
  rb_is_sparse(VALUE self)
@@ -179,21 +147,45 @@ rb_is_sparse(VALUE self)
179
147
  }
180
148
 
181
149
  /*
182
- * call-seq:
183
- * has_range? -> true or false
184
- */
150
+ * Returns <tt>self</tt> has range or not
151
+ * @overload has_range?
152
+ * @return [Boolean] Has range or not
153
+ * @opencv_func CV_HIST_HAS_RANGES
154
+ */
185
155
  VALUE
186
156
  rb_has_range(VALUE self)
187
157
  {
188
158
  return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
189
159
  }
190
160
 
161
+ /*
162
+ * Calculates a histogram of a set of arrays.
163
+ * @overload calc_hist(images, accumulate=nil, mask=nil)
164
+ * @param images [Array<IplImage>]
165
+ * Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
166
+ * Each of them can have an arbitrary number of channels.
167
+ * @param accumulate [Boolean]
168
+ * Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated.
169
+ * This feature enables you to compute a single histogram from several sets of arrays,
170
+ * or to update the histogram in time.
171
+ * @param mask [CvMat]
172
+ * Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i].
173
+ * The non-zero mask elements mark the array elements counted in the histogram.
174
+ * @return [CvHistogram] Histogram of a set of arrays
175
+ * @opencv_func cvCalcHist
176
+ */
191
177
  VALUE
192
178
  rb_calc_hist(int argc, VALUE* argv, VALUE self)
193
179
  {
194
180
  return rb_calc_hist_bang(argc, argv, rb_copy_hist(self));
195
181
  }
196
182
 
183
+ /*
184
+ * Calculates a histogram of a set of arrays.
185
+ * @overload calc_hist!(images, accumulate=nil, mask=nil)
186
+ * @see #calc_hist
187
+ * @opencv_func cvCalcHist
188
+ */
197
189
  VALUE
198
190
  rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
199
191
  {
@@ -218,8 +210,17 @@ rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
218
210
  }
219
211
 
220
212
  /*
221
- * call-seq:
222
- * [<i>idx1[,idx2]...</i>]
213
+ * Queries the value of the histogram bin.
214
+ * @overload [](idx0)
215
+ * @overload [](idx0, idx1)
216
+ * @overload [](idx0, idx1, idx2)
217
+ * @overload [](idx0, idx1, idx2, idx3, ...)
218
+ * @param idx* [Integer] *-th index
219
+ * @return [Number] The value of the specified bin of the 1D, 2D, 3D, or N-D histogram.
220
+ * @opencv_func cvQueryHistValue_1D
221
+ * @opencv_func cvQueryHistValue_2D
222
+ * @opencv_func cvQueryHistValue_3D
223
+ * @opencv_func cvQueryHistValue_nD
223
224
  */
224
225
  VALUE
225
226
  rb_aref(VALUE self, VALUE args)
@@ -256,6 +257,18 @@ rb_aref(VALUE self, VALUE args)
256
257
  return rb_float_new((double)value);
257
258
  }
258
259
 
260
+ /*
261
+ * Finds the minimum and maximum histogram bins.
262
+ * @overload min_max_value
263
+ * @return [Array]
264
+ * [min_value, max_value, min_idx, max_idx]: Array of the minimum / maximum value of the histogram
265
+ * and their coordinates.
266
+ * - min_value: The minimum value of the histogram.
267
+ * - max_value: The maximum value of the histogram.
268
+ * - min_idx: The array of coordinates for the minimum.
269
+ * - max_idx: The array of coordinates for the maximum.
270
+ * @opencv_func cvGetMinMaxHistValue
271
+ */
259
272
  VALUE
260
273
  rb_min_max_value(VALUE self)
261
274
  {
@@ -286,8 +299,16 @@ rb_min_max_value(VALUE self)
286
299
  }
287
300
 
288
301
  /*
289
- * call-seq:
290
- * dims -> [int[,int...]]
302
+ * Returns number of array dimensions
303
+ * @overload [](idx0, idx1, ...)
304
+ * @param idx* [Integer] *-th index
305
+ * @return [Array<Integer, Array<Integer>>]
306
+ * [dims, sizes]: Number of array dimensions and its sizes.
307
+ * - dims (Integer): Number of array dimensions
308
+ * - sizes (Array<Integer>): Vector of the array dimension sizes.
309
+ * For 2D arrays the number of rows (height) goes first,
310
+ * number of columns (width) next.
311
+ * @opencv_func cvGetDims
291
312
  */
292
313
  VALUE
293
314
  rb_dims(VALUE self)
@@ -309,10 +330,10 @@ rb_dims(VALUE self)
309
330
  }
310
331
 
311
332
  /*
312
- * call-seq:
313
- * copy_hist -> cvhist
314
- *
315
- * Clone histogram.
333
+ * Clones histogram
334
+ * @overload copy_hist
335
+ * @return [CvHistogram] Copy of the histogram
336
+ * @opencv_func cvCopyHist
316
337
  */
317
338
  VALUE
318
339
  rb_copy_hist(VALUE self)
@@ -328,8 +349,11 @@ rb_copy_hist(VALUE self)
328
349
  }
329
350
 
330
351
  /*
331
- * call-seq:
332
- * clear_hist
352
+ * Sets all histogram bins to 0 in case of dense histogram
353
+ * and removes all histogram bins in case of sparse array.
354
+ * @overload clear_hist
355
+ * @return [CvHistogram] Cleared histogram
356
+ * @opencv_func cvClearHist
333
357
  */
334
358
  VALUE
335
359
  rb_clear_hist(VALUE self)
@@ -338,10 +362,13 @@ rb_clear_hist(VALUE self)
338
362
  }
339
363
 
340
364
  /*
341
- * call-seq:
342
- * clear_hist!
343
- *
344
- * Sets all histogram bins to 0 in case of dense histogram and removes all histogram bins in case of sparse array.
365
+ * Sets all histogram bins to 0 in case of dense histogram
366
+ * and removes all histogram bins in case of sparse array.
367
+ * This method changes <tt>self</tt>.
368
+ * @overload clear_hist!
369
+ * @see #clear_hist
370
+ * @return [CvHistogram] Cleared histogram
371
+ * @opencv_func cvClearHist
345
372
  */
346
373
  VALUE
347
374
  rb_clear_hist_bang(VALUE self)
@@ -356,10 +383,12 @@ rb_clear_hist_bang(VALUE self)
356
383
  }
357
384
 
358
385
  /*
359
- * call-seq:
360
- * normalize(<i>factor</i>) -> cvhist
361
- *
362
- * Return normalized the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
386
+ * Returns normalized the histogram bins by scaling them,
387
+ * such that the sum of the bins becomes equal to <tt>factor</tt>.
388
+ * @overload normalize(factor)
389
+ * @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
390
+ * @return [CvHistogram] Normalized histogram
391
+ * @opencv_func cvNormalizeHist
363
392
  */
364
393
  VALUE
365
394
  rb_normalize_hist(VALUE self, VALUE factor)
@@ -368,10 +397,14 @@ rb_normalize_hist(VALUE self, VALUE factor)
368
397
  }
369
398
 
370
399
  /*
371
- * call-seq:
372
- * normalize!(<i>factor</i>) -> self
373
- *
374
- * normalizes the histogram bins by scaling them, such that the sum of the bins becomes equal to <i>factor</i>.
400
+ * Returns normalized the histogram bins by scaling them,
401
+ * such that the sum of the bins becomes equal to <tt>factor</tt>.
402
+ * This method changes <tt>self</tt>.
403
+ * @overload normalize!(factor)
404
+ * @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
405
+ * @return [CvHistogram] Normalized histogram
406
+ * @see #normalize
407
+ * @opencv_func cvNormalizeHist
375
408
  */
376
409
  VALUE
377
410
  rb_normalize_hist_bang(VALUE self, VALUE factor)
@@ -386,10 +419,11 @@ rb_normalize_hist_bang(VALUE self, VALUE factor)
386
419
  }
387
420
 
388
421
  /*
389
- * call-seq:
390
- * thresh_hist(<i>threshold</i>) -> cvhist
391
- *
392
- * Return cleared histogram bins that are below the specified threshold.
422
+ * Returns cleared histogram bins that are below the specified threshold.
423
+ * @overload thresh_hist(threshold)
424
+ * @param threshold [Number] Threshold value
425
+ * @return [CvHistogram] Cleared histogram
426
+ * @opencv_func cvThreshHist
393
427
  */
394
428
  VALUE
395
429
  rb_thresh_hist(VALUE self, VALUE threshold)
@@ -398,10 +432,13 @@ rb_thresh_hist(VALUE self, VALUE threshold)
398
432
  }
399
433
 
400
434
  /*
401
- * call-seq:
402
- * thresh_hist!(<i>threshold</i>) -> self
403
- *
404
435
  * Cleares histogram bins that are below the specified threshold.
436
+ * This method changes <tt>self</tt>.
437
+ * @overload thresh_hist!(threshold)
438
+ * @param threshold [Number] Threshold value
439
+ * @return [CvHistogram] Cleared histogram
440
+ * @see #thresh_hist
441
+ * @opencv_func cvThreshHist
405
442
  */
406
443
  VALUE
407
444
  rb_thresh_hist_bang(VALUE self, VALUE threshold)
@@ -415,12 +452,39 @@ rb_thresh_hist_bang(VALUE self, VALUE threshold)
415
452
  return self;
416
453
  }
417
454
 
455
+ /*
456
+ * Sets the bounds of the histogram bins.
457
+ * @overload set_hist_bin_ranges(ranges, uniform=true)
458
+ * @param ranges [Array<Number>]
459
+ * Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
460
+ * The ranges are used when the histogram is calculated or backprojected to determine
461
+ * which histogram bin corresponds to which value/tuple of values from the input image(s).
462
+ * @param uniform [Boolean]
463
+ * Uniformity flag.
464
+ * @return [CvHistogram]
465
+ * Histogram
466
+ * @opencv_func cvSetHistBinRanges
467
+ */
418
468
  VALUE
419
469
  rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self)
420
470
  {
421
471
  return rb_set_hist_bin_ranges_bang(argc, argv, rb_copy_hist(self));
422
472
  }
423
473
 
474
+ /*
475
+ * Sets the bounds of the histogram bins. This method changes <tt>self</tt>.
476
+ * @overload set_hist_bin_ranges!(ranges, uniform=true)
477
+ * @param ranges [Array<Number>]
478
+ * Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
479
+ * The ranges are used when the histogram is calculated or backprojected to determine
480
+ * which histogram bin corresponds to which value/tuple of values from the input image(s).
481
+ * @param uniform [Boolean]
482
+ * Uniformity flag.
483
+ * @return [CvHistogram]
484
+ * Histogram
485
+ * @see #set_hist_bin_ranges
486
+ * @opencv_func cvSetHistBinRanges
487
+ */
424
488
  VALUE
425
489
  rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
426
490
  {
@@ -446,6 +510,17 @@ rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
446
510
  return self;
447
511
  }
448
512
 
513
+ /*
514
+ * Calculates the back projection of a histogram.
515
+ * @overload calc_back_project(images)
516
+ * @param images [Array<IplImage>]
517
+ * Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
518
+ * Each of them can have an arbitrary number of channels.
519
+ * @return [CvMat,IplImage]
520
+ * Destination back projection array that is a single-channel array of the same size and depth
521
+ * as the first element of <tt>images</tt>
522
+ * @opencv_func cvCalcBackProject
523
+ */
449
524
  VALUE
450
525
  rb_calc_back_project(VALUE self, VALUE image)
451
526
  {
@@ -475,6 +550,24 @@ rb_calc_back_project(VALUE self, VALUE image)
475
550
  return back_project;
476
551
  }
477
552
 
553
+ /*
554
+ * Locates a template within an image by using a histogram comparison.
555
+ * @overload calc_back_project_patch(images, patch_size, method, factor)
556
+ * @param images [Array<IplImage>] Source arrays.
557
+ * @param pach_size [CvSize] Size of the patch slid though the source image.
558
+ * @param method [Integer]
559
+ * Comparison method that could be one of the following:
560
+ * - <tt>CV_COMP_CORREL</tt>: Correlation
561
+ * - <tt>CV_COMP_CHISQR</tt>: Chi-Square
562
+ * - <tt>CV_COMP_INTERSECT</tt>: Intersection
563
+ * - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
564
+ * - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
565
+ * @param factor [Number]
566
+ * Normalization factor for histograms that affects the normalization scale
567
+ * of the destination image. Pass 1 if not sure.
568
+ * @return [CvMat,IplImage] Destination image.
569
+ * @opencv_func cvCalcBackProject
570
+ */
478
571
  VALUE
479
572
  rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor)
480
573
  {
@@ -507,6 +600,22 @@ rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE meth
507
600
  return dst;
508
601
  }
509
602
 
603
+ /*
604
+ * Compares two histograms.
605
+ * @overload compare_hist(hist1, hist2, method)
606
+ * @param hist1 [CvHistogram] First compared histogram.
607
+ * @param hist2 [CvHistogram] Second compared histogram of the same size as <tt>hist1</tt>.
608
+ * @param method [Integer]
609
+ * Comparison method that could be one of the following:
610
+ * - <tt>CV_COMP_CORREL</tt>: Correlation
611
+ * - <tt>CV_COMP_CHISQR</tt>: Chi-Square
612
+ * - <tt>CV_COMP_INTERSECT</tt>: Intersection
613
+ * - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
614
+ * - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
615
+ * @return [Number] Distance of the two histograms.
616
+ * @scope class
617
+ * @opencv_func cvCompareHist
618
+ */
510
619
  VALUE
511
620
  rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
512
621
  {
@@ -522,6 +631,15 @@ rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
522
631
  return rb_float_new(result);
523
632
  }
524
633
 
634
+ /*
635
+ * Divides one histogram by another.
636
+ * @overload calc_prob_density(hist1, hist2, scale=255)
637
+ * @param hist1 [CvHistogram] First histogram (the divisor).
638
+ * @param hist2 [CvHistogram] Second histogram.
639
+ * @param scale [Number] Scale factor for the destination histogram.
640
+ * @return [CvHistogram] Destination histogram.
641
+ * @opencv_func cvCalcProbDensity
642
+ */
525
643
  VALUE
526
644
  rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
527
645
  {
@@ -542,5 +660,56 @@ rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
542
660
  return dst_hist;
543
661
  }
544
662
 
663
+ void
664
+ init_ruby_class()
665
+ {
666
+ #if 0
667
+ // For documentation using YARD
668
+ VALUE opencv = rb_define_module("OpenCV");
669
+ #endif
670
+
671
+ if (rb_klass)
672
+ return;
673
+
674
+ VALUE opencv = rb_module_opencv();
675
+ rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
676
+ rb_define_alloc_func(rb_klass, rb_allocate);
677
+ rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
678
+ rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
679
+ rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
680
+ rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
681
+ rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
682
+ rb_define_method(rb_klass, "calc_hist", RUBY_METHOD_FUNC(rb_calc_hist), -1);
683
+ rb_define_method(rb_klass, "calc_hist!", RUBY_METHOD_FUNC(rb_calc_hist_bang), -1);
684
+ rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), -2);
685
+ rb_define_alias(rb_klass, "query_hist_value", "[]");
686
+ rb_define_method(rb_klass, "min_max_value", RUBY_METHOD_FUNC(rb_min_max_value), 0);
687
+ rb_define_method(rb_klass, "copy_hist", RUBY_METHOD_FUNC(rb_copy_hist), 0);
688
+
689
+ rb_define_method(rb_klass, "clear_hist", RUBY_METHOD_FUNC(rb_clear_hist), 0);
690
+ rb_define_alias(rb_klass, "clear", "clear_hist");
691
+ rb_define_method(rb_klass, "clear_hist!", RUBY_METHOD_FUNC(rb_clear_hist_bang), 0);
692
+ rb_define_alias(rb_klass, "clear!", "clear_hist!");
693
+
694
+ rb_define_method(rb_klass, "normalize_hist", RUBY_METHOD_FUNC(rb_normalize_hist), 1);
695
+ rb_define_alias(rb_klass, "normalize", "normalize_hist");
696
+ rb_define_method(rb_klass, "normalize_hist!", RUBY_METHOD_FUNC(rb_normalize_hist_bang), 1);
697
+ rb_define_alias(rb_klass, "normalize!", "normalize_hist!");
698
+
699
+ rb_define_method(rb_klass, "thresh_hist", RUBY_METHOD_FUNC(rb_thresh_hist), 1);
700
+ rb_define_alias(rb_klass, "thresh", "thresh_hist");
701
+ rb_define_method(rb_klass, "thresh_hist!", RUBY_METHOD_FUNC(rb_thresh_hist_bang), 1);
702
+ rb_define_alias(rb_klass, "thresh!", "thresh_hist!");
703
+
704
+ rb_define_method(rb_klass, "set_hist_bin_ranges", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges), -1);
705
+ rb_define_method(rb_klass, "set_hist_bin_ranges!", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges_bang), -1);
706
+
707
+ rb_define_method(rb_klass, "calc_back_project", RUBY_METHOD_FUNC(rb_calc_back_project), 1);
708
+ rb_define_method(rb_klass, "calc_back_project_patch", RUBY_METHOD_FUNC(rb_calc_back_project_patch), 4);
709
+
710
+ rb_define_singleton_method(rb_klass, "calc_prob_density", RUBY_METHOD_FUNC(rb_calc_prob_density), -1);
711
+ rb_define_singleton_method(rb_klass, "compare_hist", RUBY_METHOD_FUNC(rb_compare_hist), 3);
712
+ }
713
+
545
714
  __NAMESPACE_END_CVHISTOGRAM
546
715
  __NAMESPACE_END_OPENCV