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,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
+
@@ -0,0 +1,75 @@
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::CvSize
10
+ class TestCvSize < OpenCVTestCase
11
+ class MySize; end
12
+
13
+ def test_width
14
+ size = CvSize.new
15
+ size.width = 100
16
+ assert_equal(100, size.width)
17
+ size.width = 200
18
+ assert_equal(200, size.width)
19
+ end
20
+
21
+ def test_height
22
+ size = CvSize.new
23
+ size.height = 100
24
+ assert_equal(100, size.height)
25
+ size.height = 200
26
+ assert_equal(200, size.height)
27
+ end
28
+
29
+ def test_compatible
30
+ assert(!(CvSize.compatible? MySize.new))
31
+ MySize.class_eval { def width; end }
32
+ assert(!(CvSize.compatible? MySize.new))
33
+ MySize.class_eval { def height; end }
34
+ assert(CvSize.compatible? MySize.new)
35
+ assert(CvSize.compatible? CvSize.new)
36
+ end
37
+
38
+ def test_initialize
39
+ size = CvSize.new
40
+ assert_equal(0, size.width)
41
+ assert_equal(0, size.height)
42
+
43
+ size = CvSize.new(10, 20)
44
+ assert_equal(10, size.width)
45
+ assert_equal(20, size.height)
46
+
47
+ size = CvSize.new(CvSize.new(10, 20))
48
+ assert_equal(10, size.width)
49
+ assert_equal(20, size.height)
50
+
51
+ assert_raise(TypeError) {
52
+ CvSize.new(DUMMY_OBJ)
53
+ }
54
+ assert_raise(ArgumentError) {
55
+ CvSize.new(1, 2, 3)
56
+ }
57
+ end
58
+
59
+ def test_to_s
60
+ size = CvSize.new(10, 20)
61
+ assert_equal('<OpenCV::CvSize:10x20>', size.to_s)
62
+ end
63
+
64
+ def test_to_ary
65
+ a = CvSize.new(10, 20).to_ary
66
+ assert_equal(10, a[0])
67
+ assert_equal(20, a[1])
68
+
69
+ # Alias
70
+ a = CvSize.new(10, 20).to_a
71
+ assert_equal(10, a[0])
72
+ assert_equal(20, a[1])
73
+ end
74
+ end
75
+