jf-ruby-opencv 0.0.18

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