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,113 @@
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::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,311 @@
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::CvSeq
10
+ class TestCvSeq < OpenCVTestCase
11
+ def test_initialize
12
+ types = [CV_SEQ_ELTYPE_POINT, CV_SEQ_ELTYPE_POINT3D, CV_SEQ_ELTYPE_CODE, CV_SEQ_ELTYPE_INDEX]
13
+ kinds = [CV_SEQ_KIND_GENERIC, CV_SEQ_KIND_CURVE, CV_SEQ_KIND_BIN_TREE, CV_SEQ_KIND_GRAPH, CV_SEQ_KIND_SUBDIV2D]
14
+ flags = [CV_SEQ_FLAG_CLOSED, CV_SEQ_FLAG_SIMPLE, CV_SEQ_FLAG_CONVEX, CV_SEQ_FLAG_HOLE]
15
+ types.each { |type|
16
+ kinds.each { |kind|
17
+ flags.each { |flag|
18
+ seq_flag = type | kind | flag
19
+ assert_equal(CvSeq, CvSeq.new(seq_flag).class)
20
+ }
21
+ }
22
+ }
23
+
24
+ [CV_SEQ_POINT_SET, CV_SEQ_POINT3D_SET, CV_SEQ_POLYLINE, CV_SEQ_POLYGON,
25
+ CV_SEQ_CONTOUR, CV_SEQ_SIMPLE_POLYGON, CV_SEQ_CHAIN, CV_SEQ_CHAIN_CONTOUR,
26
+ CV_SEQ_INDEX ].each { |seq_flag|
27
+ assert_equal(CvSeq, CvSeq.new(seq_flag).class)
28
+ }
29
+
30
+ # Unsupported types
31
+ [CV_SEQ_ELTYPE_PTR, CV_SEQ_ELTYPE_PPOINT].each { |type|
32
+ assert_raise(ArgumentError) {
33
+ CvSeq.new(type)
34
+ }
35
+ }
36
+ end
37
+
38
+ def test_total
39
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT)
40
+ assert_equal(0, seq1.total)
41
+
42
+ seq1.push(CvPoint.new(1, 2))
43
+ assert_equal(1, seq1.total)
44
+
45
+ seq1.push(CvPoint.new(3, 4))
46
+ assert_equal(2, seq1.total)
47
+ # Alias
48
+ assert_equal(2, seq1.length)
49
+ assert_equal(2, seq1.size)
50
+ end
51
+
52
+ def test_empty
53
+ assert(CvSeq.new(CV_SEQ_ELTYPE_POINT).empty?)
54
+ end
55
+
56
+ def test_aref
57
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT)
58
+ seq1.push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
59
+
60
+ assert_equal(CvPoint, seq1[0].class)
61
+ assert_equal(10, seq1[0].x)
62
+ assert_equal(20, seq1[0].y)
63
+ assert_equal(30, seq1[1].x)
64
+ assert_equal(40, seq1[1].y)
65
+ assert_equal(50, seq1[2].x)
66
+ assert_equal(60, seq1[2].y)
67
+
68
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX)
69
+ seq2.push(10, 20, 30)
70
+ assert_kind_of(Integer, seq2[0])
71
+ assert_equal(10, seq2[0])
72
+ assert_equal(20, seq2[1])
73
+ assert_equal(30, seq2[2])
74
+ end
75
+
76
+ def test_push
77
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
78
+
79
+ assert_equal(2, seq1.total)
80
+ assert_equal(CvPoint, seq1[0].class)
81
+ assert_equal(10, seq1[0].x)
82
+ assert_equal(20, seq1[0].y)
83
+ assert_equal(CvPoint, seq1[1].class)
84
+ assert_equal(30, seq1[1].x)
85
+ assert_equal(40, seq1[1].y)
86
+
87
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(50, 60))
88
+ seq2.push(seq1)
89
+ assert_equal(3, seq2.total)
90
+ assert_equal(CvPoint, seq2[0].class)
91
+ assert_equal(50, seq2[0].x)
92
+ assert_equal(60, seq2[0].y)
93
+ assert_equal(CvPoint, seq2[1].class)
94
+ assert_equal(10, seq2[1].x)
95
+ assert_equal(20, seq2[1].y)
96
+ assert_equal(CvPoint, seq2[2].class)
97
+ assert_equal(30, seq2[2].x)
98
+ assert_equal(40, seq2[2].y)
99
+
100
+ seq3 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10)
101
+ seq4 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(20, 30)
102
+ seq3.push(seq4)
103
+ assert_equal(3, seq3.total)
104
+ assert_kind_of(Integer, seq3[0])
105
+ assert_equal(10, seq3[0])
106
+ assert_equal(20, seq3[1])
107
+ assert_equal(30, seq3[2])
108
+
109
+ assert_raise(TypeError) {
110
+ seq1.push(55.5, 66.6)
111
+ }
112
+
113
+ assert_raise(TypeError) {
114
+ seq3 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(55, 66)
115
+ seq1.push(seq3)
116
+ }
117
+ end
118
+
119
+ def test_pop
120
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
121
+ point1 = seq1.pop
122
+ assert_equal(CvPoint, point1.class)
123
+ assert_equal(30, point1.x)
124
+ assert_equal(40, point1.y)
125
+
126
+ assert_equal(1, seq1.total)
127
+ assert_equal(CvPoint, seq1[0].class)
128
+ assert_equal(10, seq1[0].x)
129
+ assert_equal(20, seq1[0].y)
130
+
131
+ assert_nil(CvSeq.new(CV_SEQ_ELTYPE_POINT).pop)
132
+
133
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
134
+ assert_equal(30, seq2.pop)
135
+ assert_equal(20, seq2.pop)
136
+ assert_equal(10, seq2.pop)
137
+ end
138
+
139
+ def test_clear
140
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
141
+ seq1.clear
142
+ assert_not_nil(seq1)
143
+ assert_equal(0, seq1.total)
144
+ end
145
+
146
+ def test_unshift
147
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).unshift(CvPoint.new(10, 20), CvPoint.new(30, 40))
148
+
149
+ assert_equal(2, seq1.total)
150
+ assert_equal(CvPoint, seq1[0].class)
151
+ assert_equal(30, seq1[0].x)
152
+ assert_equal(40, seq1[0].y)
153
+ assert_equal(CvPoint, seq1[1].class)
154
+ assert_equal(10, seq1[1].x)
155
+ assert_equal(20, seq1[1].y)
156
+
157
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_POINT).unshift(CvPoint.new(50, 60))
158
+ seq2.unshift(seq1)
159
+ assert_equal(3, seq2.total)
160
+ assert_equal(CvPoint, seq1[0].class)
161
+ assert_equal(30, seq1[0].x)
162
+ assert_equal(40, seq1[0].y)
163
+ assert_equal(CvPoint, seq1[1].class)
164
+ assert_equal(10, seq1[1].x)
165
+ assert_equal(20, seq1[1].y)
166
+ assert_equal(CvPoint, seq2[2].class)
167
+ assert_equal(50, seq2[2].x)
168
+ assert_equal(60, seq2[2].y)
169
+
170
+ seq3 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).unshift(10, 20, 30)
171
+ assert_equal(3, seq3.total)
172
+ assert_equal(30, seq3[0])
173
+ assert_equal(20, seq3[1])
174
+ assert_equal(10, seq3[2])
175
+
176
+ assert_raise(TypeError) {
177
+ seq1.unshift(10)
178
+ }
179
+
180
+ assert_raise(TypeError) {
181
+ seq3 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
182
+ seq1.unshift(seq3)
183
+ }
184
+ end
185
+
186
+ def test_shift
187
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
188
+ point1 = seq1.shift
189
+ assert_equal(CvPoint, point1.class)
190
+ assert_equal(10, point1.x)
191
+ assert_equal(20, point1.y)
192
+
193
+ assert_equal(1, seq1.total)
194
+ assert_equal(CvPoint, seq1[0].class)
195
+ assert_equal(30, seq1[0].x)
196
+ assert_equal(40, seq1[0].y)
197
+
198
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
199
+ assert_equal(10, seq2.shift)
200
+ assert_equal(20, seq2.shift)
201
+ assert_equal(30, seq2.shift)
202
+
203
+ assert_nil(CvSeq.new(CV_SEQ_ELTYPE_POINT).shift)
204
+ end
205
+
206
+ def test_first
207
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
208
+ point1 = seq1.first
209
+ assert_equal(CvPoint, point1.class)
210
+ assert_equal(10, point1.x)
211
+ assert_equal(20, point1.y)
212
+
213
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
214
+ assert_equal(10, seq2.first)
215
+ end
216
+
217
+ def test_last
218
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
219
+ point1 = seq1.last
220
+ assert_equal(CvPoint, point1.class)
221
+ assert_equal(50, point1.x)
222
+ assert_equal(60, point1.y)
223
+
224
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
225
+ assert_equal(30, seq2.last)
226
+ end
227
+
228
+ def test_each
229
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
230
+ i = 0
231
+ seq1.each { |s|
232
+ assert_equal(CvPoint, s.class)
233
+ assert_equal(seq1[i].x, s.x)
234
+ assert_equal(seq1[i].y, s.y)
235
+ i += 1
236
+ }
237
+ assert_equal(3, i)
238
+
239
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20, 30)
240
+ i = 0
241
+ seq2.each { |s|
242
+ assert_equal(seq2[i], s)
243
+ i += 1
244
+ }
245
+ assert_equal(3, i)
246
+ end
247
+
248
+ def test_each_index
249
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
250
+ n = 0
251
+ seq1.each_index { |i|
252
+ assert_equal(n, i)
253
+ n += 1
254
+ }
255
+ assert_equal(3, n)
256
+ end
257
+
258
+ def test_insert
259
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40))
260
+ seq1.insert(1, CvPoint.new(50, 60))
261
+ assert_equal(3, seq1.total)
262
+ assert_equal(CvPoint, seq1[0].class)
263
+ assert_equal(10, seq1[0].x)
264
+ assert_equal(20, seq1[0].y)
265
+ assert_equal(CvPoint, seq1[1].class)
266
+ assert_equal(50, seq1[1].x)
267
+ assert_equal(60, seq1[1].y)
268
+ assert_equal(CvPoint, seq1[2].class)
269
+ assert_equal(30, seq1[2].x)
270
+ assert_equal(40, seq1[2].y)
271
+
272
+ seq2 = CvSeq.new(CV_SEQ_ELTYPE_INDEX).push(10, 20)
273
+ seq2.insert(1, 15)
274
+ assert_equal(3, seq2.total)
275
+ assert_equal(10, seq2[0])
276
+ assert_equal(15, seq2[1])
277
+ assert_equal(20, seq2[2])
278
+ end
279
+
280
+ def test_remove
281
+ seq1 = CvSeq.new(CV_SEQ_ELTYPE_POINT).push(CvPoint.new(10, 20), CvPoint.new(30, 40), CvPoint.new(50, 60))
282
+
283
+ seq1.remove(1)
284
+ assert_equal(2, seq1.total)
285
+ assert_equal(CvPoint, seq1[0].class)
286
+ assert_equal(10, seq1[0].x)
287
+ assert_equal(20, seq1[0].y)
288
+ assert_equal(CvPoint, seq1[1].class)
289
+ assert_equal(50, seq1[1].x)
290
+ assert_equal(60, seq1[1].y)
291
+ end
292
+
293
+ # These methods are tested in TestCvMat_imageprocessing#test_find_contours
294
+ # (test_cvmat_imageprocessing.rb)
295
+ # def test_h_prev
296
+ # flunk('FIXME: CvSeq#h_prev is not tested yet.')
297
+ # end
298
+
299
+ # def test_h_next
300
+ # flunk('FIXME: CvSeq#h_next is not tested yet.')
301
+ # end
302
+
303
+ # def test_v_prev
304
+ # flunk('FIXME: CvSeq#v_prev is not tested yet.')
305
+ # end
306
+
307
+ # def test_v_next
308
+ # flunk('FIXME: CvSeq#v_next is not tested yet.')
309
+ # end
310
+ end
311
+
@@ -0,0 +1,75 @@
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::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
+