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,41 @@
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::CvCircle32f
10
+ class TestCvCircle32f < OpenCVTestCase
11
+ def setup
12
+ @circle = CvCircle32f.new
13
+ end
14
+
15
+ def test_initialize
16
+ assert_equal(CvCircle32f, @circle.class)
17
+ end
18
+
19
+ def test_center
20
+ assert_equal(CvPoint2D32f, @circle.center.class)
21
+ end
22
+
23
+ def test_radius
24
+ assert_equal(Float, @circle.radius.class)
25
+ end
26
+
27
+ def test_aref
28
+ assert_equal(Float, @circle[0].class)
29
+ assert_equal(Float, @circle[1].class)
30
+ assert_equal(Float, @circle[2].class)
31
+ assert_raise(IndexError) {
32
+ @circle[3]
33
+ }
34
+ end
35
+
36
+ def test_to_ary
37
+ assert_equal(Array, @circle.to_ary.class)
38
+ assert_equal(2, @circle.to_ary.size)
39
+ end
40
+ end
41
+
@@ -0,0 +1,61 @@
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::CvConnectedComp
10
+ class TestCvConnectedComp < OpenCVTestCase
11
+ def setup
12
+ @connected_comp = CvConnectedComp.new(9216, CvScalar.new(1, 2, 3, 4),
13
+ CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
14
+ end
15
+
16
+ def test_initialize
17
+ connected_comp = CvConnectedComp.new
18
+ assert_equal(CvConnectedComp, connected_comp.class)
19
+ assert_not_nil(connected_comp.area)
20
+ assert_not_nil(connected_comp.value)
21
+ assert_not_nil(connected_comp.rect)
22
+ assert_not_nil(connected_comp.contour)
23
+
24
+ connected_comp = CvConnectedComp.new(100, CvScalar.new(1, 2, 3, 4),
25
+ CvRect.new(1, 2, 3, 4), CvSeq.new(CvPoint))
26
+ assert_equal(CvConnectedComp, connected_comp.class)
27
+ assert_not_nil(connected_comp.area)
28
+ assert_not_nil(connected_comp.value)
29
+ assert_not_nil(connected_comp.rect)
30
+ assert_not_nil(connected_comp.contour)
31
+ end
32
+
33
+ def test_area
34
+ assert_in_delta(9216.0, @connected_comp.area, 0.01)
35
+ end
36
+
37
+ def test_value
38
+ assert_equal(CvScalar, @connected_comp.value.class)
39
+ assert_cvscalar_equal(CvScalar.new(1, 2, 3, 4), @connected_comp.value)
40
+ end
41
+
42
+ def test_rect
43
+ assert_equal(CvRect, @connected_comp.rect.class)
44
+ assert_equal(1, @connected_comp.rect.x)
45
+ assert_equal(2, @connected_comp.rect.y)
46
+ assert_equal(3, @connected_comp.rect.width)
47
+ assert_equal(4, @connected_comp.rect.height)
48
+
49
+ @connected_comp.rect = CvRect.new(10, 20, 30, 40);
50
+ assert_equal(10, @connected_comp.rect.x)
51
+ assert_equal(20, @connected_comp.rect.y)
52
+ assert_equal(30, @connected_comp.rect.width)
53
+ assert_equal(40, @connected_comp.rect.height)
54
+ end
55
+
56
+ def test_contour
57
+ assert_equal(CvContour, @connected_comp.contour.class)
58
+ assert_not_nil(@connected_comp.contour)
59
+ end
60
+ end
61
+
@@ -0,0 +1,150 @@
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::CvContour
10
+ class TestCvContour < OpenCVTestCase
11
+ def test_APPROX_OPTION
12
+ assert_equal(0, CvContour::APPROX_OPTION[:method])
13
+ assert_equal(1.0, CvContour::APPROX_OPTION[:accuracy])
14
+ assert_false(CvContour::APPROX_OPTION[:recursive])
15
+ end
16
+
17
+ def test_initialize
18
+ contour = CvContour.new
19
+ assert_not_nil(contour)
20
+ assert_equal(CvContour, contour.class)
21
+ assert(contour.is_a? CvSeq)
22
+ end
23
+
24
+ def test_rect
25
+ contour = CvContour.new
26
+ assert_not_nil(contour.rect)
27
+ assert_equal(CvRect, contour.rect.class)
28
+ end
29
+
30
+ def test_color
31
+ contour = CvContour.new
32
+ assert_equal(0, contour.color)
33
+ contour.color = 1
34
+ assert_equal(1, contour.color)
35
+ end
36
+
37
+ def test_reserved
38
+ reserved = CvContour.new.reserved
39
+ assert_equal(Array, reserved.class)
40
+ assert_equal(3, reserved.size)
41
+ end
42
+
43
+ def test_approx_poly
44
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
45
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
46
+ }
47
+ contours = mat0.find_contours(:mode => CV_RETR_EXTERNAL)
48
+
49
+ poly = contours.approx_poly
50
+ assert_equal(CvContour, poly.class)
51
+ assert(poly.size > 0)
52
+ assert(poly.all? { |c| c.class == CvPoint })
53
+
54
+ poly = contours.approx_poly(:method => :dp)
55
+ assert_equal(CvContour, poly.class)
56
+ assert(poly.size > 0)
57
+ assert(poly.all? { |c| c.class == CvPoint })
58
+
59
+ poly = contours.approx_poly(:accuracy => 2.0)
60
+ assert_equal(CvContour, poly.class)
61
+ assert(poly.size > 0)
62
+ assert(poly.all? { |c| c.class == CvPoint })
63
+
64
+ [true, false, 1, 0].each { |recursive|
65
+ poly = contours.approx_poly(:recursive => recursive)
66
+ assert_equal(CvContour, poly.class)
67
+ assert(poly.size > 0)
68
+ assert(poly.all? { |c| c.class == CvPoint })
69
+ }
70
+
71
+ poly = contours.approx_poly(:method => :dp, :accuracy => 2.0, :recursive => false)
72
+ assert_equal(CvContour, poly.class)
73
+ assert(poly.size > 0)
74
+ assert(poly.all? { |c| c.class == CvPoint })
75
+
76
+ # Uncomment the following lines to show the result
77
+ # poly = contours.approx_poly(:accuracy => 3.0)
78
+ # dst = mat0.clone.zero
79
+ # begin
80
+ # dst.draw_contours!(poly, CvColor::White, CvColor::Black, 2,
81
+ # :thickness => 1, :line_type => :aa)
82
+ # end while (poly = poly.h_next)
83
+ # snap dst
84
+ end
85
+
86
+ def test_bounding_rect
87
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
88
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
89
+ }
90
+ contours = mat0.find_contours
91
+ rect = contours.bounding_rect
92
+ assert_equal(CvRect, rect.class)
93
+ assert_equal(32, rect.x)
94
+ assert_equal(32, rect.y)
95
+ assert_equal(65, rect.width)
96
+ assert_equal(65, rect.height)
97
+ end
98
+
99
+ def test_create_tree
100
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
101
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
102
+ }
103
+ contour = mat0.find_contours
104
+ tree = contour.create_tree
105
+ assert_equal(CvContourTree, tree.class)
106
+ assert_equal(34, tree.p1.x)
107
+ assert_equal(53, tree.p1.y)
108
+ assert_equal(0, tree.p2.x)
109
+ assert_equal(0, tree.p2.y)
110
+ end
111
+
112
+ def test_in
113
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
114
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
115
+ }
116
+ contour = mat0.find_contours
117
+ assert(contour.in? CvPoint.new(64, 64))
118
+ assert_false(contour.in? CvPoint.new(0, 0))
119
+ assert_nil(contour.in? CvPoint.new(64, 32))
120
+ end
121
+
122
+ def test_measure_distance
123
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
124
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
125
+ }
126
+ contour = mat0.find_contours
127
+ assert_in_delta(-0.7071, contour.measure_distance(CvPoint.new(63, 32)), 0.01)
128
+ assert_in_delta(31.01, contour.measure_distance(CvPoint.new(64, 64)), 0.01)
129
+ end
130
+
131
+ def test_point_polygon_test
132
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
133
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
134
+ }
135
+ contour = mat0.find_contours
136
+
137
+ assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), 0))
138
+ assert_equal(1, contour.point_polygon_test(CvPoint.new(64, 64), false))
139
+ assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), 0))
140
+ assert_equal(-1, contour.point_polygon_test(CvPoint.new(0, 0), false))
141
+ assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), 0))
142
+ assert_equal(0, contour.point_polygon_test(CvPoint.new(64, 32), false))
143
+
144
+ assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), 1), 0.01)
145
+ assert_in_delta(-0.7071, contour.point_polygon_test(CvPoint.new(63, 32), true), 0.01)
146
+ assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), 1), 0.01)
147
+ assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), true), 0.01)
148
+ end
149
+ end
150
+
@@ -0,0 +1,43 @@
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::CvContourTree
10
+ class TestCvContourTree < OpenCVTestCase
11
+ def setup
12
+ @tree = CvContourTree.new(CvPoint)
13
+ end
14
+
15
+ def test_initialize
16
+ tree = CvContourTree.new(CvPoint)
17
+ assert_equal(CvContourTree, tree.class)
18
+ assert(tree.is_a? CvSeq)
19
+ end
20
+
21
+ def test_p1
22
+ assert_equal(CvPoint, @tree.p1.class)
23
+ end
24
+
25
+ def test_p2
26
+ assert_equal(CvPoint, @tree.p2.class)
27
+ end
28
+
29
+ def test_contour
30
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
31
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
32
+ }
33
+ contour = mat0.find_contours
34
+ tree = contour.create_tree
35
+ contour = tree.contour(CvTermCriteria.new(100, 0.01))
36
+ assert_equal(CvContour, contour.class)
37
+
38
+ assert_raise(CvStsBadArg) {
39
+ tree.contour(CvTermCriteria.new(0, 0))
40
+ }
41
+ end
42
+ end
43
+
@@ -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::CvError
10
+ class TestCvError < OpenCVTestCase
11
+ def test_cverror
12
+ assert_equal(StandardError, CvError.superclass)
13
+ begin
14
+ raise CvError
15
+ rescue
16
+ assert_equal(CvError, $!.class)
17
+ end
18
+ end
19
+
20
+ def test_subclass
21
+ errors = [CvStsBackTrace, CvStsError, CvStsInternal, CvStsNoMem, CvStsBadArg, CvStsBadFunc, CvStsNoConv, CvStsAutoTrace, CvHeaderIsNull, CvBadImageSize, CvBadOffset, CvBadDataPtr, CvBadStep, CvBadModelOrChSeq, CvBadNumChannels, CvBadNumChannel1U, CvBadDepth, CvBadAlphaChannel, CvBadOrder, CvBadOrigin, CvBadAlign, CvBadCallBack, CvBadTileSize, CvBadCOI, CvBadROISize, CvMaskIsTiled, CvStsNullPtr, CvStsVecLengthErr, CvStsFilterStructContentErr, CvStsKernelStructContentErr, CvStsFilterOffsetErr, CvStsBadSize, CvStsDivByZero, CvStsInplaceNotSupported, CvStsObjectNotFound, CvStsUnmatchedFormats, CvStsBadFlag, CvStsBadPoint, CvStsBadMask, CvStsUnmatchedSizes, CvStsUnsupportedFormat, CvStsOutOfRange, CvStsParseError, CvStsNotImplemented, CvStsBadMemBlock, CvStsAssert, CvGpuNotSupported, CvGpuApiCallError]
22
+
23
+ errors.each { |err|
24
+ assert_equal(CvError, err.superclass)
25
+
26
+ begin
27
+ raise err
28
+ rescue err
29
+ assert_equal(err, $!.class)
30
+ rescue
31
+ flunk("Failed to catch #{err}")
32
+ end
33
+
34
+ begin
35
+ raise err
36
+ rescue CvError
37
+ assert_equal(err, $!.class)
38
+ rescue
39
+ flunk("Failed to catch #{err}")
40
+ end
41
+
42
+ begin
43
+ raise err
44
+ rescue
45
+ assert_equal(err, $!.class)
46
+ end
47
+ }
48
+ end
49
+ end
50
+
@@ -0,0 +1,65 @@
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::CvFeatureTree
10
+ class TestCvFeatureTree < OpenCVTestCase
11
+ def test_initialize
12
+ desc = CvMat.new(1, 1, :cv32f, 1)
13
+ ft = CvFeatureTree.new(desc)
14
+ assert_equal(CvFeatureTree, ft.class)
15
+
16
+ assert_raise(TypeError) {
17
+ CvFeatureTree.new(DUMMY_OBJ)
18
+ }
19
+ end
20
+
21
+ def test_find_feature
22
+ dim = 2
23
+ points = []
24
+ points << [99, 51]
25
+ points << [52, 57]
26
+ points << [57, 42]
27
+ points << [13, 39]
28
+ points << [15, 68]
29
+ points << [75, 11]
30
+ points << [69, 62]
31
+ points << [52, 46]
32
+ points << [0, 64]
33
+ points << [67, 16]
34
+
35
+ desc1 = CvMat.new(points.size, dim, :cv32f, 1)
36
+ desc1.set_data(points)
37
+
38
+ pt = [[50, 50], [11, 40]]
39
+ desc2 = CvMat.new(pt.size, dim, :cv32f, 1)
40
+ desc2.set_data(pt)
41
+
42
+ ft = CvFeatureTree.new(desc1)
43
+ results, dist = ft.find_features(desc2, 1, 10)
44
+
45
+ assert_equal(CvMat, results.class)
46
+ assert_equal(CvMat, dist.class)
47
+
48
+ assert_equal(7, results[0][0].to_i)
49
+ assert_in_delta(4.472, dist[0][0], 0.001)
50
+
51
+ assert_equal(3, results[1][0].to_i)
52
+ assert_in_delta(2.236, dist[1][0], 0.001)
53
+
54
+ assert_raise(TypeError) {
55
+ ft.find_features(DUMMY_OBJ, 1, 10)
56
+ }
57
+ assert_raise(TypeError) {
58
+ ft.find_features(desc2, DUMMY_OBJ, 10)
59
+ }
60
+ assert_raise(TypeError) {
61
+ ft.find_features(desc2, 1, DUMMY_OBJ)
62
+ }
63
+ end
64
+ end
65
+
@@ -0,0 +1,58 @@
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::CvFont
10
+ class TestCvFont < OpenCVTestCase
11
+ def test_FACE
12
+ assert_equal(0, CvFont::FACE[:simplex])
13
+ assert_equal(1, CvFont::FACE[:plain])
14
+ assert_equal(2, CvFont::FACE[:duplex])
15
+ assert_equal(4, CvFont::FACE[:triplex])
16
+ assert_equal(5, CvFont::FACE[:complex_small])
17
+ assert_equal(6, CvFont::FACE[:script_simplex])
18
+ assert_equal(7, CvFont::FACE[:script_complex])
19
+ end
20
+
21
+ def test_FONT_OPTION
22
+ assert_equal(1.0, CvFont::FONT_OPTION[:hscale])
23
+ assert_equal(1.0, CvFont::FONT_OPTION[:vscale])
24
+ assert_equal(0, CvFont::FONT_OPTION[:shear])
25
+ assert_equal(1, CvFont::FONT_OPTION[:thickness])
26
+ assert_equal(8, CvFont::FONT_OPTION[:line_type])
27
+ end
28
+
29
+ def test_initialize
30
+ font = CvFont.new(:simplex)
31
+ assert_equal(0, font.face)
32
+ assert_equal(1.0, font.hscale)
33
+ assert_equal(1.0, font.vscale)
34
+ assert_equal(0, font.shear)
35
+ assert_equal(1, font.thickness)
36
+ assert_equal(8, font.line_type)
37
+ assert_false(font.italic)
38
+
39
+ font = CvFont.new(:plain, :hscale => 2.5, :vscale => 3.5,
40
+ :shear => 0.5, :thickness => 3, :line_type => 2, :italic => false)
41
+ assert_equal(1, font.face)
42
+ assert_equal(2.5, font.hscale)
43
+ assert_equal(3.5, font.vscale)
44
+ assert_equal(0.5, font.shear)
45
+ assert_equal(3, font.thickness)
46
+ assert_equal(2, font.line_type)
47
+ assert_false(font.italic)
48
+
49
+ font = CvFont.new(:simplex, :italic => true)
50
+ assert_equal(16, font.face)
51
+ assert(font.italic)
52
+
53
+ assert_raise(ArgumentError) {
54
+ CvFont.new(:foo)
55
+ }
56
+ end
57
+ end
58
+