ruby-opencv 0.0.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/Gemfile +8 -0
  2. data/History.txt +5 -0
  3. data/License.txt +30 -0
  4. data/Manifest.txt +229 -0
  5. data/README.rdoc +149 -0
  6. data/Rakefile +32 -0
  7. data/examples/alpha_blend.rb +21 -0
  8. data/examples/box.png +0 -0
  9. data/examples/box_in_scene.png +0 -0
  10. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  11. data/examples/contours/bitmap-contours.png +0 -0
  12. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  13. data/examples/contours/contour_retrieval_modes.rb +139 -0
  14. data/examples/contours/rotated-boxes-with-detected-bounding-rectangles.jpg +0 -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/matching_to_many_images.rb +16 -0
  26. data/examples/matching_to_many_images/query.png +0 -0
  27. data/examples/matching_to_many_images/train/1.png +0 -0
  28. data/examples/matching_to_many_images/train/2.png +0 -0
  29. data/examples/matching_to_many_images/train/3.png +0 -0
  30. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  31. data/examples/paint.rb +70 -0
  32. data/examples/snake.rb +43 -0
  33. data/examples/stuff.jpg +0 -0
  34. data/examples/tiffany.jpg +0 -0
  35. data/ext/opencv/GPATH +0 -0
  36. data/ext/opencv/GSYMS +0 -0
  37. data/ext/opencv/curve.cpp +112 -0
  38. data/ext/opencv/curve.h +34 -0
  39. data/ext/opencv/cvavgcomp.cpp +67 -0
  40. data/ext/opencv/cvavgcomp.h +39 -0
  41. data/ext/opencv/cvbox2d.cpp +197 -0
  42. data/ext/opencv/cvbox2d.h +61 -0
  43. data/ext/opencv/cvcapture.cpp +499 -0
  44. data/ext/opencv/cvcapture.h +72 -0
  45. data/ext/opencv/cvchain.cpp +233 -0
  46. data/ext/opencv/cvchain.h +46 -0
  47. data/ext/opencv/cvcircle32f.cpp +116 -0
  48. data/ext/opencv/cvcircle32f.h +52 -0
  49. data/ext/opencv/cvcondensation.cpp +282 -0
  50. data/ext/opencv/cvcondensation.h +49 -0
  51. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  52. data/ext/opencv/cvconnectedcomp.h +49 -0
  53. data/ext/opencv/cvcontour.cpp +296 -0
  54. data/ext/opencv/cvcontour.h +48 -0
  55. data/ext/opencv/cvcontourtree.cpp +91 -0
  56. data/ext/opencv/cvcontourtree.h +41 -0
  57. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  58. data/ext/opencv/cvconvexitydefect.h +42 -0
  59. data/ext/opencv/cverror.cpp +159 -0
  60. data/ext/opencv/cverror.h +28 -0
  61. data/ext/opencv/cvfeaturetree.cpp +125 -0
  62. data/ext/opencv/cvfeaturetree.h +55 -0
  63. data/ext/opencv/cvfont.cpp +208 -0
  64. data/ext/opencv/cvfont.h +64 -0
  65. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  66. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  67. data/ext/opencv/cvhistogram.cpp +546 -0
  68. data/ext/opencv/cvhistogram.h +73 -0
  69. data/ext/opencv/cvhumoments.cpp +139 -0
  70. data/ext/opencv/cvhumoments.h +51 -0
  71. data/ext/opencv/cvline.cpp +154 -0
  72. data/ext/opencv/cvline.h +54 -0
  73. data/ext/opencv/cvmat.cpp +5848 -0
  74. data/ext/opencv/cvmat.h +284 -0
  75. data/ext/opencv/cvmatnd.cpp +44 -0
  76. data/ext/opencv/cvmatnd.h +28 -0
  77. data/ext/opencv/cvmemstorage.cpp +68 -0
  78. data/ext/opencv/cvmemstorage.h +53 -0
  79. data/ext/opencv/cvmoments.cpp +287 -0
  80. data/ext/opencv/cvmoments.h +75 -0
  81. data/ext/opencv/cvpoint.cpp +228 -0
  82. data/ext/opencv/cvpoint.h +64 -0
  83. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  84. data/ext/opencv/cvpoint2d32f.h +63 -0
  85. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  86. data/ext/opencv/cvpoint3d32f.h +66 -0
  87. data/ext/opencv/cvrect.cpp +333 -0
  88. data/ext/opencv/cvrect.h +79 -0
  89. data/ext/opencv/cvscalar.cpp +236 -0
  90. data/ext/opencv/cvscalar.h +71 -0
  91. data/ext/opencv/cvseq.cpp +599 -0
  92. data/ext/opencv/cvseq.h +74 -0
  93. data/ext/opencv/cvsize.cpp +221 -0
  94. data/ext/opencv/cvsize.h +65 -0
  95. data/ext/opencv/cvsize2d32f.cpp +209 -0
  96. data/ext/opencv/cvsize2d32f.h +64 -0
  97. data/ext/opencv/cvslice.cpp +120 -0
  98. data/ext/opencv/cvslice.h +61 -0
  99. data/ext/opencv/cvsparsemat.cpp +44 -0
  100. data/ext/opencv/cvsparsemat.h +28 -0
  101. data/ext/opencv/cvsurfparams.cpp +199 -0
  102. data/ext/opencv/cvsurfparams.h +58 -0
  103. data/ext/opencv/cvsurfpoint.cpp +223 -0
  104. data/ext/opencv/cvsurfpoint.h +52 -0
  105. data/ext/opencv/cvtermcriteria.cpp +192 -0
  106. data/ext/opencv/cvtermcriteria.h +71 -0
  107. data/ext/opencv/cvtwopoints.cpp +116 -0
  108. data/ext/opencv/cvtwopoints.h +51 -0
  109. data/ext/opencv/cvutils.cpp +194 -0
  110. data/ext/opencv/cvutils.h +29 -0
  111. data/ext/opencv/cvvideowriter.cpp +137 -0
  112. data/ext/opencv/cvvideowriter.h +43 -0
  113. data/ext/opencv/gui.cpp +68 -0
  114. data/ext/opencv/gui.h +30 -0
  115. data/ext/opencv/iplconvkernel.cpp +192 -0
  116. data/ext/opencv/iplconvkernel.h +71 -0
  117. data/ext/opencv/iplimage.cpp +644 -0
  118. data/ext/opencv/iplimage.h +73 -0
  119. data/ext/opencv/lib/opencv.rb +3 -0
  120. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  121. data/ext/opencv/lib/opencv/version.rb +3 -0
  122. data/ext/opencv/mouseevent.cpp +181 -0
  123. data/ext/opencv/mouseevent.h +56 -0
  124. data/ext/opencv/opencv.cpp +722 -0
  125. data/ext/opencv/opencv.h +400 -0
  126. data/ext/opencv/pointset.cpp +274 -0
  127. data/ext/opencv/pointset.h +68 -0
  128. data/ext/opencv/trackbar.cpp +121 -0
  129. data/ext/opencv/trackbar.h +69 -0
  130. data/ext/opencv/window.cpp +357 -0
  131. data/ext/opencv/window.h +66 -0
  132. data/extconf.rb +75 -0
  133. data/images/CvMat_sobel.png +0 -0
  134. data/images/CvMat_sub_rect.png +0 -0
  135. data/images/CvSeq_relationmap.png +0 -0
  136. data/images/face_detect_from_lena.jpg +0 -0
  137. data/ruby-opencv.gemspec +43 -0
  138. data/test/helper.rb +166 -0
  139. data/test/log.txt +55 -0
  140. data/test/runner.rb +30 -0
  141. data/test/samples/airplane.jpg +0 -0
  142. data/test/samples/baboon.jpg +0 -0
  143. data/test/samples/baboon200.jpg +0 -0
  144. data/test/samples/baboon200_rotated.jpg +0 -0
  145. data/test/samples/blank0.jpg +0 -0
  146. data/test/samples/blank1.jpg +0 -0
  147. data/test/samples/blank2.jpg +0 -0
  148. data/test/samples/blank3.jpg +0 -0
  149. data/test/samples/blank4.jpg +0 -0
  150. data/test/samples/blank5.jpg +0 -0
  151. data/test/samples/blank6.jpg +0 -0
  152. data/test/samples/blank7.jpg +0 -0
  153. data/test/samples/blank8.jpg +0 -0
  154. data/test/samples/blank9.jpg +0 -0
  155. data/test/samples/cat.jpg +0 -0
  156. data/test/samples/chessboard.jpg +0 -0
  157. data/test/samples/contours.jpg +0 -0
  158. data/test/samples/fruits.jpg +0 -0
  159. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  160. data/test/samples/inpaint-mask.bmp +0 -0
  161. data/test/samples/lena-256x256.jpg +0 -0
  162. data/test/samples/lena-32x32.jpg +0 -0
  163. data/test/samples/lena-eyes.jpg +0 -0
  164. data/test/samples/lena-inpaint.jpg +0 -0
  165. data/test/samples/lena.jpg +0 -0
  166. data/test/samples/lines.jpg +0 -0
  167. data/test/samples/messy0.jpg +0 -0
  168. data/test/samples/messy1.jpg +0 -0
  169. data/test/samples/movie_sample.avi +0 -0
  170. data/test/samples/one_way_train_0000.jpg +0 -0
  171. data/test/samples/one_way_train_0001.jpg +0 -0
  172. data/test/samples/partially_blank0.jpg +0 -0
  173. data/test/samples/partially_blank1.jpg +0 -0
  174. data/test/samples/smooth0.jpg +0 -0
  175. data/test/samples/smooth1.jpg +0 -0
  176. data/test/samples/smooth2.jpg +0 -0
  177. data/test/samples/smooth3.jpg +0 -0
  178. data/test/samples/smooth4.jpg +0 -0
  179. data/test/samples/smooth5.jpg +0 -0
  180. data/test/samples/smooth6.jpg +0 -0
  181. data/test/samples/str-cv-rotated.jpg +0 -0
  182. data/test/samples/str-cv.jpg +0 -0
  183. data/test/samples/str-ov.jpg +0 -0
  184. data/test/samples/stuff.jpg +0 -0
  185. data/test/test_curve.rb +43 -0
  186. data/test/test_cvavgcomp.rb +24 -0
  187. data/test/test_cvbox2d.rb +76 -0
  188. data/test/test_cvcapture.rb +183 -0
  189. data/test/test_cvchain.rb +108 -0
  190. data/test/test_cvcircle32f.rb +41 -0
  191. data/test/test_cvconnectedcomp.rb +61 -0
  192. data/test/test_cvcontour.rb +150 -0
  193. data/test/test_cvcontourtree.rb +43 -0
  194. data/test/test_cverror.rb +50 -0
  195. data/test/test_cvfeaturetree.rb +65 -0
  196. data/test/test_cvfont.rb +58 -0
  197. data/test/test_cvhaarclassifiercascade.rb +63 -0
  198. data/test/test_cvhistogram.rb +271 -0
  199. data/test/test_cvhumoments.rb +83 -0
  200. data/test/test_cvline.rb +50 -0
  201. data/test/test_cvmat.rb +2947 -0
  202. data/test/test_cvmat_drawing.rb +349 -0
  203. data/test/test_cvmat_dxt.rb +150 -0
  204. data/test/test_cvmat_imageprocessing.rb +2025 -0
  205. data/test/test_cvmat_matching.rb +57 -0
  206. data/test/test_cvmoments.rb +180 -0
  207. data/test/test_cvpoint.rb +75 -0
  208. data/test/test_cvpoint2d32f.rb +75 -0
  209. data/test/test_cvpoint3d32f.rb +93 -0
  210. data/test/test_cvrect.rb +144 -0
  211. data/test/test_cvscalar.rb +113 -0
  212. data/test/test_cvseq.rb +295 -0
  213. data/test/test_cvsize.rb +75 -0
  214. data/test/test_cvsize2d32f.rb +75 -0
  215. data/test/test_cvslice.rb +31 -0
  216. data/test/test_cvsurfparams.rb +57 -0
  217. data/test/test_cvsurfpoint.rb +66 -0
  218. data/test/test_cvtermcriteria.rb +56 -0
  219. data/test/test_cvtwopoints.rb +40 -0
  220. data/test/test_cvvideowriter.rb +58 -0
  221. data/test/test_iplconvkernel.rb +54 -0
  222. data/test/test_iplimage.rb +236 -0
  223. data/test/test_mouseevent.rb +17 -0
  224. data/test/test_opencv.rb +324 -0
  225. data/test/test_pointset.rb +126 -0
  226. data/test/test_preliminary.rb +130 -0
  227. data/test/test_trackbar.rb +47 -0
  228. data/test/test_window.rb +115 -0
  229. data/test/videowriter_result.avi +0 -0
  230. metadata +394 -0
@@ -0,0 +1,144 @@
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::CvRect
10
+ class TestCvRect < OpenCVTestCase
11
+ class MyRect; end
12
+
13
+ def test_x
14
+ rect = CvRect.new
15
+ rect.x = 100
16
+ assert_equal(100, rect.x)
17
+ rect.x = 200
18
+ assert_equal(200, rect.x)
19
+ end
20
+
21
+ def test_y
22
+ rect = CvRect.new
23
+ rect.y = 100
24
+ assert_equal(100, rect.y)
25
+ rect.y = 200
26
+ assert_equal(200, rect.y)
27
+ end
28
+
29
+ def test_width
30
+ rect = CvRect.new
31
+ rect.width = 100
32
+ assert_equal(100, rect.width)
33
+ rect.width = 200
34
+ assert_equal(200, rect.width)
35
+ end
36
+
37
+ def test_height
38
+ rect = CvRect.new
39
+ rect.height = 100
40
+ assert_equal(100, rect.height)
41
+ rect.height = 200
42
+ assert_equal(200, rect.height)
43
+ end
44
+
45
+ def test_compatible
46
+ assert(!(CvRect.compatible? MyRect.new))
47
+ MyRect.class_eval { def x; end }
48
+ assert(!(CvRect.compatible? MyRect.new))
49
+ MyRect.class_eval { def y; end }
50
+ assert(!(CvRect.compatible? MyRect.new))
51
+ MyRect.class_eval { def width; end }
52
+ assert(!(CvRect.compatible? MyRect.new))
53
+ MyRect.class_eval { def height; end }
54
+ assert(CvRect.compatible? MyRect.new)
55
+ assert(CvRect.compatible? CvRect.new)
56
+ end
57
+
58
+ def test_initialize
59
+ rect = CvRect.new
60
+ assert_equal(0, rect.x)
61
+ assert_equal(0, rect.y)
62
+ assert_equal(0, rect.width)
63
+ assert_equal(0, rect.height)
64
+
65
+ rect = CvRect.new(10, 20, 30, 40)
66
+ assert_equal(10, rect.x)
67
+ assert_equal(20, rect.y)
68
+ assert_equal(30, rect.width)
69
+ assert_equal(40, rect.height)
70
+
71
+ rect = CvRect.new(CvRect.new(10, 20, 30, 40))
72
+ assert_equal(10, rect.x)
73
+ assert_equal(20, rect.y)
74
+ assert_equal(30, rect.width)
75
+ assert_equal(40, rect.height)
76
+
77
+ assert_raise(TypeError) {
78
+ CvRect.new(DUMMY_OBJ)
79
+ }
80
+ assert_raise(ArgumentError) {
81
+ CvRect.new(1, 2)
82
+ }
83
+ assert_raise(ArgumentError) {
84
+ CvRect.new(1, 2, 3)
85
+ }
86
+ assert_raise(ArgumentError) {
87
+ CvRect.new(1, 2, 3, 4, 5)
88
+ }
89
+ end
90
+
91
+ def test_center
92
+ center = CvRect.new(10, 20, 35, 45).center
93
+ assert_in_delta(27.5, center.x, 0.01)
94
+ assert_in_delta(42.5, center.y, 0.01)
95
+ end
96
+
97
+ def test_points
98
+ points = CvRect.new(10, 20, 35, 45).points
99
+ assert_equal(4, points.size)
100
+ assert_in_delta(10, points[0].x, 0.01)
101
+ assert_in_delta(20, points[0].y, 0.01)
102
+ assert_in_delta(10, points[1].x, 0.01)
103
+ assert_in_delta(65, points[1].y, 0.01)
104
+ assert_in_delta(45, points[2].x, 0.01)
105
+ assert_in_delta(65, points[2].y, 0.01)
106
+ assert_in_delta(45, points[3].x, 0.01)
107
+ assert_in_delta(20, points[3].y, 0.01)
108
+ end
109
+
110
+ def test_top_left
111
+ tl = CvRect.new(10, 20, 35, 45).top_left
112
+ assert_equal(10, tl.x)
113
+ assert_equal(20, tl.y)
114
+ end
115
+
116
+ def test_top_right
117
+ tr = CvRect.new(10, 20, 35, 45).top_right
118
+ assert_equal(45, tr.x)
119
+ assert_equal(20, tr.y)
120
+ end
121
+
122
+ def test_bottom_left
123
+ bl = CvRect.new(10, 20, 35, 45).bottom_left
124
+ assert_equal(10, bl.x)
125
+ assert_equal(65, bl.y)
126
+ end
127
+
128
+ def test_bottom_right
129
+ br = CvRect.new(10, 20, 35, 45).bottom_right
130
+ assert_equal(45, br.x)
131
+ assert_equal(65, br.y)
132
+ end
133
+
134
+ def test_max_rect
135
+ rect1 = CvRect.new(10, 20, 30, 40)
136
+ rect2 = CvRect.new(30, 40, 70, 80)
137
+ rect3 = CvRect.max_rect(rect1, rect2)
138
+ assert_equal(10, rect3.x)
139
+ assert_equal(20, rect3.y)
140
+ assert_equal(90, rect3.width)
141
+ assert_equal(100, rect3.height)
142
+ end
143
+ end
144
+
@@ -0,0 +1,113 @@
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::CvScalar
10
+ class TestCvScalar < OpenCVTestCase
11
+ def test_initialize
12
+ s = CvScalar.new
13
+ assert_in_delta([0, 0, 0, 0], s, 0.01)
14
+
15
+ s = CvScalar.new(1.1)
16
+ assert_in_delta([1.1, 0, 0, 0], s, 0.01)
17
+
18
+ s = CvScalar.new(1.1, 2.2)
19
+ assert_in_delta([1.1, 2.2, 0, 0], s, 0.01)
20
+
21
+ s = CvScalar.new(1.1, 2.2, 3.3)
22
+ assert_in_delta([1.1, 2.2, 3.3, 0], s, 0.01)
23
+
24
+ s = CvScalar.new(1.1, 2.2, 3.3, 4.4)
25
+ assert_in_delta([1.1, 2.2, 3.3, 4.4], s, 0.01)
26
+ end
27
+
28
+ def test_aref
29
+ assert_in_delta([0, 0, 0, 0], CvScalar.new, 0.01)
30
+ assert_in_delta([10, 20, 30, 40], CvScalar.new(10, 20, 30, 40), 0.01)
31
+ assert_in_delta([0.1, 0.2, 0.3, 0.4], CvScalar.new(0.1, 0.2, 0.3, 0.4), 0.01)
32
+ end
33
+
34
+ def test_aset
35
+ s = CvScalar.new
36
+ [10, 20, 30, 40].each_with_index { |x, i|
37
+ s[i] = x
38
+ }
39
+ assert_in_delta([10, 20, 30, 40], s, 0.01)
40
+
41
+ s = CvScalar.new
42
+ [0.1, 0.2, 0.3, 0.4].each_with_index { |x, i|
43
+ s[i] = x
44
+ }
45
+ assert_in_delta([0.1, 0.2, 0.3, 0.4], s, 0.01)
46
+ end
47
+
48
+ def test_sub
49
+ s1 = CvScalar.new(10, 20, 30, 40)
50
+ s2 = CvScalar.new(2, 4, 6, 8)
51
+ [s1.sub(s2), s1 - s2].each { |s|
52
+ assert_in_delta([8, 16, 24, 32], s, 0.01)
53
+ }
54
+
55
+ s3 = CvScalar.new(0.2, 0.4, 0.6, 0.8)
56
+ [s2.sub(s3), s2 - s3].each { |s|
57
+ assert_in_delta([1.8, 3.6, 5.4, 7.2], s, 0.01)
58
+ }
59
+
60
+ mat = CvMat.new(5, 5)
61
+ mask = CvMat.new(5, 5, :cv8u, 1)
62
+ mat.height.times { |j|
63
+ mat.width.times { |i|
64
+ mat[i, j] = CvScalar.new(1.5)
65
+ mask[i, j] = (i < 2 and j < 3) ? 1 : 0
66
+ }
67
+ }
68
+ mat = CvScalar.new(0.1).sub(mat, mask)
69
+
70
+ [CvMat.new(5, 5, :cv16u, 1), CvMat.new(5, 5, :cv8u, 3)].each { |msk|
71
+ assert_raise(TypeError) {
72
+ CvScalar.new.sub(mat, msk)
73
+ }
74
+ }
75
+ end
76
+
77
+ def test_to_s
78
+ assert_equal("<OpenCV::CvScalar:10,20,30,40>", CvScalar.new(10, 20, 30, 40).to_s)
79
+ assert_equal("<OpenCV::CvScalar:0.1,0.2,0.3,0.4>", CvScalar.new(0.1, 0.2, 0.3, 0.4).to_s)
80
+ end
81
+
82
+ def test_to_ary
83
+ [[10, 20, 30, 40], [0.1, 0.2, 0.3, 0.4]].each { |a|
84
+ s = CvScalar.new(*a)
85
+ b = s.to_ary
86
+ c = s.to_a # Alias
87
+ [b, c].each { |x|
88
+ assert_equal(Array, x.class)
89
+ assert_in_delta(a, x, 0.01)
90
+ }
91
+ }
92
+ end
93
+
94
+ def test_cvcolor
95
+ assert_cvscalar_equal(CvColor::Black, CvScalar.new(0x0, 0x0, 0x0, 0))
96
+ assert_cvscalar_equal(CvColor::Silver, CvScalar.new(0x0c, 0x0c, 0x0c, 0))
97
+ assert_cvscalar_equal(CvColor::Gray, CvScalar.new(0x80, 0x80, 0x80, 0))
98
+ assert_cvscalar_equal(CvColor::White, CvScalar.new(0xff, 0xff, 0xff, 0))
99
+ assert_cvscalar_equal(CvColor::Maroon, CvScalar.new(0x0, 0x0, 0x80, 0))
100
+ assert_cvscalar_equal(CvColor::Red, CvScalar.new(0x0, 0x0, 0xff, 0))
101
+ assert_cvscalar_equal(CvColor::Purple, CvScalar.new(0x80, 0x0, 0x80, 0))
102
+ assert_cvscalar_equal(CvColor::Fuchsia, CvScalar.new(0xff, 0x0, 0xff, 0))
103
+ assert_cvscalar_equal(CvColor::Green, CvScalar.new(0x0, 0x80, 0x0, 0))
104
+ assert_cvscalar_equal(CvColor::Lime, CvScalar.new(0x0, 0xff, 0x0, 0))
105
+ assert_cvscalar_equal(CvColor::Olive, CvScalar.new(0x0, 0x80, 0x80, 0))
106
+ assert_cvscalar_equal(CvColor::Yellow, CvScalar.new(0x0, 0xff, 0xff, 0))
107
+ assert_cvscalar_equal(CvColor::Navy, CvScalar.new(0x80, 0x0, 0x0, 0))
108
+ assert_cvscalar_equal(CvColor::Blue, CvScalar.new(0xff, 0x0, 0x0, 0))
109
+ assert_cvscalar_equal(CvColor::Teal, CvScalar.new(0x80, 0x80, 0x0, 0))
110
+ assert_cvscalar_equal(CvColor::Aqua, CvScalar.new(0xff, 0xff, 0x0, 0))
111
+ end
112
+ end
113
+
@@ -0,0 +1,295 @@
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::CvSeq
10
+ class TestCvSeq < OpenCVTestCase
11
+ def test_initialize
12
+ # assert_not_nil(CvSeq.new(CvIndex))
13
+ assert_not_nil(CvSeq.new(Fixnum))
14
+ assert_not_nil(CvSeq.new(CvPoint))
15
+ assert_not_nil(CvSeq.new(CvPoint2D32f))
16
+ assert_not_nil(CvSeq.new(CvPoint3D32f))
17
+
18
+ assert(CvSeq.new(CvPoint).is_a? Enumerable)
19
+ end
20
+
21
+ def test_total
22
+ seq1 = CvSeq.new(CvPoint)
23
+ assert_equal(0, seq1.total)
24
+
25
+ seq1.push(CvPoint.new(1, 2))
26
+ assert_equal(1, seq1.total)
27
+
28
+ seq1.push(CvPoint.new(3, 4))
29
+ assert_equal(2, seq1.total)
30
+ # Alias
31
+ assert_equal(2, seq1.length)
32
+ assert_equal(2, seq1.size)
33
+ end
34
+
35
+ def test_empty
36
+ assert(CvSeq.new(CvPoint).empty?)
37
+ assert(CvSeq.new(CvPoint2D32f).empty?)
38
+ assert(CvSeq.new(CvPoint3D32f).empty?)
39
+ end
40
+
41
+ def test_aref
42
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
43
+
44
+ assert_equal(CvPoint, seq1[0].class)
45
+ assert_equal(10, seq1[0].x)
46
+ assert_equal(20, seq1[0].y)
47
+ assert_equal(30, seq1[1].x)
48
+ assert_equal(40, seq1[1].y)
49
+ assert_equal(50, seq1[2].x)
50
+ assert_equal(60, seq1[2].y)
51
+
52
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
53
+
54
+ assert_equal(Fixnum, seq2[0].class)
55
+ assert_equal(10, seq2[0])
56
+ assert_equal(20, seq2[1])
57
+ assert_equal(30, seq2[2])
58
+ end
59
+
60
+ def test_push
61
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
62
+
63
+ assert_equal(2, seq1.total)
64
+ assert_equal(CvPoint, seq1[0].class)
65
+ assert_equal(10, seq1[0].x)
66
+ assert_equal(20, seq1[0].y)
67
+ assert_equal(CvPoint, seq1[1].class)
68
+ assert_equal(30, seq1[1].x)
69
+ assert_equal(40, seq1[1].y)
70
+
71
+ seq2 = CvSeq.new(CvPoint).push(CvPoint.new(50, 60))
72
+ seq2.push(seq1)
73
+ assert_equal(3, seq2.total)
74
+ assert_equal(CvPoint, seq2[0].class)
75
+ assert_equal(50, seq2[0].x)
76
+ assert_equal(60, seq2[0].y)
77
+ assert_equal(CvPoint, seq2[1].class)
78
+ assert_equal(10, seq2[1].x)
79
+ assert_equal(20, seq2[1].y)
80
+ assert_equal(CvPoint, seq2[2].class)
81
+ assert_equal(30, seq2[2].x)
82
+ assert_equal(40, seq2[2].y)
83
+
84
+ seq3 = CvSeq.new(Fixnum).push(10)
85
+ seq4 = CvSeq.new(Fixnum).push(20, 30)
86
+ seq3.push(seq4)
87
+ assert_equal(3, seq3.total)
88
+ assert_equal(Fixnum, seq3[0].class)
89
+ assert_equal(10, seq3[0])
90
+ assert_equal(20, seq3[1])
91
+ assert_equal(30, seq3[2])
92
+
93
+ assert_raise(TypeError) {
94
+ seq1.push(CvPoint2D32f.new(55.5, 66.6))
95
+ }
96
+
97
+ assert_raise(TypeError) {
98
+ seq3 = CvSeq.new(CvPoint2D32f).push(CvPoint2D32f.new(55.5, 66.6))
99
+ seq1.push(seq3)
100
+ }
101
+ end
102
+
103
+ def test_pop
104
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
105
+ point1 = seq1.pop
106
+ assert_equal(CvPoint, point1.class)
107
+ assert_equal(30, point1.x)
108
+ assert_equal(40, point1.y)
109
+
110
+ assert_equal(1, seq1.total)
111
+ assert_equal(CvPoint, seq1[0].class)
112
+ assert_equal(10, seq1[0].x)
113
+ assert_equal(20, seq1[0].y)
114
+
115
+ assert_nil(CvSeq.new(CvPoint).pop)
116
+
117
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
118
+ assert_equal(30, seq2.pop)
119
+ assert_equal(20, seq2.pop)
120
+ assert_equal(10, seq2.pop)
121
+ end
122
+
123
+ def test_clear
124
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
125
+ seq1.clear
126
+ assert_not_nil(seq1)
127
+ assert_equal(0, seq1.total)
128
+ end
129
+
130
+ def test_unshift
131
+ seq1 = CvSeq.new(CvPoint).unshift(CvPoint.new(10, 20), CvPoint.new(30, 40))
132
+
133
+ assert_equal(2, seq1.total)
134
+ assert_equal(CvPoint, seq1[0].class)
135
+ assert_equal(30, seq1[0].x)
136
+ assert_equal(40, seq1[0].y)
137
+ assert_equal(CvPoint, seq1[1].class)
138
+ assert_equal(10, seq1[1].x)
139
+ assert_equal(20, seq1[1].y)
140
+
141
+ seq2 = CvSeq.new(CvPoint).unshift(CvPoint.new(50, 60))
142
+ seq2.unshift(seq1)
143
+ assert_equal(3, seq2.total)
144
+ assert_equal(CvPoint, seq1[0].class)
145
+ assert_equal(30, seq1[0].x)
146
+ assert_equal(40, seq1[0].y)
147
+ assert_equal(CvPoint, seq1[1].class)
148
+ assert_equal(10, seq1[1].x)
149
+ assert_equal(20, seq1[1].y)
150
+ assert_equal(CvPoint, seq2[2].class)
151
+ assert_equal(50, seq2[2].x)
152
+ assert_equal(60, seq2[2].y)
153
+
154
+ seq3 = CvSeq.new(Fixnum).unshift(10, 20, 30)
155
+ assert_equal(3, seq3.total)
156
+ assert_equal(30, seq3[0])
157
+ assert_equal(20, seq3[1])
158
+ assert_equal(10, seq3[2])
159
+
160
+ assert_raise(TypeError) {
161
+ seq1.unshift(CvPoint2D32f.new(55.5, 66.6))
162
+ }
163
+
164
+ assert_raise(TypeError) {
165
+ seq3 = CvSeq.new(CvPoint2D32f).push(CvPoint2D32f.new(55.5, 66.6))
166
+ seq1.unshift(seq3)
167
+ }
168
+ end
169
+
170
+ def test_shift
171
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
172
+ point1 = seq1.shift
173
+ assert_equal(CvPoint, point1.class)
174
+ assert_equal(10, point1.x)
175
+ assert_equal(20, point1.y)
176
+
177
+ assert_equal(1, seq1.total)
178
+ assert_equal(CvPoint, seq1[0].class)
179
+ assert_equal(30, seq1[0].x)
180
+ assert_equal(40, seq1[0].y)
181
+
182
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
183
+ assert_equal(10, seq2.shift)
184
+ assert_equal(20, seq2.shift)
185
+ assert_equal(30, seq2.shift)
186
+
187
+ assert_nil(CvSeq.new(CvPoint).shift)
188
+ end
189
+
190
+ def test_first
191
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
192
+ point1 = seq1.first
193
+ assert_equal(CvPoint, point1.class)
194
+ assert_equal(10, point1.x)
195
+ assert_equal(20, point1.y)
196
+
197
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
198
+ assert_equal(10, seq2.first)
199
+ end
200
+
201
+ def test_last
202
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
203
+ point1 = seq1.last
204
+ assert_equal(CvPoint, point1.class)
205
+ assert_equal(50, point1.x)
206
+ assert_equal(60, point1.y)
207
+
208
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
209
+ assert_equal(30, seq2.last)
210
+ end
211
+
212
+ def test_each
213
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
214
+ i = 0
215
+ seq1.each { |s|
216
+ assert_equal(CvPoint, s.class)
217
+ assert_equal(seq1[i].x, s.x)
218
+ assert_equal(seq1[i].y, s.y)
219
+ i += 1
220
+ }
221
+ assert_equal(3, i)
222
+
223
+ seq2 = CvSeq.new(Fixnum).push(10, 20, 30)
224
+ i = 0
225
+ seq2.each { |s|
226
+ assert_equal(seq2[i], s)
227
+ i += 1
228
+ }
229
+ assert_equal(3, i)
230
+ end
231
+
232
+ def test_each_index
233
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
234
+ n = 0
235
+ seq1.each_index { |i|
236
+ assert_equal(n, i)
237
+ n += 1
238
+ }
239
+ assert_equal(3, n)
240
+ end
241
+
242
+ def test_insert
243
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
244
+ seq1.insert(1, CvPoint.new(50, 60))
245
+ assert_equal(3, seq1.total)
246
+ assert_equal(CvPoint, seq1[0].class)
247
+ assert_equal(10, seq1[0].x)
248
+ assert_equal(20, seq1[0].y)
249
+ assert_equal(CvPoint, seq1[1].class)
250
+ assert_equal(50, seq1[1].x)
251
+ assert_equal(60, seq1[1].y)
252
+ assert_equal(CvPoint, seq1[2].class)
253
+ assert_equal(30, seq1[2].x)
254
+ assert_equal(40, seq1[2].y)
255
+
256
+ seq2 = CvSeq.new(Fixnum).push(10, 20)
257
+ seq2.insert(1, 15)
258
+ assert_equal(3, seq2.total)
259
+ assert_equal(10, seq2[0])
260
+ assert_equal(15, seq2[1])
261
+ assert_equal(20, seq2[2])
262
+ end
263
+
264
+ def test_remove
265
+ seq1 = CvSeq.new(CvPoint).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
266
+
267
+ seq1.remove(1)
268
+ assert_equal(2, seq1.total)
269
+ assert_equal(CvPoint, seq1[0].class)
270
+ assert_equal(10, seq1[0].x)
271
+ assert_equal(20, seq1[0].y)
272
+ assert_equal(CvPoint, seq1[1].class)
273
+ assert_equal(50, seq1[1].x)
274
+ assert_equal(60, seq1[1].y)
275
+ end
276
+
277
+ # These methods are tested in TestCvMat_imageprocessing#test_find_contours
278
+ # (test_cvmat_imageprocessing.rb)
279
+ # def test_h_prev
280
+ # flunk('FIXME: CvSeq#h_prev is not tested yet.')
281
+ # end
282
+
283
+ # def test_h_next
284
+ # flunk('FIXME: CvSeq#h_next is not tested yet.')
285
+ # end
286
+
287
+ # def test_v_prev
288
+ # flunk('FIXME: CvSeq#v_prev is not tested yet.')
289
+ # end
290
+
291
+ # def test_v_next
292
+ # flunk('FIXME: CvSeq#v_next is not tested yet.')
293
+ # end
294
+ end
295
+