ruby-opencv 0.0.9-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/DEVELOPERS_NOTE.md +137 -0
  4. data/Gemfile +8 -0
  5. data/History.txt +5 -0
  6. data/License.txt +30 -0
  7. data/Manifest.txt +227 -0
  8. data/README.md +98 -0
  9. data/Rakefile +90 -0
  10. data/config.yml +7 -0
  11. data/examples/alpha_blend.rb +21 -0
  12. data/examples/box.png +0 -0
  13. data/examples/box_in_scene.png +0 -0
  14. data/examples/contours/bitmap-contours-with-labels.png +0 -0
  15. data/examples/contours/bitmap-contours.png +0 -0
  16. data/examples/contours/bounding-box-detect-canny.rb +62 -0
  17. data/examples/contours/contour_retrieval_modes.rb +139 -0
  18. data/examples/contours/rotated-boxes.jpg +0 -0
  19. data/examples/convexhull.rb +47 -0
  20. data/examples/face_detect.rb +20 -0
  21. data/examples/find_obj.rb +169 -0
  22. data/examples/houghcircle.rb +22 -0
  23. data/examples/inpaint.png +0 -0
  24. data/examples/inpaint.rb +57 -0
  25. data/examples/lenna-rotated.jpg +0 -0
  26. data/examples/lenna.jpg +0 -0
  27. data/examples/match_kdtree.rb +88 -0
  28. data/examples/matching_to_many_images.rb +16 -0
  29. data/examples/matching_to_many_images/query.png +0 -0
  30. data/examples/matching_to_many_images/train/1.png +0 -0
  31. data/examples/matching_to_many_images/train/2.png +0 -0
  32. data/examples/matching_to_many_images/train/3.png +0 -0
  33. data/examples/matching_to_many_images/train/trainImages.txt +3 -0
  34. data/examples/paint.rb +70 -0
  35. data/examples/snake.rb +43 -0
  36. data/examples/stuff.jpg +0 -0
  37. data/examples/tiffany.jpg +0 -0
  38. data/ext/opencv/curve.cpp +112 -0
  39. data/ext/opencv/curve.h +34 -0
  40. data/ext/opencv/cvavgcomp.cpp +67 -0
  41. data/ext/opencv/cvavgcomp.h +39 -0
  42. data/ext/opencv/cvbox2d.cpp +197 -0
  43. data/ext/opencv/cvbox2d.h +61 -0
  44. data/ext/opencv/cvcapture.cpp +506 -0
  45. data/ext/opencv/cvcapture.h +72 -0
  46. data/ext/opencv/cvchain.cpp +233 -0
  47. data/ext/opencv/cvchain.h +46 -0
  48. data/ext/opencv/cvcircle32f.cpp +116 -0
  49. data/ext/opencv/cvcircle32f.h +52 -0
  50. data/ext/opencv/cvcondensation.cpp +282 -0
  51. data/ext/opencv/cvcondensation.h +49 -0
  52. data/ext/opencv/cvconnectedcomp.cpp +143 -0
  53. data/ext/opencv/cvconnectedcomp.h +49 -0
  54. data/ext/opencv/cvcontour.cpp +296 -0
  55. data/ext/opencv/cvcontour.h +48 -0
  56. data/ext/opencv/cvcontourtree.cpp +91 -0
  57. data/ext/opencv/cvcontourtree.h +41 -0
  58. data/ext/opencv/cvconvexitydefect.cpp +103 -0
  59. data/ext/opencv/cvconvexitydefect.h +42 -0
  60. data/ext/opencv/cverror.cpp +159 -0
  61. data/ext/opencv/cverror.h +28 -0
  62. data/ext/opencv/cvfeaturetree.cpp +125 -0
  63. data/ext/opencv/cvfeaturetree.h +55 -0
  64. data/ext/opencv/cvfont.cpp +208 -0
  65. data/ext/opencv/cvfont.h +64 -0
  66. data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
  67. data/ext/opencv/cvhaarclassifiercascade.h +39 -0
  68. data/ext/opencv/cvhistogram.cpp +546 -0
  69. data/ext/opencv/cvhistogram.h +73 -0
  70. data/ext/opencv/cvhumoments.cpp +139 -0
  71. data/ext/opencv/cvhumoments.h +51 -0
  72. data/ext/opencv/cvline.cpp +154 -0
  73. data/ext/opencv/cvline.h +54 -0
  74. data/ext/opencv/cvmat.cpp +5848 -0
  75. data/ext/opencv/cvmat.h +284 -0
  76. data/ext/opencv/cvmatnd.cpp +44 -0
  77. data/ext/opencv/cvmatnd.h +28 -0
  78. data/ext/opencv/cvmemstorage.cpp +68 -0
  79. data/ext/opencv/cvmemstorage.h +53 -0
  80. data/ext/opencv/cvmoments.cpp +287 -0
  81. data/ext/opencv/cvmoments.h +75 -0
  82. data/ext/opencv/cvpoint.cpp +228 -0
  83. data/ext/opencv/cvpoint.h +64 -0
  84. data/ext/opencv/cvpoint2d32f.cpp +211 -0
  85. data/ext/opencv/cvpoint2d32f.h +63 -0
  86. data/ext/opencv/cvpoint3d32f.cpp +245 -0
  87. data/ext/opencv/cvpoint3d32f.h +66 -0
  88. data/ext/opencv/cvrect.cpp +333 -0
  89. data/ext/opencv/cvrect.h +79 -0
  90. data/ext/opencv/cvscalar.cpp +236 -0
  91. data/ext/opencv/cvscalar.h +71 -0
  92. data/ext/opencv/cvseq.cpp +599 -0
  93. data/ext/opencv/cvseq.h +74 -0
  94. data/ext/opencv/cvsize.cpp +221 -0
  95. data/ext/opencv/cvsize.h +65 -0
  96. data/ext/opencv/cvsize2d32f.cpp +209 -0
  97. data/ext/opencv/cvsize2d32f.h +64 -0
  98. data/ext/opencv/cvslice.cpp +120 -0
  99. data/ext/opencv/cvslice.h +61 -0
  100. data/ext/opencv/cvsparsemat.cpp +44 -0
  101. data/ext/opencv/cvsparsemat.h +28 -0
  102. data/ext/opencv/cvsurfparams.cpp +199 -0
  103. data/ext/opencv/cvsurfparams.h +58 -0
  104. data/ext/opencv/cvsurfpoint.cpp +223 -0
  105. data/ext/opencv/cvsurfpoint.h +52 -0
  106. data/ext/opencv/cvtermcriteria.cpp +192 -0
  107. data/ext/opencv/cvtermcriteria.h +71 -0
  108. data/ext/opencv/cvtwopoints.cpp +116 -0
  109. data/ext/opencv/cvtwopoints.h +51 -0
  110. data/ext/opencv/cvutils.cpp +192 -0
  111. data/ext/opencv/cvutils.h +30 -0
  112. data/ext/opencv/cvvideowriter.cpp +137 -0
  113. data/ext/opencv/cvvideowriter.h +43 -0
  114. data/ext/opencv/extconf.rb +83 -0
  115. data/ext/opencv/gui.cpp +68 -0
  116. data/ext/opencv/gui.h +30 -0
  117. data/ext/opencv/iplconvkernel.cpp +192 -0
  118. data/ext/opencv/iplconvkernel.h +71 -0
  119. data/ext/opencv/iplimage.cpp +644 -0
  120. data/ext/opencv/iplimage.h +73 -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/images/CvMat_sobel.png +0 -0
  132. data/images/CvMat_sub_rect.png +0 -0
  133. data/images/CvSeq_relationmap.png +0 -0
  134. data/images/face_detect_from_lena.jpg +0 -0
  135. data/lib/opencv.rb +12 -0
  136. data/lib/opencv/psyched_yaml.rb +22 -0
  137. data/lib/opencv/version.rb +3 -0
  138. data/ruby-opencv.gemspec +44 -0
  139. data/test/helper.rb +166 -0
  140. data/test/runner.rb +30 -0
  141. data/test/samples/airplane.jpg +0 -0
  142. data/test/samples/baboon.jpg +0 -0
  143. data/test/samples/baboon200.jpg +0 -0
  144. data/test/samples/baboon200_rotated.jpg +0 -0
  145. data/test/samples/blank0.jpg +0 -0
  146. data/test/samples/blank1.jpg +0 -0
  147. data/test/samples/blank2.jpg +0 -0
  148. data/test/samples/blank3.jpg +0 -0
  149. data/test/samples/blank4.jpg +0 -0
  150. data/test/samples/blank5.jpg +0 -0
  151. data/test/samples/blank6.jpg +0 -0
  152. data/test/samples/blank7.jpg +0 -0
  153. data/test/samples/blank8.jpg +0 -0
  154. data/test/samples/blank9.jpg +0 -0
  155. data/test/samples/cat.jpg +0 -0
  156. data/test/samples/chessboard.jpg +0 -0
  157. data/test/samples/contours.jpg +0 -0
  158. data/test/samples/fruits.jpg +0 -0
  159. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  160. data/test/samples/inpaint-mask.bmp +0 -0
  161. data/test/samples/lena-256x256.jpg +0 -0
  162. data/test/samples/lena-32x32.jpg +0 -0
  163. data/test/samples/lena-eyes.jpg +0 -0
  164. data/test/samples/lena-inpaint.jpg +0 -0
  165. data/test/samples/lena.jpg +0 -0
  166. data/test/samples/lines.jpg +0 -0
  167. data/test/samples/messy0.jpg +0 -0
  168. data/test/samples/messy1.jpg +0 -0
  169. data/test/samples/movie_sample.avi +0 -0
  170. data/test/samples/one_way_train_0000.jpg +0 -0
  171. data/test/samples/one_way_train_0001.jpg +0 -0
  172. data/test/samples/partially_blank0.jpg +0 -0
  173. data/test/samples/partially_blank1.jpg +0 -0
  174. data/test/samples/smooth0.jpg +0 -0
  175. data/test/samples/smooth1.jpg +0 -0
  176. data/test/samples/smooth2.jpg +0 -0
  177. data/test/samples/smooth3.jpg +0 -0
  178. data/test/samples/smooth4.jpg +0 -0
  179. data/test/samples/smooth5.jpg +0 -0
  180. data/test/samples/smooth6.jpg +0 -0
  181. data/test/samples/str-cv-rotated.jpg +0 -0
  182. data/test/samples/str-cv.jpg +0 -0
  183. data/test/samples/str-ov.jpg +0 -0
  184. data/test/samples/stuff.jpg +0 -0
  185. data/test/test_curve.rb +43 -0
  186. data/test/test_cvavgcomp.rb +24 -0
  187. data/test/test_cvbox2d.rb +76 -0
  188. data/test/test_cvcapture.rb +183 -0
  189. data/test/test_cvchain.rb +108 -0
  190. data/test/test_cvcircle32f.rb +41 -0
  191. data/test/test_cvconnectedcomp.rb +61 -0
  192. data/test/test_cvcontour.rb +150 -0
  193. data/test/test_cvcontourtree.rb +43 -0
  194. data/test/test_cverror.rb +50 -0
  195. data/test/test_cvfeaturetree.rb +65 -0
  196. data/test/test_cvfont.rb +58 -0
  197. data/test/test_cvhaarclassifiercascade.rb +63 -0
  198. data/test/test_cvhistogram.rb +271 -0
  199. data/test/test_cvhumoments.rb +83 -0
  200. data/test/test_cvline.rb +50 -0
  201. data/test/test_cvmat.rb +2947 -0
  202. data/test/test_cvmat_drawing.rb +349 -0
  203. data/test/test_cvmat_dxt.rb +150 -0
  204. data/test/test_cvmat_imageprocessing.rb +2025 -0
  205. data/test/test_cvmat_matching.rb +57 -0
  206. data/test/test_cvmoments.rb +180 -0
  207. data/test/test_cvpoint.rb +75 -0
  208. data/test/test_cvpoint2d32f.rb +75 -0
  209. data/test/test_cvpoint3d32f.rb +93 -0
  210. data/test/test_cvrect.rb +144 -0
  211. data/test/test_cvscalar.rb +113 -0
  212. data/test/test_cvseq.rb +295 -0
  213. data/test/test_cvsize.rb +75 -0
  214. data/test/test_cvsize2d32f.rb +75 -0
  215. data/test/test_cvslice.rb +31 -0
  216. data/test/test_cvsurfparams.rb +57 -0
  217. data/test/test_cvsurfpoint.rb +66 -0
  218. data/test/test_cvtermcriteria.rb +56 -0
  219. data/test/test_cvtwopoints.rb +40 -0
  220. data/test/test_cvvideowriter.rb +58 -0
  221. data/test/test_iplconvkernel.rb +54 -0
  222. data/test/test_iplimage.rb +236 -0
  223. data/test/test_mouseevent.rb +17 -0
  224. data/test/test_opencv.rb +324 -0
  225. data/test/test_pointset.rb +126 -0
  226. data/test/test_preliminary.rb +130 -0
  227. data/test/test_trackbar.rb +47 -0
  228. data/test/test_window.rb +115 -0
  229. metadata +386 -0
@@ -0,0 +1,63 @@
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::CvHaarClassifierCascade
10
+ class TestCvHaarClassifierCascade < OpenCVTestCase
11
+ def setup
12
+ @cascade = CvHaarClassifierCascade.load(HAARCASCADE_FRONTALFACE_ALT)
13
+ end
14
+
15
+ def test_load
16
+ assert_equal(CvHaarClassifierCascade, @cascade.class)
17
+ assert_raise(ArgumentError) {
18
+ CvHaarClassifierCascade.load('not/exist.xml')
19
+ }
20
+ end
21
+
22
+ def test_detect_objects
23
+ img = CvMat.load(FILENAME_LENA256x256)
24
+
25
+ detected = @cascade.detect_objects(img)
26
+ assert_equal(CvSeq, detected.class)
27
+ assert_equal(1, detected.size)
28
+ assert_equal(CvAvgComp, detected[0].class)
29
+ assert_equal(106, detected[0].x)
30
+ assert_equal(100, detected[0].y)
31
+ assert_equal(89, detected[0].width)
32
+ assert_equal(89, detected[0].height)
33
+ assert_equal(48, detected[0].neighbors)
34
+
35
+ detected = @cascade.detect_objects(img) { |face|
36
+ assert_equal(106, face.x)
37
+ assert_equal(100, face.y)
38
+ assert_equal(89, face.width)
39
+ assert_equal(89, face.height)
40
+ assert_equal(48, face.neighbors)
41
+ }
42
+ assert_equal(CvSeq, detected.class)
43
+ assert_equal(1, detected.size)
44
+ assert_equal(CvAvgComp, detected[0].class)
45
+
46
+ detected = @cascade.detect_objects(img, :scale_factor => 2.0, :flags => CV_HAAR_DO_CANNY_PRUNING,
47
+ :min_neighbors => 5, :min_size => CvSize.new(10, 10),
48
+ :max_size => CvSize.new(100, 100))
49
+ assert_equal(CvSeq, detected.class)
50
+ assert_equal(1, detected.size)
51
+ assert_equal(CvAvgComp, detected[0].class)
52
+ assert_equal(109, detected[0].x)
53
+ assert_equal(102, detected[0].y)
54
+ assert_equal(80, detected[0].width)
55
+ assert_equal(80, detected[0].height)
56
+ assert_equal(7, detected[0].neighbors)
57
+
58
+ assert_raise(TypeError) {
59
+ @cascade.detect_objects('foo')
60
+ }
61
+ end
62
+ end
63
+
@@ -0,0 +1,271 @@
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::CvHistogram
10
+ class TestCvHistogram < OpenCVTestCase
11
+ def setup
12
+ @img = IplImage.load(FILENAME_LENA32x32, 0)
13
+
14
+ dim = 1
15
+ sizes = [8]
16
+ ranges = [[0, 255]]
17
+ @hist1 = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, ranges, true).calc_hist!([@img])
18
+
19
+ dim = 2
20
+ sizes = [8, 16]
21
+ ranges = [[0, 255], [0, 255]]
22
+ @hist2 = CvHistogram.new(dim, sizes, CV_HIST_SPARSE, ranges, true).calc_hist!([@img, @img])
23
+ end
24
+
25
+ def teardown
26
+ @hist1 = nil
27
+ @hist2 = nil
28
+ GC.start
29
+ end
30
+
31
+ def test_initialize
32
+ dim = 1
33
+ sizes = [256]
34
+ ranges = [[0, 256]]
35
+ hist1 = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, ranges, true)
36
+ hist2 = CvHistogram.new(dim, sizes, CV_HIST_ARRAY)
37
+ hist3 = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, nil)
38
+ hist4 = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, nil, false)
39
+ end
40
+
41
+ def test_is_uniform
42
+ assert(@hist1.is_uniform?)
43
+ assert(@hist2.is_uniform?)
44
+ end
45
+
46
+ def test_is_sparse
47
+ assert_false(@hist1.is_sparse?)
48
+ assert(@hist2.is_sparse?)
49
+ end
50
+
51
+ def test_has_range
52
+ assert(@hist1.has_range?)
53
+ assert(@hist2.has_range?)
54
+ end
55
+
56
+ def test_calc_hist
57
+ img = IplImage.new(1, 1, :cv8u, 1)
58
+ assert_equal(CvHistogram, @hist1.calc_hist([img]).class)
59
+ assert_equal(CvHistogram, @hist1.calc_hist([img, img]).class)
60
+ assert_equal(CvHistogram, @hist1.calc_hist([img], true).class)
61
+ assert_equal(CvHistogram, @hist1.calc_hist([img, img], false).class)
62
+ mask = CvMat.new(1, 1, :cv8u, 1)
63
+ assert_equal(CvHistogram, @hist1.calc_hist([img], true, mask).class)
64
+
65
+ assert_raise(TypeError) {
66
+ @hist1.calc_hist(img)
67
+ }
68
+ assert_raise(TypeError) {
69
+ @hist1.calc_hist([DUMMY_OBJ])
70
+ }
71
+ assert_raise(TypeError) {
72
+ @hist1.calc_hist(nil)
73
+ }
74
+ assert_raise(TypeError) {
75
+ @hist1.calc_hist([img], true, DUMMY_OBJ)
76
+ }
77
+ assert_raise(CvStsBadArg) {
78
+ @hist1.calc_hist([])
79
+ }
80
+ end
81
+
82
+ def test_aref
83
+ expected = [0.0, 102.0, 189.0, 244.0, 285.0, 140.0, 64.0, 0.0]
84
+ expected.each_with_index { |x, i|
85
+ assert_in_delta(x, @hist1[i], 0.001)
86
+ assert_in_delta(x, @hist1.query_hist_value(i), 0.001)
87
+ }
88
+ end
89
+
90
+ def test_min_max_value
91
+ min, max, min_loc, max_loc = @hist1.min_max_value
92
+ assert_in_delta(0.0, min, 0.001)
93
+ assert_in_delta(285.0, max, 0.001)
94
+ assert_equal(Array, min_loc.class)
95
+ assert_equal(Array, max_loc.class)
96
+ assert_equal(1, min_loc.size)
97
+ assert_equal(1, max_loc.size)
98
+ assert_equal(0, min_loc[0])
99
+ assert_equal(4, max_loc[0])
100
+
101
+ min, max, min_loc, max_loc = @hist2.min_max_value
102
+ assert_in_delta(14.0, min, 0.001)
103
+ assert_in_delta(158.0, max, 0.001)
104
+ assert_equal(Array, min_loc.class)
105
+ assert_equal(Array, max_loc.class)
106
+ assert_equal(2, min_loc.size)
107
+ assert_equal(2, max_loc.size)
108
+ assert_equal(1, min_loc[0])
109
+ assert_equal(2, min_loc[1])
110
+ assert_equal(4, max_loc[0])
111
+ assert_equal(9, max_loc[1])
112
+ end
113
+
114
+ def test_dims
115
+ dims, sizes = @hist1.dims
116
+ assert_equal(1, dims)
117
+ assert_equal(Array, sizes.class)
118
+ assert_equal(1, sizes.size)
119
+ assert_equal(8, sizes[0])
120
+
121
+ dims, sizes = @hist2.dims
122
+ assert_equal(2, dims)
123
+ assert_equal(Array, sizes.class)
124
+ assert_equal(2, sizes.size)
125
+ assert_equal(8, sizes[0])
126
+ assert_equal(16, sizes[1])
127
+ end
128
+
129
+ def test_copy_hist
130
+ expected = [0.0, 102.0, 189.0, 244.0, 285.0, 140.0, 64.0, 0.0]
131
+ hist = @hist1.copy_hist
132
+ expected.each_with_index { |x, i|
133
+ assert_in_delta(x, hist[i], 0.001)
134
+ assert_in_delta(x, hist.query_hist_value(i), 0.001)
135
+ }
136
+ end
137
+
138
+ def test_clear_hist
139
+ @hist1.clear_hist!
140
+ dims, sizes = @hist1.dims
141
+ dims.times { |i|
142
+ assert_in_delta(0.0, @hist1[i], 0.001)
143
+ }
144
+ end
145
+
146
+ def test_normalize_hist
147
+ @hist1.normalize_hist!(100)
148
+ expected = [0.0, 9.96, 18.46, 23.83, 27.83, 13.67, 6.25, 0.0]
149
+ expected.each_with_index { |x, i|
150
+ assert_in_delta(x, @hist1[i], 0.01)
151
+ }
152
+ end
153
+
154
+ def test_thresh_hist
155
+ @hist1.thresh_hist!(150)
156
+ expected = [0.0, 0.0, 189.0, 244.0, 285.0, 0.0, 0.0, 0.0]
157
+ expected.each_with_index { |x, i|
158
+ assert_in_delta(x, @hist1[i], 0.001)
159
+ }
160
+ end
161
+
162
+ def test_set_hist_bin_ranges
163
+ dim = 1
164
+ sizes = [8]
165
+
166
+ hist = CvHistogram.new(dim, sizes, CV_HIST_ARRAY)
167
+ assert_false(hist.has_range?)
168
+ assert(hist.is_uniform?)
169
+
170
+ ranges = [[0, 255]]
171
+ hist.set_hist_bin_ranges!(ranges, true)
172
+ assert(hist.has_range?)
173
+ assert(hist.is_uniform?)
174
+
175
+ assert_raise(TypeError) {
176
+ hist.set_hist_bin_ranges!(DUMMY_OBJ)
177
+ }
178
+ assert_raise(TypeError) {
179
+ hist.set_hist_bin_ranges!([DUMMY_OBJ])
180
+ }
181
+ end
182
+
183
+ def test_calc_back_project
184
+ back_project = @hist1.calc_back_project([@img])
185
+ assert_equal(@img.class, back_project.class)
186
+ assert_equal('2a0097af1ab4f9343e4feaae3a780c93', hash_img(back_project))
187
+
188
+ assert_raise(TypeError) {
189
+ @hist1.calc_back_project(DUMMY_OBJ)
190
+ }
191
+ assert_raise(TypeError) {
192
+ @hist1.calc_back_project([DUMMY_OBJ])
193
+ }
194
+ end
195
+
196
+ def test_calc_back_project_patch
197
+ img = IplImage.load(FILENAME_LENA256x256, 0)
198
+ template = IplImage.load(FILENAME_LENA_EYES, 0)
199
+
200
+ dim = 1
201
+ sizes = [8]
202
+ ranges = [[0, 255]]
203
+ hist = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, ranges).calc_hist!([template])
204
+ back_project = hist.calc_back_project_patch([img], template.size, CV_COMP_CORREL, 1.0)
205
+ assert_equal('e6497e45c6f2f715328bbc2fefe31581', hash_img(back_project))
206
+
207
+ assert_raise(TypeError) {
208
+ hist.calc_back_project_patch(DUMMY_OBJ, template.size, CV_COMP_CORREL, 1.0)
209
+ }
210
+ assert_raise(TypeError) {
211
+ hist.calc_back_project_patch([DUMMY_OBJ], template.size, CV_COMP_CORREL, 1.0)
212
+ }
213
+
214
+ # Uncomment the following line to show the result
215
+ # min_val, max_val, min_loc, max_loc = back_project.min_max_loc
216
+ # result = img.rectangle(max_loc, CvPoint.new(max_loc.x + template.width, max_loc.y + template.height),
217
+ # :thickness => 2)
218
+ # snap img, template, back_project, result
219
+ end
220
+
221
+ def test_compare_hist
222
+ img = IplImage.load(FILENAME_CAT, 0)
223
+ dim, sizes = @hist1.dims
224
+ ranges = [[0, 255]]
225
+ hist = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, ranges).calc_hist!([img])
226
+
227
+ assert_in_delta(0.7446, CvHistogram.compare_hist(@hist1, hist, CV_COMP_CORREL), 0.1)
228
+ assert_in_delta(30250343.0, CvHistogram.compare_hist(@hist1, hist, CV_COMP_CHISQR), 1.0)
229
+ assert_in_delta(1024.0, CvHistogram.compare_hist(@hist1, hist, CV_COMP_INTERSECT), 1.0)
230
+ assert_in_delta(0.2955, CvHistogram.compare_hist(@hist1, hist, CV_COMP_BHATTACHARYYA), 0.1)
231
+
232
+ assert_raise(TypeError) {
233
+ CvHistogram.compare_hist(DUMMY_OBJ, hist, CV_COMP_CORREL)
234
+ }
235
+ assert_raise(TypeError) {
236
+ CvHistogram.compare_hist(@hist1, DUMMY_OBJ, CV_COMP_CORREL)
237
+ }
238
+ assert_raise(TypeError) {
239
+ CvHistogram.compare_hist(@hist1, hist, DUMMY_OBJ)
240
+ }
241
+ end
242
+
243
+ def test_calc_prob_density
244
+ img = IplImage.load(FILENAME_CAT, 0)
245
+ dim, sizes = @hist1.dims
246
+ ranges = [[0, 255]]
247
+ hist = CvHistogram.new(dim, sizes, CV_HIST_ARRAY, ranges).calc_hist!([img])
248
+ dst = CvHistogram.calc_prob_density(hist, @hist1)
249
+
250
+ assert_equal(CvHistogram, dst.class)
251
+ dim, sizes = dst.dims
252
+ expected_dim, expected_sizes = @hist1.dims
253
+ assert_equal(expected_dim, dim)
254
+ expected_sizes.each_with_index { |x, i|
255
+ assert_equal(x, sizes[i])
256
+ }
257
+
258
+ expected = [0.0, 1.437, 1.135, 1.092, 2.323, 3.712, 3.103, 0.0]
259
+ expected.each_with_index { |x, i|
260
+ assert_in_delta(x, dst[i], 0.001)
261
+ }
262
+
263
+ assert_raise(TypeError) {
264
+ CvHistogram.calc_prob_density(DUMMY_OBJ, @hist1)
265
+ }
266
+ assert_raise(TypeError) {
267
+ CvHistogram.calc_prob_density(hist, DUMMY_OBJ)
268
+ }
269
+ end
270
+ end
271
+
@@ -0,0 +1,83 @@
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::CvHuMoment
10
+ class TestCvHuMoments < 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
+
26
+ @hu_moments1 = CvHuMoments.new(@moment1)
27
+ @hu_moments2 = CvHuMoments.new(@moment2)
28
+ @hu_moments3 = CvHuMoments.new(@moment3)
29
+ @hu_moments4 = CvHuMoments.new(@moment4)
30
+ end
31
+
32
+ def test_initialize
33
+ [@hu_moments1, @hu_moments2, @hu_moments3, @hu_moments4].each { |m|
34
+ assert_not_nil(m)
35
+ assert_equal(CvHuMoments, m.class)
36
+ }
37
+
38
+ assert_raise(TypeError) {
39
+ CvHuMoments.new('foo')
40
+ }
41
+ end
42
+
43
+ def test_huX
44
+ hu_moments = [@hu_moments1.hu1, @hu_moments1.hu2, @hu_moments1.hu3, @hu_moments1.hu4,
45
+ @hu_moments1.hu5, @hu_moments1.hu6, @hu_moments1.hu7]
46
+ hu_moments.each { |hu|
47
+ assert_in_delta(0.0, hu, 0.000001)
48
+ }
49
+
50
+ hu_moments = [@hu_moments2.hu1, @hu_moments2.hu2, @hu_moments2.hu3, @hu_moments2.hu4,
51
+ @hu_moments2.hu5, @hu_moments2.hu6, @hu_moments2.hu7]
52
+ hu_moments.each { |hu|
53
+ assert_in_delta(0.0, hu, 0.000001)
54
+ }
55
+
56
+ hu_moments = [@hu_moments3.hu2, @hu_moments3.hu3, @hu_moments3.hu4,
57
+ @hu_moments3.hu5, @hu_moments3.hu6, @hu_moments3.hu7]
58
+ assert_in_delta(0.001771, @hu_moments3.hu1, 0.000001)
59
+ hu_moments.each { |hu|
60
+ assert_in_delta(0.0, hu, 0.000001)
61
+ }
62
+
63
+ hu_moments = [@hu_moments4.hu3, @hu_moments4.hu4,
64
+ @hu_moments4.hu5, @hu_moments4.hu6, @hu_moments4.hu7]
65
+ assert_in_delta(0.361650, @hu_moments4.hu1, 0.000001)
66
+ assert_in_delta(0.000625, @hu_moments4.hu2, 0.000001)
67
+ hu_moments.each { |hu|
68
+ assert_in_delta(0.0, hu, 0.000001)
69
+ }
70
+ end
71
+
72
+ def test_to_ary
73
+ [@hu_moments4.to_ary, @hu_moments4.to_a].each { |hu_moments|
74
+ assert_equal(7, hu_moments.size)
75
+ assert_in_delta(0.361650, hu_moments[0], 0.000001)
76
+ assert_in_delta(0.000625, hu_moments[1], 0.000001)
77
+ hu_moments[2..7].each { |hu|
78
+ assert_in_delta(0.0, hu, 0.000001)
79
+ }
80
+ }
81
+ end
82
+ end
83
+
@@ -0,0 +1,50 @@
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::CvLine
10
+ class TestCvLine < OpenCVTestCase
11
+ def setup
12
+ @line = CvLine.new
13
+ end
14
+
15
+ def test_initialize
16
+ assert_not_nil(@line)
17
+ assert_equal(CvLine, @line.class)
18
+ end
19
+
20
+ def test_rho
21
+ @line.rho = 0.0
22
+ assert_in_delta(0.0, @line.rho, 0.001)
23
+ @line.rho = 3.14
24
+ assert_in_delta(3.14, @line.rho, 0.001)
25
+ end
26
+
27
+ def test_theta
28
+ @line.theta = 0.0
29
+ assert_in_delta(0.0, @line.theta, 0.001)
30
+ @line.theta = 3.14
31
+ assert_in_delta(3.14, @line.theta, 0.001)
32
+ end
33
+
34
+ def test_aref_aset
35
+ @line[0] = 0.0
36
+ @line[1] = 0.0
37
+ assert_in_delta(0.0, @line[0], 0.001)
38
+ assert_in_delta(0.0, @line[1], 0.001)
39
+
40
+ @line[0] = 3.14
41
+ @line[1] = 2.71
42
+ assert_in_delta(3.14, @line[0], 0.001)
43
+ assert_in_delta(2.71, @line[1], 0.001)
44
+
45
+ assert_raise(IndexError) {
46
+ @line[2] = 1
47
+ }
48
+ end
49
+ end
50
+