afeld-opencv 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/.gitignore +23 -0
  2. data/Gemfile +6 -0
  3. data/History.txt +5 -0
  4. data/License.txt +30 -0
  5. data/Manifest.txt +217 -0
  6. data/README.rdoc +161 -0
  7. data/Rakefile +52 -0
  8. data/examples/alpha_blend.rb +21 -0
  9. data/examples/box.png +0 -0
  10. data/examples/box_in_scene.png +0 -0
  11. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  12. data/examples/contours/bitmap-contours.png +0 -0
  13. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  14. data/examples/contours/contour_retrieval_modes.rb +139 -0
  15. data/examples/contours/rotated-boxes.jpg +0 -0
  16. data/examples/convexhull.rb +47 -0
  17. data/examples/face_detect.rb +20 -0
  18. data/examples/find_obj.rb +169 -0
  19. data/examples/houghcircle.rb +22 -0
  20. data/examples/inpaint.png +0 -0
  21. data/examples/inpaint.rb +57 -0
  22. data/examples/lenna-rotated.jpg +0 -0
  23. data/examples/lenna.jpg +0 -0
  24. data/examples/match_kdtree.rb +88 -0
  25. data/examples/paint.rb +70 -0
  26. data/examples/snake.rb +43 -0
  27. data/examples/stuff.jpg +0 -0
  28. data/examples/tiffany.jpg +0 -0
  29. data/ext/opencv/curve.cpp +112 -0
  30. data/ext/opencv/curve.h +34 -0
  31. data/ext/opencv/cvavgcomp.cpp +67 -0
  32. data/ext/opencv/cvavgcomp.h +39 -0
  33. data/ext/opencv/cvbox2d.cpp +197 -0
  34. data/ext/opencv/cvbox2d.h +61 -0
  35. data/ext/opencv/cvcapture.cpp +499 -0
  36. data/ext/opencv/cvcapture.h +72 -0
  37. data/ext/opencv/cvchain.cpp +230 -0
  38. data/ext/opencv/cvchain.h +46 -0
  39. data/ext/opencv/cvcircle32f.cpp +116 -0
  40. data/ext/opencv/cvcircle32f.h +52 -0
  41. data/ext/opencv/cvcondensation.cpp +282 -0
  42. data/ext/opencv/cvcondensation.h +49 -0
  43. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  44. data/ext/opencv/cvconnectedcomp.h +49 -0
  45. data/ext/opencv/cvcontour.cpp +297 -0
  46. data/ext/opencv/cvcontour.h +48 -0
  47. data/ext/opencv/cvcontourtree.cpp +91 -0
  48. data/ext/opencv/cvcontourtree.h +41 -0
  49. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  50. data/ext/opencv/cvconvexitydefect.h +42 -0
  51. data/ext/opencv/cverror.cpp +159 -0
  52. data/ext/opencv/cverror.h +28 -0
  53. data/ext/opencv/cvfeaturetree.cpp +125 -0
  54. data/ext/opencv/cvfeaturetree.h +55 -0
  55. data/ext/opencv/cvfont.cpp +208 -0
  56. data/ext/opencv/cvfont.h +64 -0
  57. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  58. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  59. data/ext/opencv/cvhistogram.cpp +546 -0
  60. data/ext/opencv/cvhistogram.h +73 -0
  61. data/ext/opencv/cvhumoments.cpp +139 -0
  62. data/ext/opencv/cvhumoments.h +51 -0
  63. data/ext/opencv/cvline.cpp +154 -0
  64. data/ext/opencv/cvline.h +54 -0
  65. data/ext/opencv/cvmat.cpp +5627 -0
  66. data/ext/opencv/cvmat.h +280 -0
  67. data/ext/opencv/cvmatnd.cpp +44 -0
  68. data/ext/opencv/cvmatnd.h +28 -0
  69. data/ext/opencv/cvmemstorage.cpp +68 -0
  70. data/ext/opencv/cvmemstorage.h +53 -0
  71. data/ext/opencv/cvmoments.cpp +287 -0
  72. data/ext/opencv/cvmoments.h +75 -0
  73. data/ext/opencv/cvpoint.cpp +228 -0
  74. data/ext/opencv/cvpoint.h +64 -0
  75. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  76. data/ext/opencv/cvpoint2d32f.h +63 -0
  77. data/ext/opencv/cvpoint3d32f.cpp +246 -0
  78. data/ext/opencv/cvpoint3d32f.h +66 -0
  79. data/ext/opencv/cvrect.cpp +333 -0
  80. data/ext/opencv/cvrect.h +79 -0
  81. data/ext/opencv/cvscalar.cpp +236 -0
  82. data/ext/opencv/cvscalar.h +71 -0
  83. data/ext/opencv/cvseq.cpp +599 -0
  84. data/ext/opencv/cvseq.h +72 -0
  85. data/ext/opencv/cvsize.cpp +221 -0
  86. data/ext/opencv/cvsize.h +65 -0
  87. data/ext/opencv/cvsize2d32f.cpp +209 -0
  88. data/ext/opencv/cvsize2d32f.h +64 -0
  89. data/ext/opencv/cvslice.cpp +120 -0
  90. data/ext/opencv/cvslice.h +61 -0
  91. data/ext/opencv/cvsparsemat.cpp +44 -0
  92. data/ext/opencv/cvsparsemat.h +28 -0
  93. data/ext/opencv/cvsurfparams.cpp +199 -0
  94. data/ext/opencv/cvsurfparams.h +58 -0
  95. data/ext/opencv/cvsurfpoint.cpp +223 -0
  96. data/ext/opencv/cvsurfpoint.h +52 -0
  97. data/ext/opencv/cvtermcriteria.cpp +192 -0
  98. data/ext/opencv/cvtermcriteria.h +71 -0
  99. data/ext/opencv/cvtwopoints.cpp +116 -0
  100. data/ext/opencv/cvtwopoints.h +51 -0
  101. data/ext/opencv/cvutils.cpp +194 -0
  102. data/ext/opencv/cvutils.h +29 -0
  103. data/ext/opencv/cvvideowriter.cpp +137 -0
  104. data/ext/opencv/cvvideowriter.h +43 -0
  105. data/ext/opencv/gui.cpp +68 -0
  106. data/ext/opencv/gui.h +30 -0
  107. data/ext/opencv/iplconvkernel.cpp +192 -0
  108. data/ext/opencv/iplconvkernel.h +71 -0
  109. data/ext/opencv/iplimage.cpp +576 -0
  110. data/ext/opencv/iplimage.h +70 -0
  111. data/ext/opencv/lib/opencv.rb +3 -0
  112. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  113. data/ext/opencv/lib/opencv/version.rb +3 -0
  114. data/ext/opencv/mouseevent.cpp +181 -0
  115. data/ext/opencv/mouseevent.h +56 -0
  116. data/ext/opencv/opencv.cpp +710 -0
  117. data/ext/opencv/opencv.h +400 -0
  118. data/ext/opencv/pointset.cpp +284 -0
  119. data/ext/opencv/pointset.h +69 -0
  120. data/ext/opencv/trackbar.cpp +121 -0
  121. data/ext/opencv/trackbar.h +69 -0
  122. data/ext/opencv/window.cpp +357 -0
  123. data/ext/opencv/window.h +66 -0
  124. data/extconf.rb +65 -0
  125. data/images/CvMat_sobel.png +0 -0
  126. data/images/CvMat_sub_rect.png +0 -0
  127. data/images/CvSeq_relationmap.png +0 -0
  128. data/images/face_detect_from_lena.jpg +0 -0
  129. data/test/helper.rb +146 -0
  130. data/test/runner.rb +30 -0
  131. data/test/samples/airplane.jpg +0 -0
  132. data/test/samples/baboon.jpg +0 -0
  133. data/test/samples/baboon200.jpg +0 -0
  134. data/test/samples/baboon200_rotated.jpg +0 -0
  135. data/test/samples/blank0.jpg +0 -0
  136. data/test/samples/blank1.jpg +0 -0
  137. data/test/samples/blank2.jpg +0 -0
  138. data/test/samples/blank3.jpg +0 -0
  139. data/test/samples/blank4.jpg +0 -0
  140. data/test/samples/blank5.jpg +0 -0
  141. data/test/samples/blank6.jpg +0 -0
  142. data/test/samples/blank7.jpg +0 -0
  143. data/test/samples/blank8.jpg +0 -0
  144. data/test/samples/blank9.jpg +0 -0
  145. data/test/samples/cat.jpg +0 -0
  146. data/test/samples/contours.jpg +0 -0
  147. data/test/samples/fruits.jpg +0 -0
  148. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  149. data/test/samples/inpaint-mask.bmp +0 -0
  150. data/test/samples/lena-256x256.jpg +0 -0
  151. data/test/samples/lena-32x32.jpg +0 -0
  152. data/test/samples/lena-eyes.jpg +0 -0
  153. data/test/samples/lena-inpaint.jpg +0 -0
  154. data/test/samples/lena.jpg +0 -0
  155. data/test/samples/lines.jpg +0 -0
  156. data/test/samples/messy0.jpg +0 -0
  157. data/test/samples/messy1.jpg +0 -0
  158. data/test/samples/movie_sample.avi +0 -0
  159. data/test/samples/one_way_train_0000.jpg +0 -0
  160. data/test/samples/one_way_train_0001.jpg +0 -0
  161. data/test/samples/partially_blank0.jpg +0 -0
  162. data/test/samples/partially_blank1.jpg +0 -0
  163. data/test/samples/smooth0.jpg +0 -0
  164. data/test/samples/smooth1.jpg +0 -0
  165. data/test/samples/smooth2.jpg +0 -0
  166. data/test/samples/smooth3.jpg +0 -0
  167. data/test/samples/smooth4.jpg +0 -0
  168. data/test/samples/smooth5.jpg +0 -0
  169. data/test/samples/smooth6.jpg +0 -0
  170. data/test/samples/str-cv-rotated.jpg +0 -0
  171. data/test/samples/str-cv.jpg +0 -0
  172. data/test/samples/str-ov.jpg +0 -0
  173. data/test/samples/stuff.jpg +0 -0
  174. data/test/test_curve.rb +43 -0
  175. data/test/test_cvavgcomp.rb +24 -0
  176. data/test/test_cvbox2d.rb +76 -0
  177. data/test/test_cvcapture.rb +183 -0
  178. data/test/test_cvchain.rb +108 -0
  179. data/test/test_cvcircle32f.rb +41 -0
  180. data/test/test_cvconnectedcomp.rb +61 -0
  181. data/test/test_cvcontour.rb +150 -0
  182. data/test/test_cvcontourtree.rb +43 -0
  183. data/test/test_cverror.rb +50 -0
  184. data/test/test_cvfeaturetree.rb +65 -0
  185. data/test/test_cvfont.rb +58 -0
  186. data/test/test_cvhaarclassifiercascade.rb +63 -0
  187. data/test/test_cvhistogram.rb +271 -0
  188. data/test/test_cvhumoments.rb +83 -0
  189. data/test/test_cvline.rb +50 -0
  190. data/test/test_cvmat.rb +2752 -0
  191. data/test/test_cvmat_drawing.rb +318 -0
  192. data/test/test_cvmat_dxt.rb +147 -0
  193. data/test/test_cvmat_imageprocessing.rb +1943 -0
  194. data/test/test_cvmoments.rb +180 -0
  195. data/test/test_cvpoint.rb +75 -0
  196. data/test/test_cvpoint2d32f.rb +75 -0
  197. data/test/test_cvpoint3d32f.rb +93 -0
  198. data/test/test_cvrect.rb +144 -0
  199. data/test/test_cvscalar.rb +113 -0
  200. data/test/test_cvseq.rb +295 -0
  201. data/test/test_cvsize.rb +75 -0
  202. data/test/test_cvsize2d32f.rb +75 -0
  203. data/test/test_cvslice.rb +31 -0
  204. data/test/test_cvsurfparams.rb +57 -0
  205. data/test/test_cvsurfpoint.rb +66 -0
  206. data/test/test_cvtermcriteria.rb +56 -0
  207. data/test/test_cvtwopoints.rb +40 -0
  208. data/test/test_cvvideowriter.rb +58 -0
  209. data/test/test_iplconvkernel.rb +54 -0
  210. data/test/test_iplimage.rb +156 -0
  211. data/test/test_mouseevent.rb +17 -0
  212. data/test/test_opencv.rb +340 -0
  213. data/test/test_pointset.rb +130 -0
  214. data/test/test_preliminary.rb +130 -0
  215. data/test/test_trackbar.rb +47 -0
  216. data/test/test_window.rb +115 -0
  217. metadata +399 -0
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby; coding: utf-8-unix -*-
3
+ require 'test/unit'
4
+ require 'opencv'
5
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
6
+
7
+ include OpenCV
8
+ include GUI
9
+
10
+ # Tests for OpenCV::MouseEvent
11
+ class TestMouseEvent < OpenCVTestCase
12
+ def test_initialize
13
+ assert_not_nil(MouseEvent.new)
14
+ assert_equal(MouseEvent, MouseEvent.new.class)
15
+ end
16
+ end
17
+
@@ -0,0 +1,340 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby; coding: utf-8-unix -*-
3
+ require 'test/unit'
4
+ require 'opencv'
5
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
6
+
7
+ include OpenCV
8
+
9
+ class TestOpenCV < OpenCVTestCase
10
+ def test_constants
11
+ # OpenCV version
12
+ assert_equal('2.4.0', CV_VERSION)
13
+ assert_equal(2, CV_MAJOR_VERSION)
14
+ assert_equal(4, CV_MINOR_VERSION)
15
+ assert_equal(0, CV_SUBMINOR_VERSION)
16
+
17
+ # Depths
18
+ assert_equal(0, CV_8U)
19
+ assert_equal(1, CV_8S)
20
+ assert_equal(2, CV_16U)
21
+ assert_equal(3, CV_16S)
22
+ assert_equal(4, CV_32S)
23
+ assert_equal(5, CV_32F)
24
+ assert_equal(6, CV_64F)
25
+
26
+ # Load image flags
27
+ assert_equal(-1, CV_LOAD_IMAGE_UNCHANGED)
28
+ assert_equal(0, CV_LOAD_IMAGE_GRAYSCALE)
29
+ assert_equal(1, CV_LOAD_IMAGE_COLOR)
30
+ assert_equal(2, CV_LOAD_IMAGE_ANYDEPTH)
31
+ assert_equal(4, CV_LOAD_IMAGE_ANYCOLOR)
32
+
33
+ # Structuring element shapes
34
+ assert_equal(0, CV_SHAPE_RECT)
35
+ assert_equal(1, CV_SHAPE_CROSS)
36
+ assert_equal(2, CV_SHAPE_ELLIPSE)
37
+ assert_equal(100, CV_SHAPE_CUSTOM)
38
+
39
+ # Types of morphological operations
40
+ assert_equal(2, CV_MOP_OPEN)
41
+ assert_equal(3, CV_MOP_CLOSE)
42
+ assert_equal(4, CV_MOP_GRADIENT)
43
+ assert_equal(5, CV_MOP_TOPHAT)
44
+ assert_equal(6, CV_MOP_BLACKHAT)
45
+
46
+ # Types of the smoothing
47
+ assert_equal(0, CV_BLUR_NO_SCALE)
48
+ assert_equal(1, CV_BLUR)
49
+ assert_equal(2, CV_GAUSSIAN)
50
+ assert_equal(3, CV_MEDIAN)
51
+ assert_equal(4, CV_BILATERAL)
52
+
53
+ # Border types
54
+ assert_equal(0, IPL_BORDER_CONSTANT)
55
+ assert_equal(1, IPL_BORDER_REPLICATE)
56
+
57
+ # Thresholding types
58
+ assert_equal(0, CV_THRESH_BINARY)
59
+ assert_equal(1, CV_THRESH_BINARY_INV)
60
+ assert_equal(2, CV_THRESH_TRUNC)
61
+ assert_equal(3, CV_THRESH_TOZERO)
62
+ assert_equal(4, CV_THRESH_TOZERO_INV)
63
+ assert_equal(8, CV_THRESH_OTSU)
64
+
65
+ # Adaptive methods
66
+ assert_equal(0, CV_ADAPTIVE_THRESH_MEAN_C)
67
+ assert_equal(1, CV_ADAPTIVE_THRESH_GAUSSIAN_C)
68
+
69
+ # Retrieval mode
70
+ assert_equal(0, CV_RETR_EXTERNAL)
71
+ assert_equal(1, CV_RETR_LIST)
72
+ assert_equal(2, CV_RETR_CCOMP)
73
+ assert_equal(3, CV_RETR_TREE)
74
+
75
+ # Approximation method
76
+ assert_equal(0, CV_CHAIN_CODE)
77
+ assert_equal(1, CV_CHAIN_APPROX_NONE)
78
+ assert_equal(2, CV_CHAIN_APPROX_SIMPLE)
79
+ assert_equal(3, CV_CHAIN_APPROX_TC89_L1)
80
+ assert_equal(4, CV_CHAIN_APPROX_TC89_KCOS)
81
+ assert_equal(5, CV_LINK_RUNS)
82
+
83
+ # Termination criteria for iterative algorithms
84
+ assert_equal(1, CV_TERMCRIT_ITER)
85
+ assert_equal(1, CV_TERMCRIT_NUMBER)
86
+ assert_equal(2, CV_TERMCRIT_EPS)
87
+
88
+ # Hough transform methods
89
+ assert_equal(0, CV_HOUGH_STANDARD)
90
+ assert_equal(1, CV_HOUGH_PROBABILISTIC)
91
+ assert_equal(2, CV_HOUGH_MULTI_SCALE)
92
+ assert_equal(3, CV_HOUGH_GRADIENT)
93
+
94
+ # Inpaint method
95
+ assert_equal(0, CV_INPAINT_NS)
96
+ assert_equal(1, CV_INPAINT_TELEA)
97
+
98
+ # Match tempalte method
99
+ assert_equal(0, CV_TM_SQDIFF)
100
+ assert_equal(1, CV_TM_SQDIFF_NORMED)
101
+ assert_equal(2, CV_TM_CCORR)
102
+ assert_equal(3, CV_TM_CCORR_NORMED)
103
+ assert_equal(4, CV_TM_CCOEFF)
104
+ assert_equal(5, CV_TM_CCOEFF_NORMED)
105
+
106
+ # Comparison method
107
+ assert_equal(1, CV_CONTOURS_MATCH_I1)
108
+ assert_equal(2, CV_CONTOURS_MATCH_I2)
109
+ assert_equal(3, CV_CONTOURS_MATCH_I3)
110
+
111
+ # Fundamental matrix computing methods
112
+ assert_equal(1, CV_FM_7POINT)
113
+ assert_equal(2, CV_FM_8POINT)
114
+ assert_equal(8, CV_FM_RANSAC)
115
+ assert_equal(4, CV_FM_LMEDS)
116
+
117
+ # Flags of window
118
+ assert_equal(1, CV_WINDOW_AUTOSIZE)
119
+
120
+ # Object detection mode
121
+ assert_equal(1, CV_HAAR_DO_CANNY_PRUNING)
122
+
123
+ # Interpolation methods
124
+ assert_equal(0, CV_INTER_NN)
125
+ assert_equal(1, CV_INTER_LINEAR)
126
+ assert_equal(2, CV_INTER_CUBIC)
127
+ assert_equal(3, CV_INTER_AREA)
128
+
129
+ # Warp affine optional flags
130
+ assert_equal(8, CV_WARP_FILL_OUTLIERS)
131
+ assert_equal(16, CV_WARP_INVERSE_MAP)
132
+
133
+ # SVD operation flags
134
+ assert_equal(1, CV_SVD_MODIFY_A)
135
+ assert_equal(2, CV_SVD_U_T)
136
+ assert_equal(4, CV_SVD_V_T)
137
+
138
+ # Histogram representation format
139
+ assert_equal(0, CV_HIST_ARRAY)
140
+ assert_equal(1, CV_HIST_SPARSE)
141
+ assert_equal(1, CV_HIST_TREE)
142
+ assert_equal(1, CV_HIST_UNIFORM)
143
+
144
+ # Histogram comparison method
145
+ assert_equal(0, CV_COMP_CORREL)
146
+ assert_equal(1, CV_COMP_CHISQR)
147
+ assert_equal(2, CV_COMP_INTERSECT)
148
+ assert_equal(3, CV_COMP_BHATTACHARYYA)
149
+ end
150
+
151
+ def test_symbols
152
+ # Depths
153
+ assert_equal(0, DEPTH[:cv8u])
154
+ assert_equal(1, DEPTH[:cv8s])
155
+ assert_equal(2, DEPTH[:cv16u])
156
+ assert_equal(3, DEPTH[:cv16s])
157
+ assert_equal(4, DEPTH[:cv32s])
158
+ assert_equal(5, DEPTH[:cv32f])
159
+ assert_equal(6, DEPTH[:cv64f])
160
+
161
+ # Inversion methods
162
+ assert_equal(0, INVERSION_METHOD[:lu])
163
+ assert_equal(1, INVERSION_METHOD[:svd])
164
+ assert_equal(2, INVERSION_METHOD[:svd_sym])
165
+ assert_equal(2, INVERSION_METHOD[:svd_symmetric])
166
+
167
+ # Flags for DFT and DCT
168
+ assert_equal(0, DXT_FLAG[:forward])
169
+ assert_equal(1, DXT_FLAG[:inverse])
170
+ assert_equal(2, DXT_FLAG[:scale])
171
+ assert_equal(4, DXT_FLAG[:rows])
172
+
173
+ # Interpolation methods
174
+ assert_equal(0, INTERPOLATION_METHOD[:nn])
175
+ assert_equal(1, INTERPOLATION_METHOD[:linear])
176
+ assert_equal(2, INTERPOLATION_METHOD[:cubic])
177
+ assert_equal(3, INTERPOLATION_METHOD[:area])
178
+
179
+ # Warp affine optional flags
180
+ assert_equal(8, WARP_FLAG[:fill_outliers])
181
+ assert_equal(16, WARP_FLAG[:inverse_map])
182
+
183
+ # Homography calculation methods
184
+ assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all])
185
+ assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds])
186
+ assert_equal(8, HOMOGRAPHY_CALC_METHOD[:ransac])
187
+
188
+ # Anti aliasing flags
189
+ assert_equal(16, CONNECTIVITY[:aa])
190
+ assert_equal(16, CONNECTIVITY[:anti_alias])
191
+
192
+ # Retrieval modes
193
+ assert_equal(0, RETRIEVAL_MODE[:external])
194
+ assert_equal(1, RETRIEVAL_MODE[:list])
195
+ assert_equal(2, RETRIEVAL_MODE[:ccomp])
196
+ assert_equal(3, RETRIEVAL_MODE[:tree])
197
+
198
+ # Approximation methods
199
+ assert_equal(0, APPROX_CHAIN_METHOD[:code])
200
+ assert_equal(1, APPROX_CHAIN_METHOD[:approx_none])
201
+ assert_equal(2, APPROX_CHAIN_METHOD[:approx_simple])
202
+ assert_equal(3, APPROX_CHAIN_METHOD[:approx_tc89_l1])
203
+ assert_equal(4, APPROX_CHAIN_METHOD[:approx_tc89_kcos])
204
+
205
+ # Approximation methods (polygon)
206
+ assert_equal(0, APPROX_POLY_METHOD[:dp])
207
+
208
+ # Match template methods
209
+ assert_equal(0, MATCH_TEMPLATE_METHOD[:sqdiff])
210
+ assert_equal(1, MATCH_TEMPLATE_METHOD[:sqdiff_normed])
211
+ assert_equal(2, MATCH_TEMPLATE_METHOD[:ccorr])
212
+ assert_equal(3, MATCH_TEMPLATE_METHOD[:ccorr_normed])
213
+ assert_equal(4, MATCH_TEMPLATE_METHOD[:ccoeff])
214
+ assert_equal(5, MATCH_TEMPLATE_METHOD[:ccoeff_normed])
215
+
216
+ # Structuring element shapes
217
+ assert_equal(0, STRUCTURING_ELEMENT_SHAPE[:rect])
218
+ assert_equal(1, STRUCTURING_ELEMENT_SHAPE[:cross])
219
+ assert_equal(2, STRUCTURING_ELEMENT_SHAPE[:ellipse])
220
+ assert_equal(100, STRUCTURING_ELEMENT_SHAPE[:custom])
221
+
222
+ # Types of morphological operations
223
+ assert_equal(2, MORPHOLOGICAL_OPERATION[:open])
224
+ assert_equal(3, MORPHOLOGICAL_OPERATION[:close])
225
+ assert_equal(4, MORPHOLOGICAL_OPERATION[:gradient])
226
+ assert_equal(5, MORPHOLOGICAL_OPERATION[:tophat])
227
+ assert_equal(6, MORPHOLOGICAL_OPERATION[:blackhat])
228
+
229
+ # Types of the smoothing
230
+ assert_equal(0, SMOOTHING_TYPE[:blur_no_scale])
231
+ assert_equal(1, SMOOTHING_TYPE[:blur])
232
+ assert_equal(2, SMOOTHING_TYPE[:gaussian])
233
+ assert_equal(3, SMOOTHING_TYPE[:median])
234
+ assert_equal(4, SMOOTHING_TYPE[:bilateral])
235
+
236
+ # Thresholding types
237
+ assert_equal(0, THRESHOLD_TYPE[:binary])
238
+ assert_equal(1, THRESHOLD_TYPE[:binary_inv])
239
+ assert_equal(2, THRESHOLD_TYPE[:trunc])
240
+ assert_equal(3, THRESHOLD_TYPE[:tozero])
241
+ assert_equal(4, THRESHOLD_TYPE[:tozero_inv])
242
+ assert_equal(8, THRESHOLD_TYPE[:otsu])
243
+
244
+ # Hough transform methods
245
+ assert_equal(0, HOUGH_TRANSFORM_METHOD[:standard])
246
+ assert_equal(1, HOUGH_TRANSFORM_METHOD[:probabilistic])
247
+ assert_equal(2, HOUGH_TRANSFORM_METHOD[:multi_scale])
248
+ assert_equal(3, HOUGH_TRANSFORM_METHOD[:gradient])
249
+
250
+ # Inpaint method
251
+ assert_equal(0, INPAINT_METHOD[:ns])
252
+ assert_equal(1, INPAINT_METHOD[:telea])
253
+
254
+ # Comparison method
255
+ assert_equal(1, COMPARISON_METHOD[:i1])
256
+ assert_equal(2, COMPARISON_METHOD[:i2])
257
+ assert_equal(3, COMPARISON_METHOD[:i3])
258
+ end
259
+
260
+ def test_cvt_color_funcs
261
+ mat_1ch = CvMat.new(1, 1, :cv8u, 1)
262
+ mat_1ch[0] = CvScalar.new(10)
263
+
264
+ mat_3ch = CvMat.new(1, 1, :cv8u, 3)
265
+ mat_3ch[0] = CvScalar.new(10, 20, 30)
266
+
267
+ mat_4ch = CvMat.new(1, 1, :cv8u, 4)
268
+ mat_4ch[0] = CvScalar.new(10, 20, 30, 40)
269
+
270
+ gray_rgb = (0.299 * mat_3ch[0][0] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][2]).round
271
+ gray_bgr = (0.299 * mat_3ch[0][2] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][0]).round
272
+
273
+ # RGB(A) <=> RGB(A)
274
+ [mat_3ch.BGR2BGRA, mat_3ch.RGB2RGBA].each { |m|
275
+ assert_equal(CvMat, m.class)
276
+ assert_equal(4, m.channel)
277
+ assert_cvscalar_equal(CvScalar.new(10, 20, 30, 255), m[0])
278
+ }
279
+ [mat_3ch.BGR2RGBA, mat_3ch.RGB2BGRA].each { |m|
280
+ assert_equal(CvMat, m.class)
281
+ assert_equal(4, m.channel)
282
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 255), m[0])
283
+ }
284
+ [mat_4ch.BGRA2BGR, mat_4ch.RGBA2RGB].each { |m|
285
+ assert_equal(CvMat, m.class)
286
+ assert_equal(3, m.channel)
287
+ assert_cvscalar_equal(CvScalar.new(10, 20, 30, 0), m[0])
288
+ }
289
+ [mat_4ch.RGBA2BGR, mat_4ch.BGRA2RGB].each { |m|
290
+ assert_equal(CvMat, m.class)
291
+ assert_equal(3, m.channel)
292
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
293
+ }
294
+ [mat_3ch.BGR2RGB, mat_3ch.RGB2BGR].each { |m|
295
+ assert_equal(CvMat, m.class)
296
+ assert_equal(3, m.channel)
297
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
298
+ }
299
+ [mat_4ch.BGRA2RGBA, mat_4ch.RGBA2BGRA].each { |m|
300
+ assert_equal(CvMat, m.class)
301
+ assert_equal(4, m.channel)
302
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 40), m[0])
303
+ }
304
+
305
+ # RGB <=> GRAY
306
+ [mat_3ch.BGR2GRAY, mat_4ch.BGRA2GRAY].each { |m|
307
+ assert_equal(CvMat, m.class)
308
+ assert_equal(1, m.channel)
309
+ assert_cvscalar_equal(CvScalar.new(gray_bgr, 0, 0, 0), m[0])
310
+ }
311
+ [mat_3ch.RGB2GRAY, mat_4ch.RGBA2GRAY].each { |m|
312
+ assert_equal(CvMat, m.class)
313
+ assert_equal(1, m.channel)
314
+ assert_cvscalar_equal(CvScalar.new(gray_rgb, 0, 0, 0), m[0])
315
+ }
316
+ [mat_1ch.GRAY2BGR, mat_1ch.GRAY2RGB].each { |m|
317
+ assert_equal(CvMat, m.class)
318
+ assert_equal(3, m.channel)
319
+ assert_cvscalar_equal(CvScalar.new(10, 10, 10, 0), m[0])
320
+ }
321
+ [mat_1ch.GRAY2BGRA, mat_1ch.GRAY2RGBA].each { |m|
322
+ assert_equal(CvMat, m.class)
323
+ assert_equal(4, m.channel)
324
+ assert_cvscalar_equal(CvScalar.new(10, 10, 10, 255), m[0])
325
+ }
326
+
327
+ img_3ch = IplImage.new(1, 1, :cv8u, 3)
328
+ assert_equal(IplImage, img_3ch.BGR2GRAY.class)
329
+
330
+ flunk('FIXME: Most cvtColor functions are not tested yet.')
331
+ end
332
+
333
+ def test_build_information
334
+ s = build_information
335
+ assert_equal(String, s.class)
336
+ assert(s =~ /^\s+General configuration for OpenCV #{CV_VERSION}/)
337
+ end
338
+ end
339
+
340
+
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby; coding: utf-8-unix -*-
3
+ require 'test/unit'
4
+ require 'opencv'
5
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
6
+
7
+ include OpenCV
8
+
9
+ # Tests for OpenCV::PointSet
10
+ class TestPointSet < OpenCVTestCase
11
+ def setup
12
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
13
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
14
+ }
15
+ @contour1 = mat0.find_contours
16
+ @contour2 = CvContour.new
17
+ end
18
+
19
+ def test_contour_area
20
+ assert_equal(3118, @contour1.contour_area.to_i)
21
+
22
+ s = CvSlice.new(0, @contour1.size / 2)
23
+ assert_equal(1527, @contour1.contour_area(s).to_i)
24
+
25
+ assert_raise(TypeError) {
26
+ @contour1.contour_area(DUMMY_OBJ)
27
+ }
28
+ assert_raise(CvStsBadArg) {
29
+ @contour2.contour_area
30
+ }
31
+ end
32
+
33
+ def test_fit_ellipse2
34
+ box = @contour1.fit_ellipse2
35
+
36
+ center = box.center
37
+ assert_equal(64, center.x.to_i)
38
+ assert_equal(64, center.y.to_i)
39
+
40
+ size = box.size
41
+ assert_in_delta(63.116, size.width, 0.001)
42
+ assert_in_delta(63.116, size.height, 0.001)
43
+ assert_in_delta(180, box.angle, 0.001)
44
+
45
+ assert_raise(CvStsBadArg) {
46
+ @contour2.fit_ellipse2
47
+ }
48
+ end
49
+
50
+ def test_convex_hull2
51
+ [@contour1.convex_hull2, @contour1.convex_hull2(true)].each { |hull|
52
+ assert_equal(36, hull.size)
53
+ assert_equal(CvContour, hull.class)
54
+ assert_equal(CvPoint, hull[0].class)
55
+ assert_equal(32, hull[0].x)
56
+ assert_equal(64, hull[0].y)
57
+ }
58
+
59
+ hull = @contour1.convex_hull2(false)
60
+ assert_equal(36, hull.size)
61
+ assert_equal(CvContour, hull.class)
62
+ assert_equal(CvPoint, hull[0].class)
63
+ assert_equal(96, hull[0].x)
64
+ assert_equal(64, hull[0].y)
65
+
66
+ @contour1.convex_hull2(DUMMY_OBJ)
67
+ end
68
+
69
+ def test_check_contour_convexity
70
+ assert_false(@contour1.check_contour_convexity)
71
+ end
72
+
73
+ def test_convexity_defects
74
+ hull = @contour1.convex_hull2(true, false)
75
+ defects = @contour1.convexity_defects(hull)
76
+ assert_equal(CvSeq, defects.class)
77
+ assert_equal(CvConvexityDefect, defects[0].class)
78
+ assert_equal(32, defects.size)
79
+
80
+ d = defects[0]
81
+ assert_equal(33, d.start.x)
82
+ assert_equal(57, d.start.y)
83
+ assert_equal(33, d.depth_point.x)
84
+ assert_equal(63, d.depth_point.y)
85
+ assert_equal(32, d.end.x)
86
+ assert_equal(64, d.end.y)
87
+ assert_in_delta(0.8485, d.depth, 0.001)
88
+
89
+ assert_raise(TypeError) {
90
+ @contour1.convexity_defects(DUMMY_OBJ)
91
+ }
92
+ end
93
+
94
+ def test_min_area_rect2
95
+ box = @contour1.min_area_rect2
96
+
97
+ assert_equal(CvBox2D, box.class)
98
+ center = box.center
99
+ assert_equal(64, center.x.to_i)
100
+ assert_equal(64, center.y.to_i)
101
+
102
+ size = box.size
103
+ assert_in_delta(63.356, size.width, 0.001)
104
+ assert_in_delta(63.356, size.height, 0.001)
105
+ assert_in_delta(-8.130, box.angle, 0.001)
106
+
107
+ flunk('FIXME: Currently PointSet#min_area_rect2 causes segmentation fault when "self" is invalid.')
108
+ assert_raise(CvStsBadSize) {
109
+ @contour2.min_area_rect2
110
+ }
111
+ end
112
+
113
+ def test_min_enclosing_circle
114
+ circle = @contour1.min_enclosing_circle
115
+ assert_equal(CvCircle32f, circle.class)
116
+ center = circle.center
117
+ assert_equal(64, center.x.to_i)
118
+ assert_equal(64, center.y.to_i)
119
+ assert_in_delta(32.959, circle.radius, 0.001)
120
+
121
+ assert_raise(CvStsBadArg) {
122
+ @contour2.min_enclosing_circle
123
+ }
124
+ end
125
+
126
+ def test_calc_pgh
127
+ flunk('FIXME: PointSet#calc_pgh is not implemented yet.')
128
+ end
129
+ end
130
+