ruby-opencv 0.0.10-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +26 -0
  3. data/DEVELOPERS_NOTE.md +137 -0
  4. data/Gemfile +8 -0
  5. data/History.txt +5 -0
  6. data/License.txt +30 -0
  7. data/Manifest.txt +227 -0
  8. data/README.md +98 -0
  9. data/Rakefile +90 -0
  10. data/config.yml +7 -0
  11. data/examples/alpha_blend.rb +21 -0
  12. data/examples/box.png +0 -0
  13. data/examples/box_in_scene.png +0 -0
  14. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  15. data/examples/contours/bitmap-contours.png +0 -0
  16. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  17. data/examples/contours/contour_retrieval_modes.rb +139 -0
  18. data/examples/contours/rotated-boxes.jpg +0 -0
  19. data/examples/convexhull.rb +47 -0
  20. data/examples/face_detect.rb +20 -0
  21. data/examples/find_obj.rb +169 -0
  22. data/examples/houghcircle.rb +22 -0
  23. data/examples/inpaint.png +0 -0
  24. data/examples/inpaint.rb +57 -0
  25. data/examples/lenna-rotated.jpg +0 -0
  26. data/examples/lenna.jpg +0 -0
  27. data/examples/match_kdtree.rb +88 -0
  28. data/examples/matching_to_many_images.rb +16 -0
  29. data/examples/matching_to_many_images/query.png +0 -0
  30. data/examples/matching_to_many_images/train/1.png +0 -0
  31. data/examples/matching_to_many_images/train/2.png +0 -0
  32. data/examples/matching_to_many_images/train/3.png +0 -0
  33. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  34. data/examples/paint.rb +70 -0
  35. data/examples/snake.rb +43 -0
  36. data/examples/stuff.jpg +0 -0
  37. data/examples/tiffany.jpg +0 -0
  38. data/ext/opencv/curve.cpp +112 -0
  39. data/ext/opencv/curve.h +34 -0
  40. data/ext/opencv/cvavgcomp.cpp +67 -0
  41. data/ext/opencv/cvavgcomp.h +39 -0
  42. data/ext/opencv/cvbox2d.cpp +197 -0
  43. data/ext/opencv/cvbox2d.h +61 -0
  44. data/ext/opencv/cvcapture.cpp +506 -0
  45. data/ext/opencv/cvcapture.h +72 -0
  46. data/ext/opencv/cvchain.cpp +233 -0
  47. data/ext/opencv/cvchain.h +46 -0
  48. data/ext/opencv/cvcircle32f.cpp +116 -0
  49. data/ext/opencv/cvcircle32f.h +52 -0
  50. data/ext/opencv/cvcondensation.cpp +282 -0
  51. data/ext/opencv/cvcondensation.h +49 -0
  52. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  53. data/ext/opencv/cvconnectedcomp.h +49 -0
  54. data/ext/opencv/cvcontour.cpp +296 -0
  55. data/ext/opencv/cvcontour.h +48 -0
  56. data/ext/opencv/cvcontourtree.cpp +91 -0
  57. data/ext/opencv/cvcontourtree.h +41 -0
  58. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  59. data/ext/opencv/cvconvexitydefect.h +42 -0
  60. data/ext/opencv/cverror.cpp +159 -0
  61. data/ext/opencv/cverror.h +28 -0
  62. data/ext/opencv/cvfeaturetree.cpp +125 -0
  63. data/ext/opencv/cvfeaturetree.h +55 -0
  64. data/ext/opencv/cvfont.cpp +208 -0
  65. data/ext/opencv/cvfont.h +64 -0
  66. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  67. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  68. data/ext/opencv/cvhistogram.cpp +546 -0
  69. data/ext/opencv/cvhistogram.h +73 -0
  70. data/ext/opencv/cvhumoments.cpp +139 -0
  71. data/ext/opencv/cvhumoments.h +51 -0
  72. data/ext/opencv/cvline.cpp +154 -0
  73. data/ext/opencv/cvline.h +54 -0
  74. data/ext/opencv/cvmat.cpp +5848 -0
  75. data/ext/opencv/cvmat.h +284 -0
  76. data/ext/opencv/cvmatnd.cpp +44 -0
  77. data/ext/opencv/cvmatnd.h +28 -0
  78. data/ext/opencv/cvmemstorage.cpp +68 -0
  79. data/ext/opencv/cvmemstorage.h +53 -0
  80. data/ext/opencv/cvmoments.cpp +287 -0
  81. data/ext/opencv/cvmoments.h +75 -0
  82. data/ext/opencv/cvpoint.cpp +228 -0
  83. data/ext/opencv/cvpoint.h +64 -0
  84. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  85. data/ext/opencv/cvpoint2d32f.h +63 -0
  86. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  87. data/ext/opencv/cvpoint3d32f.h +66 -0
  88. data/ext/opencv/cvrect.cpp +333 -0
  89. data/ext/opencv/cvrect.h +79 -0
  90. data/ext/opencv/cvscalar.cpp +236 -0
  91. data/ext/opencv/cvscalar.h +71 -0
  92. data/ext/opencv/cvseq.cpp +599 -0
  93. data/ext/opencv/cvseq.h +74 -0
  94. data/ext/opencv/cvsize.cpp +221 -0
  95. data/ext/opencv/cvsize.h +65 -0
  96. data/ext/opencv/cvsize2d32f.cpp +209 -0
  97. data/ext/opencv/cvsize2d32f.h +64 -0
  98. data/ext/opencv/cvslice.cpp +120 -0
  99. data/ext/opencv/cvslice.h +61 -0
  100. data/ext/opencv/cvsparsemat.cpp +44 -0
  101. data/ext/opencv/cvsparsemat.h +28 -0
  102. data/ext/opencv/cvsurfparams.cpp +199 -0
  103. data/ext/opencv/cvsurfparams.h +58 -0
  104. data/ext/opencv/cvsurfpoint.cpp +223 -0
  105. data/ext/opencv/cvsurfpoint.h +52 -0
  106. data/ext/opencv/cvtermcriteria.cpp +192 -0
  107. data/ext/opencv/cvtermcriteria.h +71 -0
  108. data/ext/opencv/cvtwopoints.cpp +116 -0
  109. data/ext/opencv/cvtwopoints.h +51 -0
  110. data/ext/opencv/cvutils.cpp +192 -0
  111. data/ext/opencv/cvutils.h +30 -0
  112. data/ext/opencv/cvvideowriter.cpp +137 -0
  113. data/ext/opencv/cvvideowriter.h +43 -0
  114. data/ext/opencv/extconf.rb +83 -0
  115. data/ext/opencv/gui.cpp +68 -0
  116. data/ext/opencv/gui.h +30 -0
  117. data/ext/opencv/iplconvkernel.cpp +192 -0
  118. data/ext/opencv/iplconvkernel.h +71 -0
  119. data/ext/opencv/iplimage.cpp +644 -0
  120. data/ext/opencv/iplimage.h +73 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +727 -0
  124. data/ext/opencv/opencv.h +400 -0
  125. data/ext/opencv/pointset.cpp +274 -0
  126. data/ext/opencv/pointset.h +68 -0
  127. data/ext/opencv/trackbar.cpp +121 -0
  128. data/ext/opencv/trackbar.h +69 -0
  129. data/ext/opencv/window.cpp +357 -0
  130. data/ext/opencv/window.h +66 -0
  131. data/images/CvMat_sobel.png +0 -0
  132. data/images/CvMat_sub_rect.png +0 -0
  133. data/images/CvSeq_relationmap.png +0 -0
  134. data/images/face_detect_from_lena.jpg +0 -0
  135. data/lib/1.9/opencv.so +0 -0
  136. data/lib/2.0/opencv.so +0 -0
  137. data/lib/opencv.rb +12 -0
  138. data/lib/opencv/psyched_yaml.rb +22 -0
  139. data/lib/opencv/version.rb +3 -0
  140. data/ruby-opencv.gemspec +44 -0
  141. data/test/helper.rb +166 -0
  142. data/test/runner.rb +30 -0
  143. data/test/samples/airplane.jpg +0 -0
  144. data/test/samples/baboon.jpg +0 -0
  145. data/test/samples/baboon200.jpg +0 -0
  146. data/test/samples/baboon200_rotated.jpg +0 -0
  147. data/test/samples/blank0.jpg +0 -0
  148. data/test/samples/blank1.jpg +0 -0
  149. data/test/samples/blank2.jpg +0 -0
  150. data/test/samples/blank3.jpg +0 -0
  151. data/test/samples/blank4.jpg +0 -0
  152. data/test/samples/blank5.jpg +0 -0
  153. data/test/samples/blank6.jpg +0 -0
  154. data/test/samples/blank7.jpg +0 -0
  155. data/test/samples/blank8.jpg +0 -0
  156. data/test/samples/blank9.jpg +0 -0
  157. data/test/samples/cat.jpg +0 -0
  158. data/test/samples/chessboard.jpg +0 -0
  159. data/test/samples/contours.jpg +0 -0
  160. data/test/samples/fruits.jpg +0 -0
  161. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  162. data/test/samples/inpaint-mask.bmp +0 -0
  163. data/test/samples/lena-256x256.jpg +0 -0
  164. data/test/samples/lena-32x32.jpg +0 -0
  165. data/test/samples/lena-eyes.jpg +0 -0
  166. data/test/samples/lena-inpaint.jpg +0 -0
  167. data/test/samples/lena.jpg +0 -0
  168. data/test/samples/lines.jpg +0 -0
  169. data/test/samples/messy0.jpg +0 -0
  170. data/test/samples/messy1.jpg +0 -0
  171. data/test/samples/movie_sample.avi +0 -0
  172. data/test/samples/one_way_train_0000.jpg +0 -0
  173. data/test/samples/one_way_train_0001.jpg +0 -0
  174. data/test/samples/partially_blank0.jpg +0 -0
  175. data/test/samples/partially_blank1.jpg +0 -0
  176. data/test/samples/smooth0.jpg +0 -0
  177. data/test/samples/smooth1.jpg +0 -0
  178. data/test/samples/smooth2.jpg +0 -0
  179. data/test/samples/smooth3.jpg +0 -0
  180. data/test/samples/smooth4.jpg +0 -0
  181. data/test/samples/smooth5.jpg +0 -0
  182. data/test/samples/smooth6.jpg +0 -0
  183. data/test/samples/str-cv-rotated.jpg +0 -0
  184. data/test/samples/str-cv.jpg +0 -0
  185. data/test/samples/str-ov.jpg +0 -0
  186. data/test/samples/stuff.jpg +0 -0
  187. data/test/test_curve.rb +43 -0
  188. data/test/test_cvavgcomp.rb +24 -0
  189. data/test/test_cvbox2d.rb +76 -0
  190. data/test/test_cvcapture.rb +183 -0
  191. data/test/test_cvchain.rb +108 -0
  192. data/test/test_cvcircle32f.rb +41 -0
  193. data/test/test_cvconnectedcomp.rb +61 -0
  194. data/test/test_cvcontour.rb +150 -0
  195. data/test/test_cvcontourtree.rb +43 -0
  196. data/test/test_cverror.rb +50 -0
  197. data/test/test_cvfeaturetree.rb +65 -0
  198. data/test/test_cvfont.rb +58 -0
  199. data/test/test_cvhaarclassifiercascade.rb +63 -0
  200. data/test/test_cvhistogram.rb +271 -0
  201. data/test/test_cvhumoments.rb +83 -0
  202. data/test/test_cvline.rb +50 -0
  203. data/test/test_cvmat.rb +2947 -0
  204. data/test/test_cvmat_drawing.rb +349 -0
  205. data/test/test_cvmat_dxt.rb +150 -0
  206. data/test/test_cvmat_imageprocessing.rb +2015 -0
  207. data/test/test_cvmat_matching.rb +57 -0
  208. data/test/test_cvmoments.rb +180 -0
  209. data/test/test_cvpoint.rb +75 -0
  210. data/test/test_cvpoint2d32f.rb +75 -0
  211. data/test/test_cvpoint3d32f.rb +93 -0
  212. data/test/test_cvrect.rb +144 -0
  213. data/test/test_cvscalar.rb +113 -0
  214. data/test/test_cvseq.rb +295 -0
  215. data/test/test_cvsize.rb +75 -0
  216. data/test/test_cvsize2d32f.rb +75 -0
  217. data/test/test_cvslice.rb +31 -0
  218. data/test/test_cvsurfparams.rb +57 -0
  219. data/test/test_cvsurfpoint.rb +66 -0
  220. data/test/test_cvtermcriteria.rb +56 -0
  221. data/test/test_cvtwopoints.rb +40 -0
  222. data/test/test_cvvideowriter.rb +58 -0
  223. data/test/test_iplconvkernel.rb +54 -0
  224. data/test/test_iplimage.rb +236 -0
  225. data/test/test_mouseevent.rb +17 -0
  226. data/test/test_opencv.rb +329 -0
  227. data/test/test_pointset.rb +126 -0
  228. data/test/test_preliminary.rb +130 -0
  229. data/test/test_trackbar.rb +47 -0
  230. data/test/test_window.rb +115 -0
  231. metadata +386 -0
@@ -0,0 +1,54 @@
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::IplConvKernel
10
+ class TestIplConvKernel < OpenCVTestCase
11
+ def test_initialize
12
+ [:rect, :cross, :ellipse, CV_SHAPE_RECT, CV_SHAPE_CROSS, CV_SHAPE_ELLIPSE].each { |shape|
13
+ kernel = IplConvKernel.new(5, 5, 2, 2, shape)
14
+ assert_not_nil(kernel)
15
+ }
16
+
17
+ values = [1] * 25
18
+ [:custom, CV_SHAPE_CUSTOM].each { |shape|
19
+ kernel = IplConvKernel.new(5, 5, 2, 2, shape, values)
20
+ assert_not_nil(kernel)
21
+ }
22
+
23
+ [:custom, CV_SHAPE_CUSTOM].each { |shape|
24
+ assert_raise(ArgumentError) {
25
+ IplConvKernel.new(5, 5, 2, 2, shape)
26
+ }
27
+ }
28
+
29
+ assert_raise(TypeError) {
30
+ IplConvKernel.new(5, 5, 2, 2, :foobar)
31
+ }
32
+ end
33
+
34
+ def test_size
35
+ kernel = IplConvKernel.new(5, 4, 2, 2, :rect)
36
+ size = kernel.size
37
+ assert_equal(5, size.width)
38
+ assert_equal(4, size.height)
39
+
40
+ assert_equal(5, kernel.cols)
41
+ assert_equal(4, kernel.rows)
42
+ end
43
+
44
+ def test_anchor
45
+ kernel = IplConvKernel.new(5, 4, 3, 2, :rect)
46
+ a = kernel.anchor
47
+ assert_equal(3, a.x)
48
+ assert_equal(2, a.y)
49
+
50
+ assert_equal(3, kernel.anchor_x)
51
+ assert_equal(2, kernel.anchor_y)
52
+ end
53
+ end
54
+
@@ -0,0 +1,236 @@
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::IplImage
10
+ class TestIplImage < OpenCVTestCase
11
+ def should_classify_images_as(filename, classification)
12
+ assert_equal(OpenCV::IplImage::load(filename, OpenCV::CV_LOAD_IMAGE_GRAYSCALE).smoothness[0], classification)
13
+ end
14
+
15
+ def test_initialize
16
+ img = IplImage.new(10, 20)
17
+ assert_equal(10, img.width)
18
+ assert_equal(20, img.height)
19
+ assert_equal(:cv8u, img.depth)
20
+ assert_equal(3, img.channel)
21
+
22
+ img = IplImage.new(30, 40, :cv32f, 1)
23
+ assert_equal(30, img.width)
24
+ assert_equal(40, img.height)
25
+ assert_equal(:cv32f, img.depth)
26
+ assert_equal(1, img.channel)
27
+ end
28
+
29
+ def test_load
30
+ img1 = IplImage.load(FILENAME_CAT)
31
+ assert_equal(IplImage, img1.class)
32
+ assert_equal(375, img1.width)
33
+ assert_equal(500, img1.height)
34
+ assert_equal(:cv8u, img1.depth)
35
+ assert_equal(3, img1.channel)
36
+
37
+ img2 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
38
+ assert_equal(IplImage, img2.class)
39
+ assert_equal(375, img2.width)
40
+ assert_equal(500, img2.height)
41
+ assert_equal(:cv8u, img2.depth)
42
+ assert_equal(1, img2.channel)
43
+
44
+ img3 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR)
45
+ assert_equal(IplImage, img3.class)
46
+ assert_equal(375, img3.width)
47
+ assert_equal(500, img3.height)
48
+ assert_equal(:cv8u, img3.depth)
49
+ assert_equal(3, img3.channel)
50
+
51
+ assert_raise(ArgumentError) {
52
+ IplImage.load
53
+ }
54
+ assert_raise(TypeError) {
55
+ IplImage.load(123)
56
+ }
57
+ assert_raise(TypeError) {
58
+ IplImage.load(FILENAME_CAT, 'foobar')
59
+ }
60
+ assert_raise(StandardError) {
61
+ IplImage.load('file/does/not/exist')
62
+ }
63
+
64
+ # Uncomment the following lines to show the results
65
+ # snap img1, img2, img3
66
+ end
67
+
68
+ def test_decode
69
+ data = nil
70
+ open(FILENAME_CAT, 'rb') { |f|
71
+ data = f.read
72
+ }
73
+ data_ary = data.unpack("c*")
74
+ data_mat = CvMat.new(1, data_ary.size).set_data(data_ary)
75
+ expected = IplImage.load(FILENAME_CAT)
76
+
77
+ img1 = IplImage.decode(data)
78
+ img2 = IplImage.decode(data_ary)
79
+ img3 = IplImage.decode(data_mat)
80
+ img4 = IplImage.decode(data, CV_LOAD_IMAGE_COLOR)
81
+ img5 = IplImage.decode(data_ary, CV_LOAD_IMAGE_COLOR)
82
+ img6 = IplImage.decode(data_mat, CV_LOAD_IMAGE_COLOR)
83
+ expected_hash = hash_img(expected)
84
+
85
+ [img1, img2, img3, img4, img5, img6].each { |img|
86
+ assert_equal(IplImage, img.class)
87
+ assert_equal(expected.rows, img.rows)
88
+ assert_equal(expected.cols, img.cols)
89
+ assert_equal(expected.channel, img.channel)
90
+ assert_equal(expected_hash, hash_img(img))
91
+ }
92
+
93
+ expected_c1 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_GRAYSCALE)
94
+ img1c1 = IplImage.decode(data, CV_LOAD_IMAGE_GRAYSCALE)
95
+ img2c1 = IplImage.decode(data_ary, CV_LOAD_IMAGE_GRAYSCALE)
96
+ img3c1 = IplImage.decode(data_mat, CV_LOAD_IMAGE_GRAYSCALE)
97
+ expected_hash_c1 = hash_img(expected_c1)
98
+
99
+ [img1c1, img2c1, img3c1].each { |img|
100
+ assert_equal(IplImage, img.class)
101
+ assert_equal(expected_c1.rows, img.rows)
102
+ assert_equal(expected_c1.cols, img.cols)
103
+ assert_equal(expected_c1.channel, img.channel)
104
+ assert_equal(expected_hash_c1, hash_img(img))
105
+ }
106
+
107
+ assert_raise(TypeError) {
108
+ IplImage.decode(DUMMY_OBJ)
109
+ }
110
+ assert_raise(TypeError) {
111
+ IplImage.decode(data, DUMMY_OBJ)
112
+ }
113
+
114
+ # Uncomment the following line to show the result images
115
+ # snap img1, img2, img3
116
+ end
117
+
118
+ def test_roi
119
+ img = IplImage.new(20, 30)
120
+ rect = img.roi
121
+ assert_equal(0, rect.x)
122
+ assert_equal(0, rect.y)
123
+ assert_equal(img.width, rect.width)
124
+ assert_equal(img.height, rect.height)
125
+
126
+ img.set_roi(CvRect.new(2, 3, 10, 20))
127
+ rect = img.roi
128
+ assert_equal(2, rect.x)
129
+ assert_equal(3, rect.y)
130
+ assert_equal(10, rect.width)
131
+ assert_equal(20, rect.height)
132
+
133
+ img.reset_roi
134
+ rect = img.roi
135
+ assert_equal(0, rect.x)
136
+ assert_equal(0, rect.y)
137
+ assert_equal(img.width, rect.width)
138
+ assert_equal(img.height, rect.height)
139
+
140
+ img.set_roi(CvRect.new(1, 2, 5, 6)) {|image|
141
+ rect = image.roi
142
+ assert_equal(1, rect.x)
143
+ assert_equal(2, rect.y)
144
+ assert_equal(5, rect.width)
145
+ assert_equal(6, rect.height)
146
+ }
147
+ rect = img.roi
148
+ assert_equal(0, rect.x)
149
+ assert_equal(0, rect.y)
150
+ assert_equal(img.width, rect.width)
151
+ assert_equal(img.height, rect.height)
152
+
153
+ # Alias
154
+ img.roi = CvRect.new(4, 5, 11, 12)
155
+ rect = img.roi
156
+ assert_equal(4, rect.x)
157
+ assert_equal(5, rect.y)
158
+ assert_equal(11, rect.width)
159
+ assert_equal(12, rect.height)
160
+ end
161
+
162
+ def test_coi
163
+ img = IplImage.new(20, 30)
164
+ assert_equal(0, img.coi)
165
+
166
+ img.set_coi(1)
167
+ assert_equal(1, img.coi)
168
+
169
+ img.reset_coi
170
+ assert_equal(0, img.coi)
171
+
172
+ img.set_coi(2) {|image|
173
+ assert_equal(2, image.coi)
174
+ }
175
+ assert_equal(0, img.coi)
176
+
177
+ # Alias
178
+ img.coi = 1
179
+ assert_equal(1, img.coi)
180
+ end
181
+
182
+ def test_smoothness
183
+ asset_path = File.join(File.dirname(__FILE__), 'samples')
184
+
185
+ for image in Array.new(7) { |e| e = File.join(asset_path, "smooth%d.jpg") % e } do
186
+ should_classify_images_as image, :smooth
187
+ end
188
+
189
+ for image in Array.new(2) { |e| e = File.join(asset_path, "messy%d.jpg") % e } do
190
+ should_classify_images_as image, :messy
191
+ end
192
+
193
+ for image in Array.new(10) { |e| e = File.join(asset_path, "blank%d.jpg") % e } do
194
+ should_classify_images_as image, :blank
195
+ end
196
+
197
+ for image in Array.new(2) { |e| e = File.join(asset_path, "partially_blank%d.jpg") % e } do
198
+ should_classify_images_as image, :blank
199
+ end
200
+ end
201
+
202
+ def test_pyr_segmentation
203
+ img0 = IplImage.load(FILENAME_CAT, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH)
204
+ img0.set_roi(CvRect.new(0, 0, 256, 512))
205
+ img1, seq1 = img0.pyr_segmentation(2, 255, 50)
206
+ assert_equal('963b26f51b14f175fbbf128e9b9e979f', hash_img(img1))
207
+ assert_equal(11, seq1.total)
208
+
209
+ assert_raise(CvStsAssert) {
210
+ img0.pyr_segmentation(-1, 255, 50)
211
+ }
212
+ assert_raise(CvStsAssert) {
213
+ img0.pyr_segmentation(1000, 255, 50)
214
+ }
215
+ assert_raise(CvStsAssert) {
216
+ img0.pyr_segmentation(4, -1, 50)
217
+ }
218
+ assert_raise(CvStsAssert) {
219
+ img0.pyr_segmentation(4, 255, -1)
220
+ }
221
+ assert_raise(TypeError) {
222
+ img0.pyr_segmentation(DUMMY_OBJ, 255, 50)
223
+ }
224
+ assert_raise(TypeError) {
225
+ img0.pyr_segmentation(4, DUMMY_OBJ, 50)
226
+ }
227
+ assert_raise(TypeError) {
228
+ img0.pyr_segmentation(4, 255, DUMMY_OBJ)
229
+ }
230
+ assert_raise(CvBadDepth) {
231
+ IplImage.new(10, 10, :cv32f, 2).pyr_segmentation(4, 255, 50)
232
+ }
233
+ end
234
+ end
235
+
236
+
@@ -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,329 @@
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.6.1', CV_VERSION)
13
+ assert_equal(2, CV_MAJOR_VERSION)
14
+ assert_equal(4, CV_MINOR_VERSION)
15
+ assert_equal(6, CV_SUBMINOR_VERSION)
16
+
17
+ assert_equal(2, CV_VERSION_EPOCH)
18
+ assert_equal(4, CV_VERSION_MAJOR)
19
+ assert_equal(6, CV_VERSION_MINOR)
20
+ assert_equal(1, 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
+ # Load image flags
32
+ assert_equal(-1, CV_LOAD_IMAGE_UNCHANGED)
33
+ assert_equal(0, CV_LOAD_IMAGE_GRAYSCALE)
34
+ assert_equal(1, CV_LOAD_IMAGE_COLOR)
35
+ assert_equal(2, CV_LOAD_IMAGE_ANYDEPTH)
36
+ assert_equal(4, CV_LOAD_IMAGE_ANYCOLOR)
37
+
38
+ # Structuring element shapes
39
+ assert_equal(0, CV_SHAPE_RECT)
40
+ assert_equal(1, CV_SHAPE_CROSS)
41
+ assert_equal(2, CV_SHAPE_ELLIPSE)
42
+ assert_equal(100, CV_SHAPE_CUSTOM)
43
+
44
+ # Types of morphological operations
45
+ assert_equal(2, CV_MOP_OPEN)
46
+ assert_equal(3, CV_MOP_CLOSE)
47
+ assert_equal(4, CV_MOP_GRADIENT)
48
+ assert_equal(5, CV_MOP_TOPHAT)
49
+ assert_equal(6, CV_MOP_BLACKHAT)
50
+
51
+ # Types of the smoothing
52
+ assert_equal(0, CV_BLUR_NO_SCALE)
53
+ assert_equal(1, CV_BLUR)
54
+ assert_equal(2, CV_GAUSSIAN)
55
+ assert_equal(3, CV_MEDIAN)
56
+ assert_equal(4, CV_BILATERAL)
57
+
58
+ # Border types
59
+ assert_equal(0, IPL_BORDER_CONSTANT)
60
+ assert_equal(1, IPL_BORDER_REPLICATE)
61
+
62
+ # Thresholding types
63
+ assert_equal(0, CV_THRESH_BINARY)
64
+ assert_equal(1, CV_THRESH_BINARY_INV)
65
+ assert_equal(2, CV_THRESH_TRUNC)
66
+ assert_equal(3, CV_THRESH_TOZERO)
67
+ assert_equal(4, CV_THRESH_TOZERO_INV)
68
+ assert_equal(8, CV_THRESH_OTSU)
69
+
70
+ # Adaptive methods
71
+ assert_equal(0, CV_ADAPTIVE_THRESH_MEAN_C)
72
+ assert_equal(1, CV_ADAPTIVE_THRESH_GAUSSIAN_C)
73
+
74
+ # Retrieval mode
75
+ assert_equal(0, CV_RETR_EXTERNAL)
76
+ assert_equal(1, CV_RETR_LIST)
77
+ assert_equal(2, CV_RETR_CCOMP)
78
+ assert_equal(3, CV_RETR_TREE)
79
+
80
+ # Approximation method
81
+ assert_equal(0, CV_CHAIN_CODE)
82
+ assert_equal(1, CV_CHAIN_APPROX_NONE)
83
+ assert_equal(2, CV_CHAIN_APPROX_SIMPLE)
84
+ assert_equal(3, CV_CHAIN_APPROX_TC89_L1)
85
+ assert_equal(4, CV_CHAIN_APPROX_TC89_KCOS)
86
+ assert_equal(5, CV_LINK_RUNS)
87
+
88
+ # Termination criteria for iterative algorithms
89
+ assert_equal(1, CV_TERMCRIT_ITER)
90
+ assert_equal(1, CV_TERMCRIT_NUMBER)
91
+ assert_equal(2, CV_TERMCRIT_EPS)
92
+
93
+ # Hough transform methods
94
+ assert_equal(0, CV_HOUGH_STANDARD)
95
+ assert_equal(1, CV_HOUGH_PROBABILISTIC)
96
+ assert_equal(2, CV_HOUGH_MULTI_SCALE)
97
+ assert_equal(3, CV_HOUGH_GRADIENT)
98
+
99
+ # Inpaint method
100
+ assert_equal(0, CV_INPAINT_NS)
101
+ assert_equal(1, CV_INPAINT_TELEA)
102
+
103
+ # Match tempalte method
104
+ assert_equal(0, CV_TM_SQDIFF)
105
+ assert_equal(1, CV_TM_SQDIFF_NORMED)
106
+ assert_equal(2, CV_TM_CCORR)
107
+ assert_equal(3, CV_TM_CCORR_NORMED)
108
+ assert_equal(4, CV_TM_CCOEFF)
109
+ assert_equal(5, CV_TM_CCOEFF_NORMED)
110
+
111
+ # Comparison method
112
+ assert_equal(1, CV_CONTOURS_MATCH_I1)
113
+ assert_equal(2, CV_CONTOURS_MATCH_I2)
114
+ assert_equal(3, CV_CONTOURS_MATCH_I3)
115
+
116
+ # Fundamental matrix computing methods
117
+ assert_equal(1, CV_FM_7POINT)
118
+ assert_equal(2, CV_FM_8POINT)
119
+ assert_equal(8, CV_FM_RANSAC)
120
+ assert_equal(4, CV_FM_LMEDS)
121
+
122
+ # Flags of window
123
+ assert_equal(1, CV_WINDOW_AUTOSIZE)
124
+
125
+ # Object detection mode
126
+ assert_equal(1, CV_HAAR_DO_CANNY_PRUNING)
127
+
128
+ # Interpolation methods
129
+ assert_equal(0, CV_INTER_NN)
130
+ assert_equal(1, CV_INTER_LINEAR)
131
+ assert_equal(2, CV_INTER_CUBIC)
132
+ assert_equal(3, CV_INTER_AREA)
133
+
134
+ # Warp affine optional flags
135
+ assert_equal(8, CV_WARP_FILL_OUTLIERS)
136
+ assert_equal(16, CV_WARP_INVERSE_MAP)
137
+
138
+ # SVD operation flags
139
+ assert_equal(1, CV_SVD_MODIFY_A)
140
+ assert_equal(2, CV_SVD_U_T)
141
+ assert_equal(4, CV_SVD_V_T)
142
+
143
+ # Histogram representation format
144
+ assert_equal(0, CV_HIST_ARRAY)
145
+ assert_equal(1, CV_HIST_SPARSE)
146
+ assert_equal(1, CV_HIST_TREE)
147
+ assert_equal(1, CV_HIST_UNIFORM)
148
+
149
+ # Histogram comparison method
150
+ assert_equal(0, CV_COMP_CORREL)
151
+ assert_equal(1, CV_COMP_CHISQR)
152
+ assert_equal(2, CV_COMP_INTERSECT)
153
+ assert_equal(3, CV_COMP_BHATTACHARYYA)
154
+ end
155
+
156
+ def test_symbols
157
+ # Depths
158
+ assert_equal(0, DEPTH[:cv8u])
159
+ assert_equal(1, DEPTH[:cv8s])
160
+ assert_equal(2, DEPTH[:cv16u])
161
+ assert_equal(3, DEPTH[:cv16s])
162
+ assert_equal(4, DEPTH[:cv32s])
163
+ assert_equal(5, DEPTH[:cv32f])
164
+ assert_equal(6, DEPTH[:cv64f])
165
+
166
+ # Inversion methods
167
+ assert_equal(0, INVERSION_METHOD[:lu])
168
+ assert_equal(1, INVERSION_METHOD[:svd])
169
+ assert_equal(2, INVERSION_METHOD[:svd_sym])
170
+ assert_equal(2, INVERSION_METHOD[:svd_symmetric])
171
+
172
+ # Homography calculation methods
173
+ assert_equal(0, HOMOGRAPHY_CALC_METHOD[:all])
174
+ assert_equal(4, HOMOGRAPHY_CALC_METHOD[:lmeds])
175
+ assert_equal(8, HOMOGRAPHY_CALC_METHOD[:ransac])
176
+
177
+ # Anti aliasing flags
178
+ assert_equal(16, CONNECTIVITY[:aa])
179
+ assert_equal(16, CONNECTIVITY[:anti_alias])
180
+
181
+ # Retrieval modes
182
+ assert_equal(0, RETRIEVAL_MODE[:external])
183
+ assert_equal(1, RETRIEVAL_MODE[:list])
184
+ assert_equal(2, RETRIEVAL_MODE[:ccomp])
185
+ assert_equal(3, RETRIEVAL_MODE[:tree])
186
+
187
+ # Approximation methods
188
+ assert_equal(0, APPROX_CHAIN_METHOD[:code])
189
+ assert_equal(1, APPROX_CHAIN_METHOD[:approx_none])
190
+ assert_equal(2, APPROX_CHAIN_METHOD[:approx_simple])
191
+ assert_equal(3, APPROX_CHAIN_METHOD[:approx_tc89_l1])
192
+ assert_equal(4, APPROX_CHAIN_METHOD[:approx_tc89_kcos])
193
+
194
+ # Approximation methods (polygon)
195
+ assert_equal(0, APPROX_POLY_METHOD[:dp])
196
+
197
+ # Match template methods
198
+ assert_equal(0, MATCH_TEMPLATE_METHOD[:sqdiff])
199
+ assert_equal(1, MATCH_TEMPLATE_METHOD[:sqdiff_normed])
200
+ assert_equal(2, MATCH_TEMPLATE_METHOD[:ccorr])
201
+ assert_equal(3, MATCH_TEMPLATE_METHOD[:ccorr_normed])
202
+ assert_equal(4, MATCH_TEMPLATE_METHOD[:ccoeff])
203
+ assert_equal(5, MATCH_TEMPLATE_METHOD[:ccoeff_normed])
204
+
205
+ # Structuring element shapes
206
+ assert_equal(0, STRUCTURING_ELEMENT_SHAPE[:rect])
207
+ assert_equal(1, STRUCTURING_ELEMENT_SHAPE[:cross])
208
+ assert_equal(2, STRUCTURING_ELEMENT_SHAPE[:ellipse])
209
+ assert_equal(100, STRUCTURING_ELEMENT_SHAPE[:custom])
210
+
211
+ # Types of morphological operations
212
+ assert_equal(2, MORPHOLOGICAL_OPERATION[:open])
213
+ assert_equal(3, MORPHOLOGICAL_OPERATION[:close])
214
+ assert_equal(4, MORPHOLOGICAL_OPERATION[:gradient])
215
+ assert_equal(5, MORPHOLOGICAL_OPERATION[:tophat])
216
+ assert_equal(6, MORPHOLOGICAL_OPERATION[:blackhat])
217
+
218
+ # Types of the smoothing
219
+ assert_equal(0, SMOOTHING_TYPE[:blur_no_scale])
220
+ assert_equal(1, SMOOTHING_TYPE[:blur])
221
+ assert_equal(2, SMOOTHING_TYPE[:gaussian])
222
+ assert_equal(3, SMOOTHING_TYPE[:median])
223
+ assert_equal(4, SMOOTHING_TYPE[:bilateral])
224
+
225
+ # Thresholding types
226
+ assert_equal(0, THRESHOLD_TYPE[:binary])
227
+ assert_equal(1, THRESHOLD_TYPE[:binary_inv])
228
+ assert_equal(2, THRESHOLD_TYPE[:trunc])
229
+ assert_equal(3, THRESHOLD_TYPE[:tozero])
230
+ assert_equal(4, THRESHOLD_TYPE[:tozero_inv])
231
+ assert_equal(8, THRESHOLD_TYPE[:otsu])
232
+
233
+ # Hough transform methods
234
+ assert_equal(0, HOUGH_TRANSFORM_METHOD[:standard])
235
+ assert_equal(1, HOUGH_TRANSFORM_METHOD[:probabilistic])
236
+ assert_equal(2, HOUGH_TRANSFORM_METHOD[:multi_scale])
237
+ assert_equal(3, HOUGH_TRANSFORM_METHOD[:gradient])
238
+
239
+ # Inpaint method
240
+ assert_equal(0, INPAINT_METHOD[:ns])
241
+ assert_equal(1, INPAINT_METHOD[:telea])
242
+
243
+ # Comparison method
244
+ assert_equal(1, COMPARISON_METHOD[:i1])
245
+ assert_equal(2, COMPARISON_METHOD[:i2])
246
+ assert_equal(3, COMPARISON_METHOD[:i3])
247
+ end
248
+
249
+ def test_cvt_color_funcs
250
+ mat_1ch = CvMat.new(1, 1, :cv8u, 1)
251
+ mat_1ch[0] = CvScalar.new(10)
252
+
253
+ mat_3ch = CvMat.new(1, 1, :cv8u, 3)
254
+ mat_3ch[0] = CvScalar.new(10, 20, 30)
255
+
256
+ mat_4ch = CvMat.new(1, 1, :cv8u, 4)
257
+ mat_4ch[0] = CvScalar.new(10, 20, 30, 40)
258
+
259
+ gray_rgb = (0.299 * mat_3ch[0][0] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][2]).round
260
+ gray_bgr = (0.299 * mat_3ch[0][2] + 0.587 * mat_3ch[0][1] + 0.114 * mat_3ch[0][0]).round
261
+
262
+ # RGB(A) <=> RGB(A)
263
+ [mat_3ch.BGR2BGRA, mat_3ch.RGB2RGBA].each { |m|
264
+ assert_equal(CvMat, m.class)
265
+ assert_equal(4, m.channel)
266
+ assert_cvscalar_equal(CvScalar.new(10, 20, 30, 255), m[0])
267
+ }
268
+ [mat_3ch.BGR2RGBA, mat_3ch.RGB2BGRA].each { |m|
269
+ assert_equal(CvMat, m.class)
270
+ assert_equal(4, m.channel)
271
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 255), m[0])
272
+ }
273
+ [mat_4ch.BGRA2BGR, mat_4ch.RGBA2RGB].each { |m|
274
+ assert_equal(CvMat, m.class)
275
+ assert_equal(3, m.channel)
276
+ assert_cvscalar_equal(CvScalar.new(10, 20, 30, 0), m[0])
277
+ }
278
+ [mat_4ch.RGBA2BGR, mat_4ch.BGRA2RGB].each { |m|
279
+ assert_equal(CvMat, m.class)
280
+ assert_equal(3, m.channel)
281
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
282
+ }
283
+ [mat_3ch.BGR2RGB, mat_3ch.RGB2BGR].each { |m|
284
+ assert_equal(CvMat, m.class)
285
+ assert_equal(3, m.channel)
286
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 0), m[0])
287
+ }
288
+ [mat_4ch.BGRA2RGBA, mat_4ch.RGBA2BGRA].each { |m|
289
+ assert_equal(CvMat, m.class)
290
+ assert_equal(4, m.channel)
291
+ assert_cvscalar_equal(CvScalar.new(30, 20, 10, 40), m[0])
292
+ }
293
+
294
+ # RGB <=> GRAY
295
+ [mat_3ch.BGR2GRAY, mat_4ch.BGRA2GRAY].each { |m|
296
+ assert_equal(CvMat, m.class)
297
+ assert_equal(1, m.channel)
298
+ assert_cvscalar_equal(CvScalar.new(gray_bgr, 0, 0, 0), m[0])
299
+ }
300
+ [mat_3ch.RGB2GRAY, mat_4ch.RGBA2GRAY].each { |m|
301
+ assert_equal(CvMat, m.class)
302
+ assert_equal(1, m.channel)
303
+ assert_cvscalar_equal(CvScalar.new(gray_rgb, 0, 0, 0), m[0])
304
+ }
305
+ [mat_1ch.GRAY2BGR, mat_1ch.GRAY2RGB].each { |m|
306
+ assert_equal(CvMat, m.class)
307
+ assert_equal(3, m.channel)
308
+ assert_cvscalar_equal(CvScalar.new(10, 10, 10, 0), m[0])
309
+ }
310
+ [mat_1ch.GRAY2BGRA, mat_1ch.GRAY2RGBA].each { |m|
311
+ assert_equal(CvMat, m.class)
312
+ assert_equal(4, m.channel)
313
+ assert_cvscalar_equal(CvScalar.new(10, 10, 10, 255), m[0])
314
+ }
315
+
316
+ img_3ch = IplImage.new(1, 1, :cv8u, 3)
317
+ assert_equal(IplImage, img_3ch.BGR2GRAY.class)
318
+
319
+ flunk('FIXME: Most cvtColor functions are not tested yet.')
320
+ end
321
+
322
+ def test_build_information
323
+ s = build_information
324
+ assert_equal(String, s.class)
325
+ assert(s =~ /^\s+General configuration for OpenCV #{CV_VERSION}/)
326
+ end
327
+ end
328
+
329
+