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,318 @@
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 drawing functions of OpenCV::CvMat
10
+ class TestCvMat_drawing < OpenCVTestCase
11
+ def test_DRAWING_OPTION
12
+ CvMat::DRAWING_OPTION[:color].to_ary.each { |c|
13
+ assert_in_delta(0, c, 0.01)
14
+ }
15
+ assert_equal(1, CvMat::DRAWING_OPTION[:thickness])
16
+ assert_equal(8, CvMat::DRAWING_OPTION[:line_type])
17
+ assert_equal(0, CvMat::DRAWING_OPTION[:shift])
18
+ end
19
+
20
+ def test_FLOOD_FILL_OPTION
21
+ assert_equal(4, CvMat::FLOOD_FILL_OPTION[:connectivity])
22
+ assert((not CvMat::FLOOD_FILL_OPTION[:fixed_range]))
23
+ assert((not CvMat::FLOOD_FILL_OPTION[:mask_only]))
24
+ end
25
+
26
+ def test_line
27
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
28
+ m1 = m0.clone
29
+ m2 = m0.line(CvPoint.new(1, 0), CvPoint.new(m0.width - 1, m0.height - 1),
30
+ :color => CvColor::Red, :thickness => 3, :line_type => :aa)
31
+ m1.line!(CvPoint.new(1, 0), CvPoint.new(m0.width - 1, m0.height - 1),
32
+ :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
33
+
34
+ # Uncomment the following line to show the image
35
+ # snap(['Line: Blue, thickness = 1', m1], ['Line: Red, thickness = 3', m2])
36
+
37
+ assert_raise(TypeError) {
38
+ m0.line(DUMMY_OBJ, CvPoint.new(1, 0))
39
+ }
40
+ assert_raise(TypeError) {
41
+ m0.line(CvPoint.new(1, 0), DUMMY_OBJ)
42
+ }
43
+ assert_raise(TypeError) {
44
+ m0.line(CvPoint.new(1, 0), CvPoint.new(1, 1), :color => DUMMY_OBJ)
45
+ }
46
+ # assert_raise(CvError) {
47
+ # m0.line(CvPoint.new(1, 0), CvPoint.new(1, 1), :thickness => DUMMY_OBJ)
48
+ # }
49
+ # m0.line(CvPoint.new(1, 0), CvPoint.new(1, 1), :line_type => DUMMY_OBJ)
50
+ end
51
+
52
+ def test_rectangle
53
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
54
+ m1 = m0.clone
55
+ m2 = m0.rectangle(CvPoint.new(20, 20), CvPoint.new(m0.width - 20, m0.height - 20),
56
+ :color => CvColor::Red, :thickness => 3, :line_type => :aa)
57
+ m1.rectangle!(CvPoint.new(20, 20), CvPoint.new(m0.width - 20, m0.height - 20),
58
+ :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
59
+
60
+ # Uncomment the following line to show the image
61
+ # snap(['Rectangle: Blue, thickness = 1', m1], ['Rectangle: Red, thickness = 3', m2])
62
+
63
+ assert_raise(TypeError) {
64
+ m0.line(DUMMY_OBJ, CvPoint.new(1, 0))
65
+ }
66
+ assert_raise(TypeError) {
67
+ m0.rectangle(CvPoint.new(1, 0), DUMMY_OBJ)
68
+ }
69
+ assert_raise(TypeError) {
70
+ m0.rectangle(CvPoint.new(1, 0), CvPoint.new(1, 1), :color => DUMMY_OBJ)
71
+ }
72
+ # assert_raise(CvError) {
73
+ # m0.rectangle(CvPoint.new(1, 0), CvPoint.new(1, 1), :thickness => DUMMY_OBJ)
74
+ # }
75
+ # m0.rectangle(CvPoint.new(1, 0), CvPoint.new(1, 1), :line_type => DUMMY_OBJ)
76
+ end
77
+
78
+ def test_circle
79
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
80
+ m1 = m0.clone
81
+ m2 = m0.circle(CvPoint.new(m0.width / 2, m0.height / 2), 80,
82
+ :color => CvColor::Red, :thickness => 3, :line_type => :aa)
83
+ m1.circle!(CvPoint.new(m0.width / 2, m0.height / 2), 80,
84
+ :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
85
+
86
+ # Uncomment the following line to show the image
87
+ # snap(['Circle: Blue, thickness = 1', m1], ['Circle: Red, thickness = 3', m2])
88
+
89
+ assert_raise(TypeError) {
90
+ m0.circle(DUMMY_OBJ, 10)
91
+ }
92
+ assert_raise(TypeError) {
93
+ m0.circle(CvPoint.new(1, 0), DUMMY_OBJ)
94
+ }
95
+ assert_raise(TypeError) {
96
+ m0.circle(CvPoint.new(1, 0), 10, :color => DUMMY_OBJ)
97
+ }
98
+ # assert_raise(CvError) {
99
+ # m0.circle(CvPoint.new(1, 0), 10, :thickness => DUMMY_OBJ)
100
+ # }
101
+ m0.circle(CvPoint.new(1, 0), 10, :line_type => DUMMY_OBJ)
102
+ end
103
+
104
+ def test_ellipse
105
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
106
+ m1 = m0.clone
107
+ m2 = m0.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, 360,
108
+ :color => CvColor::Red, :thickness => 3, :line_type => :aa)
109
+ m1.ellipse!(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, 360,
110
+ :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
111
+
112
+ # Uncomment the following line to show the image
113
+ # snap(['Ellipse: Blue, thickness = 1', m1], ['Ellipse: Red, thickness = 3', m2])
114
+
115
+ assert_raise(TypeError) {
116
+ m1.ellipse(DUMMY_OBJ, CvSize.new(100, 60), 30, 0, 360)
117
+ }
118
+ assert_raise(TypeError) {
119
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), DUMMY_OBJ, 30, 0, 360)
120
+ }
121
+ assert_raise(TypeError) {
122
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), DUMMY_OBJ, 0, 360)
123
+ }
124
+ assert_raise(TypeError) {
125
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, DUMMY_OBJ, 360)
126
+ }
127
+ assert_raise(TypeError) {
128
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, DUMMY_OBJ)
129
+ }
130
+ assert_raise(TypeError) {
131
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, 360,
132
+ :color => DUMMY_OBJ)
133
+ }
134
+ # assert_raise(CvError) {
135
+ # m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, 360,
136
+ # :thickness => DUMMY_OBJ)
137
+ # }
138
+ m1.ellipse(CvPoint.new(m0.width / 2, m0.height / 2), CvSize.new(100, 60), 30, 0, 360,
139
+ :line_type => DUMMY_OBJ)
140
+ end
141
+
142
+ def test_ellipse_box
143
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
144
+ box = CvBox2D.new(CvPoint2D32f.new(m0.width / 2, m0.height / 2), CvSize2D32f.new(120, 160), 30)
145
+ m1 = m0.clone
146
+ m2 = m0.ellipse_box(box, :color => CvColor::Red, :thickness => 3, :line_type => :aa)
147
+ m1.ellipse_box!(box, :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
148
+
149
+ # Uncomment the following line to show the image
150
+ # snap(['Ellipse box: Blue, thickness = 1', m1], ['Ellipse box: Red, thickness = 3', m2])
151
+
152
+ assert_raise(TypeError) {
153
+ m1.ellipse_box(DUMMY_OBJ)
154
+ }
155
+ assert_raise(TypeError) {
156
+ m1.ellipse_box(box, :color => DUMMY_OBJ)
157
+ }
158
+ # assert_raise(CvError) {
159
+ # m1.ellipse_box(box, :thickness => DUMMY_OBJ)
160
+ # }
161
+ m1.ellipse_box(box, :line_type => DUMMY_OBJ)
162
+ end
163
+
164
+ def test_fill_poly
165
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
166
+ pt = [[CvPoint.new(10, 20), CvPoint.new(10, 150), CvPoint.new(100, 50)],
167
+ [CvPoint.new(200, 10), CvPoint.new(200, 200), CvPoint.new(170, 200)],
168
+ [CvPoint.new(30, 10), CvPoint.new(0, 0), CvPoint.new(90, 150)]]
169
+
170
+ m1 = m0.clone
171
+ m2 = m0.fill_poly(pt, :color => CvColor::Red, :line_type => :aa)
172
+ m1.fill_poly!(pt, :color => CvColor::Blue, :line_type => :aa)
173
+
174
+ # Uncomment the following line to view the image
175
+ # snap(['Fill poly: Blue', m1], ['Fill poly: Red', m2])
176
+
177
+ assert_raise(TypeError) {
178
+ m1.fill_poly(DUMMY_OBJ)
179
+ }
180
+ assert_raise(TypeError) {
181
+ m1.fill_poly([DUMMY_OBJ, DUMMY_OBJ])
182
+ }
183
+ assert_raise(TypeError) {
184
+ m1.fill_poly(pt, :color => DUMMY_OBJ)
185
+ }
186
+ # assert_raise(CvError) {
187
+ # m1.fill_poly(pt, :thickness => DUMMY_OBJ)
188
+ # }
189
+ # m1.fill_poly(pt, :line_type => DUMMY_OBJ)
190
+ end
191
+
192
+ def test_fill_convex_poly
193
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
194
+ pt = [CvPoint.new(10, 20), CvPoint.new(10, 150), CvPoint.new(100, 50)]
195
+
196
+ m1 = m0.clone
197
+ m2 = m0.fill_convex_poly(pt, :color => CvColor::Red, :line_type => :aa)
198
+ m1.fill_convex_poly!(pt, :color => CvColor::Blue, :line_type => :aa)
199
+
200
+ # Uncomment the following line to view the image
201
+ # snap(['Fill convex poly: Blue', m1], ['Fill convex poly: Red', m2])
202
+
203
+
204
+ assert_raise(TypeError) {
205
+ m1.fill_convex_poly(DUMMY_OBJ)
206
+ }
207
+ assert_raise(TypeError) {
208
+ m1.fill_convex_poly([DUMMY_OBJ, DUMMY_OBJ])
209
+ }
210
+ assert_raise(TypeError) {
211
+ m1.fill_convex_poly(pt, :color => DUMMY_OBJ)
212
+ }
213
+ # assert_raise(CvError) {
214
+ # m1.fill_convex_poly(pt, :thickness => DUMMY_OBJ)
215
+ # }
216
+ # m1.fill_convex_poly(pt, :line_type => DUMMY_OBJ)
217
+ end
218
+
219
+ def test_poly_line
220
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
221
+ pt = [[CvPoint.new(10, 20), CvPoint.new(10, 150), CvPoint.new(100, 150), CvPoint.new(10, 20)],
222
+ [CvPoint.new(100, 200), CvPoint.new(200, 190), CvPoint.new(180, 50), CvPoint.new(100, 200)]]
223
+
224
+ m1 = m0.clone
225
+ m2 = m0.poly_line(pt, :color => CvColor::Red, :thickness => 3, :line_type => :aa)
226
+ m1.poly_line!(pt, :color => CvColor::Blue, :thickness => 1, :line_type => :aa)
227
+
228
+ # Uncomment the following line to view the image
229
+ # snap(['Fill poly line: Blue, thickness = 1', m1], ['Fill poly line: Red, thickness = 3', m2])
230
+
231
+ assert_raise(TypeError) {
232
+ m1.poly_line(DUMMY_OBJ)
233
+ }
234
+ assert_raise(TypeError) {
235
+ m1.poly_line([DUMMY_OBJ, DUMMY_OBJ])
236
+ }
237
+ assert_raise(TypeError) {
238
+ m1.poly_line([[DUMMY_OBJ, DUMMY_OBJ], [DUMMY_OBJ, DUMMY_OBJ]])
239
+ }
240
+ assert_raise(TypeError) {
241
+ m1.poly_line(pt, :color => DUMMY_OBJ)
242
+ }
243
+ # assert_raise(CvError) {
244
+ # m1.poly_line(pt, :thickness => DUMMY_OBJ)
245
+ # }
246
+ # m1.poly_line(pt, :line_type => DUMMY_OBJ)
247
+ end
248
+
249
+ def test_draw_contours
250
+ mat0 = CvMat.load(FILENAME_CONTOURS, CV_LOAD_IMAGE_GRAYSCALE)
251
+
252
+ mat0 = mat0.threshold(128, 255, CV_THRESH_BINARY)
253
+ contours = mat0.find_contours(:mode => CV_RETR_TREE, :method => CV_CHAIN_APPROX_SIMPLE)
254
+ dst0 = mat0.clone.clear
255
+ dst1 = mat0.clone.clear.GRAY2BGR
256
+ begin
257
+ dst0 = dst0.draw_contours!(contours, CvColor::Black, CvColor::White, -1)
258
+ dst1.draw_contours!(contours, CvColor::Red, CvColor::Blue, 2,
259
+ :thickness => -1, :line_type => :aa)
260
+ end while (contours = contours.h_next)
261
+
262
+ [dst0, dst1].each { |dst|
263
+ assert_equal(mat0.class, dst.class)
264
+ assert_equal(mat0.rows, dst.rows)
265
+ assert_equal(mat0.cols, dst.cols)
266
+ assert_equal(mat0.depth, dst.depth)
267
+ }
268
+
269
+ assert_raise(TypeError) {
270
+ dst0.draw_contours(DUMMY_OBJ, CvColor::Black, CvColor::White, -1)
271
+ }
272
+ assert_raise(TypeError) {
273
+ dst0.draw_contours(contours, DUMMY_OBJ, CvColor::White, -1)
274
+ }
275
+ assert_raise(TypeError) {
276
+ dst0.draw_contours(contours, CvColor::Black, DUMMY_OBJ, -1)
277
+ }
278
+ assert_raise(TypeError) {
279
+ dst0.draw_contours(contours, CvColor::Black, CvColor::White, DUMMY_OBJ)
280
+ }
281
+ assert_raise(TypeError) {
282
+ dst0.draw_contours(contours, CvColor::Black, CvColor::White, -1, :thickness => DUMMY_OBJ)
283
+ }
284
+ assert_raise(TypeError) {
285
+ dst0.draw_contours(contours, CvColor::Black, CvColor::White, -1, :line_type => DUMMY_OBJ)
286
+ }
287
+
288
+ # Uncomment the following line to show the results
289
+ # snap ['src', mat0], ['result0', dst0], ['result1', dst1]
290
+ end
291
+
292
+ def test_put_text
293
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
294
+ m1 = m0.clone
295
+ m1.put_text!('test 1', CvPoint.new(60, 90), CvFont.new(:simplex), CvColor::Blue)
296
+ font = CvFont.new(:plain, :hscale => 5.0, :vscale => 4.5,
297
+ :shear => 1.0, :thickness => 3, :line_type => 5, :italic => true)
298
+ m2 = m0.put_text('test 2', CvPoint.new(30, 80), font, CvColor::Red)
299
+
300
+ # Uncomment the following lines to view the image
301
+ # snap(['Put text: Blue, thickness = 1', m1], ['Put text: Red, thickness = 3', m2])
302
+
303
+ assert_raise(TypeError) {
304
+ m0.put_text(DUMMY_OBJ, CvPoint.new(60, 90), font)
305
+ }
306
+ assert_raise(TypeError) {
307
+ m0.put_text('test', DUMMY_OBJ, font)
308
+ }
309
+ assert_raise(TypeError) {
310
+ m0.put_text('test', CvPoint.new(60, 90), DUMMY_OBJ)
311
+ }
312
+ assert_raise(TypeError) {
313
+ m0.put_text('test', CvPoint.new(60, 90), font, DUMMY_OBJ)
314
+ }
315
+ end
316
+ end
317
+
318
+
@@ -0,0 +1,147 @@
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 dft and dct functions of OpenCV::CvMat
10
+ class TestCvMat_dxt < OpenCVTestCase
11
+ def test_dft_1D
12
+ n = 32
13
+ w = 2 * Math::PI / n
14
+
15
+ mat0 = create_cvmat(n, 1, :cv32f, 2) { |j, i, c|
16
+ s = Math.sin(c * w)
17
+ CvScalar.new(s, s)
18
+ }
19
+
20
+ mat1 = mat0.dft(:forward)
21
+ mat2 = mat0.dft(:forward, :scale)
22
+ mat3 = mat0.dft(:forward, :scale).dft(:inverse)
23
+ n.times { |j|
24
+ if j == 1
25
+ assert_in_delta(n / 2, mat1[j, 0][0], 0.001)
26
+ assert_in_delta(-n / 2, mat1[j, 0][1], 0.001)
27
+ assert_in_delta(0.5, mat2[j, 0][0], 0.001)
28
+ assert_in_delta(-0.5, mat2[j, 0][1], 0.001)
29
+ elsif j == n - 1
30
+ assert_in_delta(-n / 2, mat1[j, 0][0], 0.001)
31
+ assert_in_delta(n / 2, mat1[j, 0][1], 0.001)
32
+ assert_in_delta(-0.5, mat2[j, 0][0], 0.001)
33
+ assert_in_delta(0.5, mat2[j, 0][1], 0.001)
34
+ else
35
+ assert_in_delta(0, mat1[j, 0][0], 0.001)
36
+ assert_in_delta(0, mat1[j, 0][1], 0.001)
37
+ assert_in_delta(0, mat2[j, 0][0], 0.001)
38
+ assert_in_delta(0, mat2[j, 0][1], 0.001)
39
+ end
40
+ assert_in_delta(mat0[j, 0][0], mat3[j, 0][0], 0.001)
41
+ assert_in_delta(mat0[j, 0][1], mat3[j, 0][1], 0.001)
42
+ }
43
+
44
+ assert_raise(TypeError) {
45
+ mat0.dft(DUMMY_OBJ)
46
+ }
47
+ end
48
+
49
+ def test_dft_2D
50
+ n = 32
51
+ w = 2 * Math::PI / n
52
+ c = 0
53
+ mat0 = CvMat.new(n, n, :cv32f, 2)
54
+ n.times { |j|
55
+ s = Math.sin(c * w)
56
+ n.times { |i|
57
+ mat0[j, i] = CvScalar.new(s, s)
58
+ }
59
+ c += 1
60
+ }
61
+
62
+ mat1 = mat0.dft(:forward)
63
+ mat2 = mat0.dft(:forward, :scale)
64
+ mat3 = mat0.dft(:forward, :scale).dft(:inverse)
65
+ n.times { |j|
66
+ n.times { |i|
67
+ if i == 0 and j == 1
68
+ assert_in_delta(n * n / 2, mat1[j, i][0], 0.001)
69
+ assert_in_delta(-n * n / 2, mat1[j, i][1], 0.001)
70
+ assert_in_delta(0.5, mat2[j, i][0], 0.001)
71
+ assert_in_delta(-0.5, mat2[j, i][1], 0.001)
72
+ elsif i == 0 and j == n - 1
73
+ assert_in_delta(-n * n / 2, mat1[j, i][0], 0.001)
74
+ assert_in_delta(n * n / 2, mat1[j, i][1], 0.001)
75
+ assert_in_delta(-0.5, mat2[j, i][0], 0.001)
76
+ assert_in_delta(0.5, mat2[j, i][1], 0.001)
77
+ else
78
+ assert_in_delta(0, mat1[j, i][0], 0.001)
79
+ assert_in_delta(0, mat1[j, i][1], 0.001)
80
+ assert_in_delta(0, mat2[j, i][0], 0.001)
81
+ assert_in_delta(0, mat2[j, i][1], 0.001)
82
+ end
83
+ assert_in_delta(mat0[j, 0][0], mat3[j, i][0], 0.001)
84
+ assert_in_delta(mat0[j, 0][1], mat3[j, i][1], 0.001)
85
+ }
86
+ }
87
+ end
88
+
89
+ def test_dct_1D
90
+ n = 8
91
+ w = 2 * Math::PI / n
92
+
93
+ mat0 = create_cvmat(n, 1, :cv32f, 1) { |j, i, c|
94
+ s = Math.sin(c * w)
95
+ CvScalar.new(s)
96
+ }
97
+
98
+ mat1 = mat0.dct
99
+ mat2 = mat0.dct(:forward).dct(:inverse)
100
+ expected1 = [0, 1.599647, -0.765367, -0.906127, 0, -0.180240, 0, -0.042290]
101
+ n.times { |j|
102
+ assert_in_delta(expected1[j], mat1[j, 0][0], 0.001)
103
+ assert_in_delta(mat0[j, 0][0], mat2[j, 0][0], 0.001)
104
+ }
105
+
106
+ assert_raise(TypeError) {
107
+ mat0.dct(DUMMY_OBJ)
108
+ }
109
+ end
110
+
111
+ def test_dct_2D
112
+ n = 8
113
+ w = 2 * Math::PI / n
114
+ c = 0
115
+ mat0 = CvMat.new(n, n, :cv32f, 1)
116
+ n.times { |j|
117
+ s = Math.sin(c * w)
118
+ n.times { |i|
119
+ mat0[j, i] = CvScalar.new(s, s)
120
+ }
121
+ c += 1
122
+ }
123
+
124
+ mat1 = mat0.dct(:forward)
125
+ mat2 = mat0.dct(:forward).dct(:inverse)
126
+ n.times { |j|
127
+ n.times { |i|
128
+ if i == 0 and j == 1
129
+ assert_in_delta(4.524486, mat1[j, i][0], 0.001)
130
+ elsif i == 0 and j == 2
131
+ assert_in_delta(-2.164784, mat1[j, i][0], 0.001)
132
+ elsif i == 0 and j == 3
133
+ assert_in_delta(-2.562915, mat1[j, i][0], 0.001)
134
+ elsif i == 0 and j == 5
135
+ assert_in_delta(-0.509796, mat1[j, i][0], 0.001)
136
+ elsif i == 0 and j == 7
137
+ assert_in_delta(-0.119615, mat1[j, i][0], 0.001)
138
+ else
139
+ assert_in_delta(0, mat1[j, i][0], 0.001)
140
+ end
141
+ assert_in_delta(mat0[j, i][0], mat2[j, i][0], 0.001)
142
+ }
143
+ }
144
+ end
145
+ end
146
+
147
+