ruby-opencv 0.0.8-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. data/.gitignore +25 -0
  2. data/DEVELOPERS_NOTE.md +120 -0
  3. data/Gemfile +9 -0
  4. data/History.txt +5 -0
  5. data/License.txt +30 -0
  6. data/Manifest.txt +226 -0
  7. data/README.md +98 -0
  8. data/Rakefile +32 -0
  9. data/examples/alpha_blend.rb +21 -0
  10. data/examples/box.png +0 -0
  11. data/examples/box_in_scene.png +0 -0
  12. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  13. data/examples/contours/bitmap-contours.png +0 -0
  14. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  15. data/examples/contours/contour_retrieval_modes.rb +139 -0
  16. data/examples/contours/rotated-boxes.jpg +0 -0
  17. data/examples/convexhull.rb +47 -0
  18. data/examples/face_detect.rb +20 -0
  19. data/examples/find_obj.rb +169 -0
  20. data/examples/houghcircle.rb +22 -0
  21. data/examples/inpaint.png +0 -0
  22. data/examples/inpaint.rb +57 -0
  23. data/examples/lenna-rotated.jpg +0 -0
  24. data/examples/lenna.jpg +0 -0
  25. data/examples/match_kdtree.rb +88 -0
  26. data/examples/matching_to_many_images.rb +16 -0
  27. data/examples/matching_to_many_images/query.png +0 -0
  28. data/examples/matching_to_many_images/train/1.png +0 -0
  29. data/examples/matching_to_many_images/train/2.png +0 -0
  30. data/examples/matching_to_many_images/train/3.png +0 -0
  31. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  32. data/examples/paint.rb +70 -0
  33. data/examples/snake.rb +43 -0
  34. data/examples/stuff.jpg +0 -0
  35. data/examples/tiffany.jpg +0 -0
  36. data/ext/opencv/curve.cpp +112 -0
  37. data/ext/opencv/curve.h +34 -0
  38. data/ext/opencv/cvavgcomp.cpp +67 -0
  39. data/ext/opencv/cvavgcomp.h +39 -0
  40. data/ext/opencv/cvbox2d.cpp +197 -0
  41. data/ext/opencv/cvbox2d.h +61 -0
  42. data/ext/opencv/cvcapture.cpp +499 -0
  43. data/ext/opencv/cvcapture.h +72 -0
  44. data/ext/opencv/cvchain.cpp +233 -0
  45. data/ext/opencv/cvchain.h +46 -0
  46. data/ext/opencv/cvcircle32f.cpp +116 -0
  47. data/ext/opencv/cvcircle32f.h +52 -0
  48. data/ext/opencv/cvcondensation.cpp +282 -0
  49. data/ext/opencv/cvcondensation.h +49 -0
  50. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  51. data/ext/opencv/cvconnectedcomp.h +49 -0
  52. data/ext/opencv/cvcontour.cpp +296 -0
  53. data/ext/opencv/cvcontour.h +48 -0
  54. data/ext/opencv/cvcontourtree.cpp +91 -0
  55. data/ext/opencv/cvcontourtree.h +41 -0
  56. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  57. data/ext/opencv/cvconvexitydefect.h +42 -0
  58. data/ext/opencv/cverror.cpp +159 -0
  59. data/ext/opencv/cverror.h +28 -0
  60. data/ext/opencv/cvfeaturetree.cpp +125 -0
  61. data/ext/opencv/cvfeaturetree.h +55 -0
  62. data/ext/opencv/cvfont.cpp +208 -0
  63. data/ext/opencv/cvfont.h +64 -0
  64. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  65. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  66. data/ext/opencv/cvhistogram.cpp +546 -0
  67. data/ext/opencv/cvhistogram.h +73 -0
  68. data/ext/opencv/cvhumoments.cpp +139 -0
  69. data/ext/opencv/cvhumoments.h +51 -0
  70. data/ext/opencv/cvline.cpp +154 -0
  71. data/ext/opencv/cvline.h +54 -0
  72. data/ext/opencv/cvmat.cpp +5848 -0
  73. data/ext/opencv/cvmat.h +284 -0
  74. data/ext/opencv/cvmatnd.cpp +44 -0
  75. data/ext/opencv/cvmatnd.h +28 -0
  76. data/ext/opencv/cvmemstorage.cpp +68 -0
  77. data/ext/opencv/cvmemstorage.h +53 -0
  78. data/ext/opencv/cvmoments.cpp +287 -0
  79. data/ext/opencv/cvmoments.h +75 -0
  80. data/ext/opencv/cvpoint.cpp +228 -0
  81. data/ext/opencv/cvpoint.h +64 -0
  82. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  83. data/ext/opencv/cvpoint2d32f.h +63 -0
  84. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  85. data/ext/opencv/cvpoint3d32f.h +66 -0
  86. data/ext/opencv/cvrect.cpp +333 -0
  87. data/ext/opencv/cvrect.h +79 -0
  88. data/ext/opencv/cvscalar.cpp +236 -0
  89. data/ext/opencv/cvscalar.h +71 -0
  90. data/ext/opencv/cvseq.cpp +599 -0
  91. data/ext/opencv/cvseq.h +74 -0
  92. data/ext/opencv/cvsize.cpp +221 -0
  93. data/ext/opencv/cvsize.h +65 -0
  94. data/ext/opencv/cvsize2d32f.cpp +209 -0
  95. data/ext/opencv/cvsize2d32f.h +64 -0
  96. data/ext/opencv/cvslice.cpp +120 -0
  97. data/ext/opencv/cvslice.h +61 -0
  98. data/ext/opencv/cvsparsemat.cpp +44 -0
  99. data/ext/opencv/cvsparsemat.h +28 -0
  100. data/ext/opencv/cvsurfparams.cpp +199 -0
  101. data/ext/opencv/cvsurfparams.h +58 -0
  102. data/ext/opencv/cvsurfpoint.cpp +223 -0
  103. data/ext/opencv/cvsurfpoint.h +52 -0
  104. data/ext/opencv/cvtermcriteria.cpp +192 -0
  105. data/ext/opencv/cvtermcriteria.h +71 -0
  106. data/ext/opencv/cvtwopoints.cpp +116 -0
  107. data/ext/opencv/cvtwopoints.h +51 -0
  108. data/ext/opencv/cvutils.cpp +194 -0
  109. data/ext/opencv/cvutils.h +29 -0
  110. data/ext/opencv/cvvideowriter.cpp +137 -0
  111. data/ext/opencv/cvvideowriter.h +43 -0
  112. data/ext/opencv/gui.cpp +68 -0
  113. data/ext/opencv/gui.h +30 -0
  114. data/ext/opencv/iplconvkernel.cpp +192 -0
  115. data/ext/opencv/iplconvkernel.h +71 -0
  116. data/ext/opencv/iplimage.cpp +644 -0
  117. data/ext/opencv/iplimage.h +73 -0
  118. data/ext/opencv/lib/opencv.rb +3 -0
  119. data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
  120. data/ext/opencv/lib/opencv/version.rb +3 -0
  121. data/ext/opencv/mouseevent.cpp +181 -0
  122. data/ext/opencv/mouseevent.h +56 -0
  123. data/ext/opencv/opencv.cpp +722 -0
  124. data/ext/opencv/opencv.h +400 -0
  125. data/ext/opencv/pointset.cpp +274 -0
  126. data/ext/opencv/pointset.h +68 -0
  127. data/ext/opencv/trackbar.cpp +121 -0
  128. data/ext/opencv/trackbar.h +69 -0
  129. data/ext/opencv/window.cpp +357 -0
  130. data/ext/opencv/window.h +66 -0
  131. data/extconf.rb +75 -0
  132. data/images/CvMat_sobel.png +0 -0
  133. data/images/CvMat_sub_rect.png +0 -0
  134. data/images/CvSeq_relationmap.png +0 -0
  135. data/images/face_detect_from_lena.jpg +0 -0
  136. data/lib/opencv.rb +3 -0
  137. data/lib/opencv/psyched_yaml.rb +22 -0
  138. data/lib/opencv/version.rb +3 -0
  139. data/ruby-opencv.gemspec +43 -0
  140. data/test/helper.rb +166 -0
  141. data/test/runner.rb +30 -0
  142. data/test/samples/airplane.jpg +0 -0
  143. data/test/samples/baboon.jpg +0 -0
  144. data/test/samples/baboon200.jpg +0 -0
  145. data/test/samples/baboon200_rotated.jpg +0 -0
  146. data/test/samples/blank0.jpg +0 -0
  147. data/test/samples/blank1.jpg +0 -0
  148. data/test/samples/blank2.jpg +0 -0
  149. data/test/samples/blank3.jpg +0 -0
  150. data/test/samples/blank4.jpg +0 -0
  151. data/test/samples/blank5.jpg +0 -0
  152. data/test/samples/blank6.jpg +0 -0
  153. data/test/samples/blank7.jpg +0 -0
  154. data/test/samples/blank8.jpg +0 -0
  155. data/test/samples/blank9.jpg +0 -0
  156. data/test/samples/cat.jpg +0 -0
  157. data/test/samples/chessboard.jpg +0 -0
  158. data/test/samples/contours.jpg +0 -0
  159. data/test/samples/fruits.jpg +0 -0
  160. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  161. data/test/samples/inpaint-mask.bmp +0 -0
  162. data/test/samples/lena-256x256.jpg +0 -0
  163. data/test/samples/lena-32x32.jpg +0 -0
  164. data/test/samples/lena-eyes.jpg +0 -0
  165. data/test/samples/lena-inpaint.jpg +0 -0
  166. data/test/samples/lena.jpg +0 -0
  167. data/test/samples/lines.jpg +0 -0
  168. data/test/samples/messy0.jpg +0 -0
  169. data/test/samples/messy1.jpg +0 -0
  170. data/test/samples/movie_sample.avi +0 -0
  171. data/test/samples/one_way_train_0000.jpg +0 -0
  172. data/test/samples/one_way_train_0001.jpg +0 -0
  173. data/test/samples/partially_blank0.jpg +0 -0
  174. data/test/samples/partially_blank1.jpg +0 -0
  175. data/test/samples/smooth0.jpg +0 -0
  176. data/test/samples/smooth1.jpg +0 -0
  177. data/test/samples/smooth2.jpg +0 -0
  178. data/test/samples/smooth3.jpg +0 -0
  179. data/test/samples/smooth4.jpg +0 -0
  180. data/test/samples/smooth5.jpg +0 -0
  181. data/test/samples/smooth6.jpg +0 -0
  182. data/test/samples/str-cv-rotated.jpg +0 -0
  183. data/test/samples/str-cv.jpg +0 -0
  184. data/test/samples/str-ov.jpg +0 -0
  185. data/test/samples/stuff.jpg +0 -0
  186. data/test/test_curve.rb +43 -0
  187. data/test/test_cvavgcomp.rb +24 -0
  188. data/test/test_cvbox2d.rb +76 -0
  189. data/test/test_cvcapture.rb +183 -0
  190. data/test/test_cvchain.rb +108 -0
  191. data/test/test_cvcircle32f.rb +41 -0
  192. data/test/test_cvconnectedcomp.rb +61 -0
  193. data/test/test_cvcontour.rb +150 -0
  194. data/test/test_cvcontourtree.rb +43 -0
  195. data/test/test_cverror.rb +50 -0
  196. data/test/test_cvfeaturetree.rb +65 -0
  197. data/test/test_cvfont.rb +58 -0
  198. data/test/test_cvhaarclassifiercascade.rb +63 -0
  199. data/test/test_cvhistogram.rb +271 -0
  200. data/test/test_cvhumoments.rb +83 -0
  201. data/test/test_cvline.rb +50 -0
  202. data/test/test_cvmat.rb +2947 -0
  203. data/test/test_cvmat_drawing.rb +349 -0
  204. data/test/test_cvmat_dxt.rb +150 -0
  205. data/test/test_cvmat_imageprocessing.rb +2025 -0
  206. data/test/test_cvmat_matching.rb +57 -0
  207. data/test/test_cvmoments.rb +180 -0
  208. data/test/test_cvpoint.rb +75 -0
  209. data/test/test_cvpoint2d32f.rb +75 -0
  210. data/test/test_cvpoint3d32f.rb +93 -0
  211. data/test/test_cvrect.rb +144 -0
  212. data/test/test_cvscalar.rb +113 -0
  213. data/test/test_cvseq.rb +295 -0
  214. data/test/test_cvsize.rb +75 -0
  215. data/test/test_cvsize2d32f.rb +75 -0
  216. data/test/test_cvslice.rb +31 -0
  217. data/test/test_cvsurfparams.rb +57 -0
  218. data/test/test_cvsurfpoint.rb +66 -0
  219. data/test/test_cvtermcriteria.rb +56 -0
  220. data/test/test_cvtwopoints.rb +40 -0
  221. data/test/test_cvvideowriter.rb +58 -0
  222. data/test/test_iplconvkernel.rb +54 -0
  223. data/test/test_iplimage.rb +236 -0
  224. data/test/test_mouseevent.rb +17 -0
  225. data/test/test_opencv.rb +324 -0
  226. data/test/test_pointset.rb +126 -0
  227. data/test/test_preliminary.rb +130 -0
  228. data/test/test_trackbar.rb +47 -0
  229. data/test/test_window.rb +115 -0
  230. metadata +414 -0
@@ -0,0 +1,349 @@
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_draw_chessboard_corners
293
+ mat0 = CvMat.load(FILENAME_CHESSBOARD, 1)
294
+ mat1 = mat0.clone
295
+ pattern_size = CvSize.new(4, 4)
296
+
297
+ gray = mat1.BGR2GRAY
298
+ corners, found = gray.find_chessboard_corners(pattern_size)
299
+
300
+ mat2 = mat1.draw_chessboard_corners(pattern_size, corners, found)
301
+ mat1.draw_chessboard_corners!(pattern_size, corners, found)
302
+ [mat1, mat2].each { |dst|
303
+ assert_equal(mat0.class, dst.class)
304
+ assert_equal(mat0.rows, dst.rows)
305
+ assert_equal(mat0.cols, dst.cols)
306
+ assert_equal(mat0.depth, dst.depth)
307
+ }
308
+
309
+ assert_raise(TypeError) {
310
+ mat1.draw_chessboard_corners(DUMMY_OBJ, corners, found)
311
+ }
312
+ assert_raise(TypeError) {
313
+ mat1.draw_chessboard_corners(pattern_size, DUMMY_OBJ, found)
314
+ }
315
+ assert_nothing_raised {
316
+ mat1.draw_chessboard_corners(pattern_size, corners, DUMMY_OBJ)
317
+ }
318
+
319
+ # Uncomment the following line to show the results
320
+ # snap mat0, mat1, mat2
321
+ end
322
+
323
+ def test_put_text
324
+ m0 = create_cvmat(240, 320, :cv8u, 3) { CvColor::White }
325
+ m1 = m0.clone
326
+ m1.put_text!('test 1', CvPoint.new(60, 90), CvFont.new(:simplex), CvColor::Blue)
327
+ font = CvFont.new(:plain, :hscale => 5.0, :vscale => 4.5,
328
+ :shear => 1.0, :thickness => 3, :line_type => 5, :italic => true)
329
+ m2 = m0.put_text('test 2', CvPoint.new(30, 80), font, CvColor::Red)
330
+
331
+ # Uncomment the following lines to view the image
332
+ # snap(['Put text: Blue, thickness = 1', m1], ['Put text: Red, thickness = 3', m2])
333
+
334
+ assert_raise(TypeError) {
335
+ m0.put_text(DUMMY_OBJ, CvPoint.new(60, 90), font)
336
+ }
337
+ assert_raise(TypeError) {
338
+ m0.put_text('test', DUMMY_OBJ, font)
339
+ }
340
+ assert_raise(TypeError) {
341
+ m0.put_text('test', CvPoint.new(60, 90), DUMMY_OBJ)
342
+ }
343
+ assert_raise(TypeError) {
344
+ m0.put_text('test', CvPoint.new(60, 90), font, DUMMY_OBJ)
345
+ }
346
+ end
347
+ end
348
+
349
+
@@ -0,0 +1,150 @@
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(CV_DXT_FORWARD)
21
+ mat2 = mat0.dft(CV_DXT_FORWARD | CV_DXT_SCALE)
22
+ mat3 = mat0.dft(CV_DXT_FORWARD | CV_DXT_SCALE).dft(CV_DXT_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
+ assert_raise(TypeError) {
48
+ mat0.dft(CV_DXT_FORWARD, DUMMY_OBJ)
49
+ }
50
+ end
51
+
52
+ def test_dft_2D
53
+ n = 32
54
+ w = 2 * Math::PI / n
55
+ c = 0
56
+ mat0 = CvMat.new(n, n, :cv32f, 2)
57
+ n.times { |j|
58
+ s = Math.sin(c * w)
59
+ n.times { |i|
60
+ mat0[j, i] = CvScalar.new(s, s)
61
+ }
62
+ c += 1
63
+ }
64
+
65
+ mat1 = mat0.dft(CV_DXT_FORWARD)
66
+ mat2 = mat0.dft(CV_DXT_FORWARD | CV_DXT_SCALE)
67
+ mat3 = mat0.dft(CV_DXT_FORWARD | CV_DXT_SCALE).dft(CV_DXT_INVERSE)
68
+ n.times { |j|
69
+ n.times { |i|
70
+ if i == 0 and j == 1
71
+ assert_in_delta(n * n / 2, mat1[j, i][0], 0.001)
72
+ assert_in_delta(-n * n / 2, mat1[j, i][1], 0.001)
73
+ assert_in_delta(0.5, mat2[j, i][0], 0.001)
74
+ assert_in_delta(-0.5, mat2[j, i][1], 0.001)
75
+ elsif i == 0 and j == n - 1
76
+ assert_in_delta(-n * n / 2, mat1[j, i][0], 0.001)
77
+ assert_in_delta(n * n / 2, mat1[j, i][1], 0.001)
78
+ assert_in_delta(-0.5, mat2[j, i][0], 0.001)
79
+ assert_in_delta(0.5, mat2[j, i][1], 0.001)
80
+ else
81
+ assert_in_delta(0, mat1[j, i][0], 0.001)
82
+ assert_in_delta(0, mat1[j, i][1], 0.001)
83
+ assert_in_delta(0, mat2[j, i][0], 0.001)
84
+ assert_in_delta(0, mat2[j, i][1], 0.001)
85
+ end
86
+ assert_in_delta(mat0[j, 0][0], mat3[j, i][0], 0.001)
87
+ assert_in_delta(mat0[j, 0][1], mat3[j, i][1], 0.001)
88
+ }
89
+ }
90
+ end
91
+
92
+ def test_dct_1D
93
+ n = 8
94
+ w = 2 * Math::PI / n
95
+
96
+ mat0 = create_cvmat(n, 1, :cv32f, 1) { |j, i, c|
97
+ s = Math.sin(c * w)
98
+ CvScalar.new(s)
99
+ }
100
+
101
+ mat1 = mat0.dct(CV_DXT_FORWARD)
102
+ mat2 = mat0.dct(CV_DXT_FORWARD).dct(CV_DXT_INVERSE)
103
+ expected1 = [0, 1.599647, -0.765367, -0.906127, 0, -0.180240, 0, -0.042290]
104
+ n.times { |j|
105
+ assert_in_delta(expected1[j], mat1[j, 0][0], 0.001)
106
+ assert_in_delta(mat0[j, 0][0], mat2[j, 0][0], 0.001)
107
+ }
108
+
109
+ assert_raise(TypeError) {
110
+ mat0.dct(DUMMY_OBJ)
111
+ }
112
+ end
113
+
114
+ def test_dct_2D
115
+ n = 8
116
+ w = 2 * Math::PI / n
117
+ c = 0
118
+ mat0 = CvMat.new(n, n, :cv32f, 1)
119
+ n.times { |j|
120
+ s = Math.sin(c * w)
121
+ n.times { |i|
122
+ mat0[j, i] = CvScalar.new(s, s)
123
+ }
124
+ c += 1
125
+ }
126
+
127
+ mat1 = mat0.dct(CV_DXT_FORWARD)
128
+ mat2 = mat0.dct(CV_DXT_FORWARD).dct(CV_DXT_INVERSE)
129
+ n.times { |j|
130
+ n.times { |i|
131
+ if i == 0 and j == 1
132
+ assert_in_delta(4.524486, mat1[j, i][0], 0.001)
133
+ elsif i == 0 and j == 2
134
+ assert_in_delta(-2.164784, mat1[j, i][0], 0.001)
135
+ elsif i == 0 and j == 3
136
+ assert_in_delta(-2.562915, mat1[j, i][0], 0.001)
137
+ elsif i == 0 and j == 5
138
+ assert_in_delta(-0.509796, mat1[j, i][0], 0.001)
139
+ elsif i == 0 and j == 7
140
+ assert_in_delta(-0.119615, mat1[j, i][0], 0.001)
141
+ else
142
+ assert_in_delta(0, mat1[j, i][0], 0.001)
143
+ end
144
+ assert_in_delta(mat0[j, i][0], mat2[j, i][0], 0.001)
145
+ }
146
+ }
147
+ end
148
+ end
149
+
150
+