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,180 @@
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::CvMoment
10
+ class TestCvMoments < OpenCVTestCase
11
+ def setup
12
+ @mat = create_cvmat(128, 128, :cv8u, 1) { |j, i|
13
+ if j >= 32 and j < 96 and i >= 16 and i < 112
14
+ CvScalar.new(0)
15
+ elsif j >= 16 and j < 112 and i >= 16 and i < 112
16
+ CvScalar.new(128)
17
+ else
18
+ CvScalar.new(255)
19
+ end
20
+ }
21
+ @moment1 = CvMoments.new
22
+ @moment2 = CvMoments.new(nil, true)
23
+ @moment3 = CvMoments.new(@mat)
24
+ @moment4 = CvMoments.new(@mat, true)
25
+ end
26
+
27
+ def test_initialize
28
+ [@moment1, @moment2, @moment3, @moment4].each { |m|
29
+ assert_not_nil(m)
30
+ assert_equal(CvMoments, m.class)
31
+ }
32
+
33
+ assert_raise(TypeError) {
34
+ CvMoments.new('foo')
35
+ }
36
+ end
37
+
38
+ def test_spatial
39
+ assert_in_delta(0, @moment1.spatial(0, 0), 0.1)
40
+ assert_in_delta(0, @moment2.spatial(0, 0), 0.1)
41
+ assert_in_delta(2221056, @moment3.spatial(0, 0), 0.1)
42
+ assert_in_delta(10240, @moment4.spatial(0, 0), 0.1)
43
+ end
44
+
45
+ def test_central
46
+ assert_in_delta(0, @moment1.central(0, 0), 0.1)
47
+ assert_in_delta(0, @moment2.central(0, 0), 0.1)
48
+ assert_in_delta(2221056, @moment3.central(0, 0), 0.1)
49
+ assert_in_delta(10240, @moment4.central(0, 0), 0.1)
50
+ end
51
+
52
+ def test_normalized_central
53
+ assert_in_delta(0, @moment1.normalized_central(0, 0), 0.1)
54
+ assert_in_delta(0, @moment2.normalized_central(0, 0), 0.1)
55
+ assert_in_delta(1, @moment3.normalized_central(0, 0), 0.1)
56
+ assert_in_delta(1, @moment4.normalized_central(0, 0), 0.1)
57
+ end
58
+
59
+ def test_hu
60
+ hu_moments = @moment1.hu
61
+ assert_equal(CvHuMoments, hu_moments.class)
62
+ hu_moments.to_a.each { |hu|
63
+ assert_in_delta(0.0, hu, 0.000001)
64
+ }
65
+
66
+ hu_moments = @moment2.hu
67
+ assert_equal(CvHuMoments, hu_moments.class)
68
+ hu_moments.to_a.each { |hu|
69
+ assert_in_delta(0.0, hu, 0.000001)
70
+ }
71
+
72
+ hu_moments = @moment3.hu
73
+ assert_equal(CvHuMoments, hu_moments.class)
74
+ assert_in_delta(0.001771, hu_moments.hu1, 0.000001)
75
+ hu_moments.to_a[1..7].each { |hu|
76
+ assert_in_delta(0.0, hu, 0.000001)
77
+ }
78
+
79
+ hu_moments = @moment4.hu
80
+ assert_equal(CvHuMoments, hu_moments.class)
81
+ assert_in_delta(0.361650, hu_moments.hu1, 0.000001)
82
+ assert_in_delta(0.000625, hu_moments.hu2, 0.000001)
83
+ hu_moments.to_a[2..7].each { |hu|
84
+ assert_in_delta(0.0, hu, 0.000001)
85
+ }
86
+ end
87
+
88
+ def test_gravity_center
89
+ center = @moment1.gravity_center
90
+ assert_equal(CvPoint2D32f, center.class)
91
+ assert(center.x.nan?)
92
+ assert(center.y.nan?)
93
+
94
+ center = @moment2.gravity_center
95
+ assert_equal(CvPoint2D32f, center.class)
96
+ assert(center.x.nan?)
97
+ assert(center.y.nan?)
98
+
99
+ center = @moment3.gravity_center
100
+ assert_equal(CvPoint2D32f, center.class)
101
+ assert_in_delta(63.5, center.x, 0.001)
102
+ assert_in_delta(63.5, center.y, 0.001)
103
+
104
+ center = @moment4.gravity_center
105
+ assert_equal(CvPoint2D32f, center.class)
106
+ assert_in_delta(63.5, center.x, 0.001)
107
+ assert_in_delta(63.5, center.y, 0.001)
108
+ end
109
+
110
+ def test_angle
111
+ [@moment1, @moment2].each { |m|
112
+ assert_nil(m.angle)
113
+ }
114
+ [@moment3, @moment4].each { |m|
115
+ assert_in_delta(0, m.angle, 0.001)
116
+ }
117
+ end
118
+
119
+ def test_mXX
120
+ [@moment1, @moment2].each { |m|
121
+ assert_in_delta(0, m.m00, 0.001)
122
+ assert_in_delta(0, m.m10, 0.001)
123
+ assert_in_delta(0, m.m01, 0.001)
124
+ assert_in_delta(0, m.m20, 0.001)
125
+ assert_in_delta(0, m.m11, 0.001)
126
+ assert_in_delta(0, m.m02, 0.001)
127
+ assert_in_delta(0, m.m30, 0.001)
128
+ assert_in_delta(0, m.m21, 0.001)
129
+ assert_in_delta(0, m.m12, 0.001)
130
+ assert_in_delta(0, m.m03, 0.001)
131
+ assert_in_delta(0, m.mu20, 0.001)
132
+ assert_in_delta(0, m.mu11, 0.001)
133
+ assert_in_delta(0, m.mu02, 0.001)
134
+ assert_in_delta(0, m.mu30, 0.001)
135
+ assert_in_delta(0, m.mu21, 0.001)
136
+ assert_in_delta(0, m.mu12, 0.001)
137
+ assert_in_delta(0, m.mu03, 0.001)
138
+ assert_in_delta(0, m.inv_sqrt_m00, 0.001)
139
+ }
140
+
141
+ assert_in_delta(2221056, @moment3.m00, 0.001)
142
+ assert_in_delta(141037056, @moment3.m10, 0.001)
143
+ assert_in_delta(141037056, @moment3.m01, 0.001)
144
+ assert_in_delta(13157049856, @moment3.m20, 0.001)
145
+ assert_in_delta(8955853056, @moment3.m11, 0.001)
146
+ assert_in_delta(13492594176, @moment3.m02, 0.001)
147
+ assert_in_delta(1369024659456, @moment3.m30, 0.001)
148
+ assert_in_delta(835472665856, @moment3.m21, 0.001)
149
+ assert_in_delta(856779730176, @moment3.m12, 0.001)
150
+ assert_in_delta(1432945852416, @moment3.m03, 0.001)
151
+ assert_in_delta(4201196800, @moment3.mu20, 0.001)
152
+ assert_in_delta(0, @moment3.mu11, 0.001)
153
+ assert_in_delta(4536741120, @moment3.mu02, 0.001)
154
+ assert_in_delta(0, @moment3.mu30, 0.001)
155
+ assert_in_delta(0, @moment3.mu21, 0.001)
156
+ assert_in_delta(0, @moment3.mu12, 0.001)
157
+ assert_in_delta(0, @moment3.mu03, 0.001)
158
+ assert_in_delta(0.000671, @moment3.inv_sqrt_m00, 0.000001)
159
+
160
+ assert_in_delta(10240, @moment4.m00, 0.001)
161
+ assert_in_delta(650240, @moment4.m10, 0.001)
162
+ assert_in_delta(650240, @moment4.m01, 0.001)
163
+ assert_in_delta(58940416, @moment4.m20, 0.001)
164
+ assert_in_delta(41290240, @moment4.m11, 0.001)
165
+ assert_in_delta(61561856, @moment4.m02, 0.001)
166
+ assert_in_delta(5984288768, @moment4.m30, 0.001)
167
+ assert_in_delta(3742716416, @moment4.m21, 0.001)
168
+ assert_in_delta(3909177856, @moment4.m12, 0.001)
169
+ assert_in_delta(6483673088, @moment4.m03, 0.001)
170
+ assert_in_delta(17650176, @moment4.mu20, 0.001)
171
+ assert_in_delta(0, @moment4.mu11, 0.001)
172
+ assert_in_delta(20271616, @moment4.mu02, 0.001)
173
+ assert_in_delta(0, @moment4.mu30, 0.001)
174
+ assert_in_delta(0, @moment4.mu21, 0.001)
175
+ assert_in_delta(0, @moment4.mu12, 0.001)
176
+ assert_in_delta(0, @moment4.mu03, 0.001)
177
+ assert_in_delta(0.009882, @moment4.inv_sqrt_m00, 0.000001)
178
+ end
179
+ end
180
+
@@ -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::CvPoint
10
+ class TestCvPoint < OpenCVTestCase
11
+ class MyPoint; end
12
+ def test_x
13
+ point = CvPoint.new
14
+ point.x = 100
15
+ assert_equal(100, point.x)
16
+ point.x = 200
17
+ assert_equal(200, point.x)
18
+ end
19
+
20
+ def test_y
21
+ point = CvPoint.new
22
+ point.y = 100
23
+ assert_equal(100, point.y)
24
+ point.y = 200
25
+ assert_equal(200, point.y)
26
+ end
27
+
28
+ def test_compatible
29
+ assert(!(CvPoint.compatible? MyPoint.new))
30
+ MyPoint.class_eval { def x; end }
31
+ assert(!(CvPoint.compatible? MyPoint.new))
32
+ MyPoint.class_eval { def y; end }
33
+ assert(CvPoint.compatible? MyPoint.new)
34
+ assert(CvPoint.compatible? CvPoint.new)
35
+ end
36
+
37
+ def test_initialize
38
+ point = CvPoint.new
39
+ assert_equal(0, point.x)
40
+ assert_equal(0, point.y)
41
+
42
+ point = CvPoint.new(10, 20)
43
+ assert_equal(10, point.x)
44
+ assert_equal(20, point.y)
45
+
46
+ point = CvPoint.new(CvPoint.new(10, 20))
47
+ assert_equal(10, point.x)
48
+ assert_equal(20, point.y)
49
+
50
+ assert_raise(TypeError) {
51
+ CvPoint.new(DUMMY_OBJ)
52
+ }
53
+ assert_raise(ArgumentError) {
54
+ CvPoint.new(1, 2, 3)
55
+ }
56
+ end
57
+
58
+ def test_to_s
59
+ point = CvPoint.new(10, 20)
60
+ assert_equal('<OpenCV::CvPoint:(10,20)>', point.to_s)
61
+ end
62
+
63
+ def test_to_ary
64
+ a = CvPoint.new(10, 20).to_ary
65
+ assert_equal(10, a[0])
66
+ assert_equal(20, a[1])
67
+
68
+ # Alias
69
+ a = CvPoint.new(10, 20).to_a
70
+ assert_equal(10, a[0])
71
+ assert_equal(20, a[1])
72
+ end
73
+ end
74
+
75
+
@@ -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::CvPoint2D32f
10
+ class TestCvPoint2D32f < OpenCVTestCase
11
+ class MyPoint; end
12
+ def test_x
13
+ point = CvPoint2D32f.new
14
+ point.x = 1.1
15
+ assert_in_delta(1.1, point.x, 0.001)
16
+ point.x = 2.2
17
+ assert_in_delta(2.2, point.x, 0.001)
18
+ end
19
+
20
+ def test_y
21
+ point = CvPoint2D32f.new
22
+ point.y = 1.1
23
+ assert_in_delta(1.1, point.y, 0.001)
24
+ point.y = 2.2
25
+ assert_in_delta(2.2, point.y, 0.001)
26
+ end
27
+
28
+ def test_compatible
29
+ assert(!(CvPoint2D32f.compatible? MyPoint.new))
30
+ MyPoint.class_eval { def x; end }
31
+ assert(!(CvPoint2D32f.compatible? MyPoint.new))
32
+ MyPoint.class_eval { def y; end }
33
+ assert(CvPoint2D32f.compatible? MyPoint.new)
34
+ assert(CvPoint2D32f.compatible? CvPoint2D32f.new)
35
+ end
36
+
37
+ def test_initialize
38
+ point = CvPoint2D32f.new
39
+ assert_in_delta(0, point.x, 0.001)
40
+ assert_in_delta(0, point.y, 0.001)
41
+
42
+ point = CvPoint2D32f.new(1.1, 2.2)
43
+ assert_in_delta(1.1, point.x, 0.001)
44
+ assert_in_delta(2.2, point.y, 0.001)
45
+
46
+ point = CvPoint2D32f.new(CvPoint2D32f.new(1.1, 2.2))
47
+ assert_in_delta(1.1, point.x, 0.001)
48
+ assert_in_delta(2.2, point.y, 0.001)
49
+
50
+ assert_raise(TypeError) {
51
+ CvPoint2D32f.new(DUMMY_OBJ)
52
+ }
53
+ assert_raise(ArgumentError) {
54
+ CvPoint2D32f.new(1, 2, 3)
55
+ }
56
+ end
57
+
58
+ def test_to_s
59
+ point = CvPoint2D32f.new(1.1, 2.2)
60
+ assert_equal('<OpenCV::CvPoint2D32f:(1.1,2.2)>', point.to_s)
61
+ end
62
+
63
+ def test_to_ary
64
+ a = CvPoint2D32f.new(1.1, 2.2).to_ary
65
+ assert_in_delta(1.1, a[0], 0.001)
66
+ assert_in_delta(2.2, a[1], 0.001)
67
+
68
+ # Alias
69
+ a = CvPoint2D32f.new(1.1, 2.2).to_a
70
+ assert_in_delta(1.1, a[0], 0.001)
71
+ assert_in_delta(2.2, a[1], 0.001)
72
+ end
73
+ end
74
+
75
+
@@ -0,0 +1,93 @@
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::CvPoint3D32f
10
+ class TestCvPoint3D32f < OpenCVTestCase
11
+ class MyPoint; end
12
+ def test_x
13
+ point = CvPoint3D32f.new
14
+ point.x = 1.1
15
+ assert_in_delta(1.1, point.x, 0.001)
16
+ point.x = 2.2
17
+ assert_in_delta(2.2, point.x, 0.001)
18
+ end
19
+
20
+ def test_y
21
+ point = CvPoint3D32f.new
22
+ point.y = 1.1
23
+ assert_in_delta(1.1, point.y, 0.001)
24
+ point.y = 2.2
25
+ assert_in_delta(2.2, point.y, 0.001)
26
+ end
27
+
28
+ def test_z
29
+ point = CvPoint3D32f.new
30
+ point.z = 1.1
31
+ assert_in_delta(1.1, point.z, 0.001)
32
+ point.z = 2.2
33
+ assert_in_delta(2.2, point.z, 0.001)
34
+ end
35
+
36
+ def test_compatible
37
+ assert(!(CvPoint3D32f.compatible? MyPoint.new))
38
+ MyPoint.class_eval { def x; end }
39
+ assert(!(CvPoint3D32f.compatible? MyPoint.new))
40
+ MyPoint.class_eval { def y; end }
41
+ assert(!(CvPoint3D32f.compatible? MyPoint.new))
42
+ MyPoint.class_eval { def z; end }
43
+ assert(CvPoint3D32f.compatible? MyPoint.new)
44
+ assert(CvPoint3D32f.compatible? CvPoint3D32f.new)
45
+ end
46
+
47
+ def test_initialize
48
+ point = CvPoint3D32f.new
49
+ assert_in_delta(0, point.x, 0.001)
50
+ assert_in_delta(0, point.y, 0.001)
51
+ assert_in_delta(0, point.z, 0.001)
52
+
53
+ point = CvPoint3D32f.new(1.1, 2.2, 3.3)
54
+ assert_in_delta(1.1, point.x, 0.001)
55
+ assert_in_delta(2.2, point.y, 0.001)
56
+ assert_in_delta(3.3, point.z, 0.001)
57
+
58
+ point = CvPoint3D32f.new(CvPoint3D32f.new(1.1, 2.2, 3.3))
59
+ assert_in_delta(1.1, point.x, 0.001)
60
+ assert_in_delta(2.2, point.y, 0.001)
61
+ assert_in_delta(3.3, point.z, 0.001)
62
+
63
+ assert_raise(TypeError) {
64
+ CvPoint3D32f.new(DUMMY_OBJ)
65
+ }
66
+ assert_raise(ArgumentError) {
67
+ CvPoint3D32f.new(1, 2)
68
+ }
69
+ assert_raise(ArgumentError) {
70
+ CvPoint3D32f.new(1, 2, 3, 4)
71
+ }
72
+ end
73
+
74
+ def test_to_s
75
+ point = CvPoint3D32f.new(1.1, 2.2, 3.3)
76
+ assert_equal('<OpenCV::CvPoint3D32f:(1.1,2.2,3.3)>', point.to_s)
77
+ end
78
+
79
+ def test_to_ary
80
+ a = CvPoint3D32f.new(1.1, 2.2, 3.3).to_ary
81
+ assert_in_delta(1.1, a[0], 0.001)
82
+ assert_in_delta(2.2, a[1], 0.001)
83
+ assert_in_delta(3.3, a[2], 0.001)
84
+
85
+ # Alias
86
+ a = CvPoint3D32f.new(1.1, 2.2, 3.3).to_a
87
+ assert_in_delta(1.1, a[0], 0.001)
88
+ assert_in_delta(2.2, a[1], 0.001)
89
+ assert_in_delta(3.3, a[2], 0.001)
90
+ end
91
+ end
92
+
93
+
@@ -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
+