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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -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::Curve
10
+ class TestCurve < OpenCVTestCase
11
+ def setup
12
+ @contour1 = CvContour.new
13
+
14
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
15
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
16
+ }
17
+ @contour2 = mat0.find_contours
18
+ end
19
+
20
+ def test_closed
21
+ assert_false(@contour1.closed?)
22
+ assert(@contour2.closed?)
23
+ end
24
+
25
+ def test_convex
26
+ assert_false(@contour1.convex?)
27
+ end
28
+
29
+ def test_hole
30
+ assert_false(@contour1.hole?)
31
+ end
32
+
33
+ def test_simple
34
+ assert(@contour1.simple?)
35
+ end
36
+
37
+ def test_arc_length
38
+ assert_in_delta(211.480, @contour2.arc_length, 0.001)
39
+ assert_in_delta(32.181, @contour2.arc_length(CvSlice.new(0, 9), true), 0.001)
40
+ assert_in_delta(32.181, @contour2.arc_length(0..10, true), 0.001)
41
+ end
42
+ end
43
+
@@ -0,0 +1,24 @@
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::CvAvgComp
10
+ class TestCvAvgComp < OpenCVTestCase
11
+ def setup
12
+ @avgcomp = CvAvgComp.new
13
+ end
14
+
15
+ def test_initialize
16
+ assert_equal(CvAvgComp, @avgcomp.class)
17
+ assert(@avgcomp.is_a? CvRect)
18
+ end
19
+
20
+ def test_neighbors
21
+ assert_equal(Fixnum, @avgcomp.neighbors.class)
22
+ end
23
+ end
24
+
@@ -0,0 +1,76 @@
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::CvBox2D
10
+ class TestCvBox2D < OpenCVTestCase
11
+ class MyPoint; end
12
+ def test_initialize
13
+ box = CvBox2D.new
14
+ assert_in_delta(0, box.center.x, 0.001)
15
+ assert_in_delta(0, box.center.y, 0.001)
16
+ assert_in_delta(0, box.size.width, 0.001)
17
+ assert_in_delta(0, box.size.height, 0.001)
18
+ assert_in_delta(0, box.angle, 0.001)
19
+
20
+ box = CvBox2D.new(CvPoint2D32f.new(1.1, 2.2), CvSize2D32f.new(3.3, 4.4), 5.5)
21
+ assert_in_delta(1.1, box.center.x, 0.001)
22
+ assert_in_delta(2.2, box.center.y, 0.001)
23
+ assert_in_delta(3.3, box.size.width, 0.001)
24
+ assert_in_delta(4.4, box.size.height, 0.001)
25
+ assert_in_delta(5.5, box.angle, 0.001)
26
+ end
27
+
28
+ def test_center
29
+ box = CvBox2D.new
30
+ box.center = CvPoint2D32f.new(1.1, 2.2)
31
+ assert_in_delta(1.1, box.center.x, 0.001)
32
+ assert_in_delta(2.2, box.center.y, 0.001)
33
+
34
+ box.center.x = 3.3
35
+ box.center.y = 4.4
36
+ assert_in_delta(3.3, box.center.x, 0.001)
37
+ assert_in_delta(4.4, box.center.y, 0.001)
38
+ end
39
+
40
+ def test_size
41
+ box = CvBox2D.new
42
+ box.size = CvSize2D32f.new(1.1, 2.2)
43
+ assert_in_delta(1.1, box.size.width, 0.001)
44
+ assert_in_delta(2.2, box.size.height, 0.001)
45
+
46
+ box.size.width = 3.3
47
+ box.size.height = 4.4
48
+ assert_in_delta(3.3, box.size.width, 0.001)
49
+ assert_in_delta(4.4, box.size.height, 0.001)
50
+ end
51
+
52
+ def test_angle
53
+ box = CvBox2D.new
54
+ box.angle = 1.1
55
+ assert_in_delta(1.1, box.angle, 0.001)
56
+ end
57
+
58
+ def test_points
59
+ box = CvBox2D.new
60
+ box.center = CvPoint2D32f.new(10, 20)
61
+ box.size = CvSize2D32f.new(5, 7)
62
+ pt = box.points
63
+
64
+ assert_equal(4, pt.size)
65
+ assert_in_delta(7.5, pt[0].x, 0.001)
66
+ assert_in_delta(23.5, pt[0].y, 0.001)
67
+ assert_in_delta(7.5, pt[1].x, 0.001)
68
+ assert_in_delta(16.5, pt[1].y, 0.001)
69
+ assert_in_delta(12.5, pt[2].x, 0.001)
70
+ assert_in_delta(16.5, pt[2].y, 0.001)
71
+ assert_in_delta(12.5, pt[3].x, 0.001)
72
+ assert_in_delta(23.5, pt[3].y, 0.001)
73
+ end
74
+ end
75
+
76
+
@@ -0,0 +1,183 @@
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::CvCapture
10
+ class TestCvCapture < OpenCVTestCase
11
+ def setup
12
+ @cap = CvCapture.open(AVI_SAMPLE)
13
+ @cap.query
14
+ end
15
+
16
+ def teardown
17
+ @cap = nil
18
+ end
19
+
20
+ def test_INTERFACE
21
+ assert_equal(CvCapture::INTERFACE[:any], 0)
22
+ assert_equal(CvCapture::INTERFACE[:mil], 100)
23
+ assert_equal(CvCapture::INTERFACE[:vfw], 200)
24
+ assert_equal(CvCapture::INTERFACE[:v4l], 200)
25
+ assert_equal(CvCapture::INTERFACE[:v4l2], 200)
26
+ assert_equal(CvCapture::INTERFACE[:fireware], 300)
27
+ assert_equal(CvCapture::INTERFACE[:ieee1394], 300)
28
+ assert_equal(CvCapture::INTERFACE[:dc1394], 300)
29
+ assert_equal(CvCapture::INTERFACE[:cmu1394], 300)
30
+ assert_equal(CvCapture::INTERFACE[:stereo], 400)
31
+ assert_equal(CvCapture::INTERFACE[:tyzx], 400)
32
+ assert_equal(CvCapture::INTERFACE[:tyzx_left], 400)
33
+ assert_equal(CvCapture::INTERFACE[:tyzx_right], 401)
34
+ assert_equal(CvCapture::INTERFACE[:tyzx_color], 402)
35
+ assert_equal(CvCapture::INTERFACE[:tyzx_z], 403)
36
+ assert_equal(CvCapture::INTERFACE[:qt], 500)
37
+ assert_equal(CvCapture::INTERFACE[:quicktime], 500)
38
+ end
39
+
40
+ def test_open
41
+ cap1 = CvCapture.open(AVI_SAMPLE)
42
+ assert_equal(CvCapture, cap1.class)
43
+
44
+ # Uncomment the following lines to test capturing from camera
45
+ # cap2 = CvCapture.open(0)
46
+ # assert_equal(CvCapture, cap2.class)
47
+ # CvCapture::INTERFACE.each { |k, v|
48
+ # cap3 = CvCapture.open(k)
49
+ # assert_equal(CvCapture, cap3.class)
50
+ # }
51
+ end
52
+
53
+ def test_grab
54
+ assert(@cap.grab)
55
+ end
56
+
57
+ def test_retrieve
58
+ @cap.grab
59
+ img = @cap.retrieve
60
+ assert_equal(IplImage, img.class)
61
+ end
62
+
63
+ def test_query
64
+ img = @cap.query
65
+ assert_equal(IplImage, img.class)
66
+ end
67
+
68
+ def test_millisecond
69
+ @cap.millisecond = 10
70
+ assert(@cap.millisecond.is_a? Numeric)
71
+ # assert_equal(10, @cap.millisecond)
72
+ @cap.millisecond = 20
73
+ assert(@cap.millisecond.is_a? Numeric)
74
+ # assert_equal(20, @cap.millisecond)
75
+ end
76
+
77
+ def test_frames
78
+ @cap.frames = 10
79
+ assert(@cap.frames.is_a? Numeric)
80
+ # assert_equal(10, @cap.frames)
81
+ @cap.frames = 20
82
+ assert(@cap.frames.is_a? Numeric)
83
+ # assert_equal(20, @cap.frames)
84
+ end
85
+
86
+ def test_avi_ratio
87
+ @cap.avi_ratio = 0.1
88
+ assert(@cap.avi_ratio.is_a? Numeric)
89
+ # assert_equal(0.1, @cap.avi_ratio)
90
+ @cap.avi_ratio = 0.8
91
+ assert(@cap.avi_ratio.is_a? Numeric)
92
+ # assert_equal(0.8, @cap.avi_ratio)
93
+ end
94
+
95
+ def test_size
96
+ @cap.size = CvSize.new(320, 240)
97
+ assert_equal(CvSize, @cap.size.class)
98
+ # assert_equal(320, @cap.size.width)
99
+ # assert_equal(240, @cap.size.height)
100
+
101
+ @cap.size = CvSize.new(640, 480)
102
+ assert_equal(CvSize, @cap.size.class)
103
+ # assert_equal(640, @cap.size.width)
104
+ # assert_equal(480, @cap.size.height)
105
+ end
106
+
107
+ def test_width
108
+ @cap.width = 320
109
+ assert(@cap.width.is_a? Numeric)
110
+ # assert_equal(320, @cap.width)
111
+ @cap.width = 640
112
+ assert(@cap.width.is_a? Numeric)
113
+ # assert_equal(640, @cap.width)
114
+ end
115
+
116
+ def test_height
117
+ @cap.height = 240
118
+ assert(@cap.height.is_a? Numeric)
119
+ # assert_equal(240, @cap.height)
120
+ @cap.height = 480
121
+ assert(@cap.height.is_a? Numeric)
122
+ # assert_equal(480, @cap.height)
123
+ end
124
+
125
+ def test_fps
126
+ @cap.fps = 15
127
+ assert(@cap.fps.is_a? Numeric)
128
+ # assert_equal(15, @cap.fps)
129
+ @cap.fps = 30
130
+ assert(@cap.fps.is_a? Numeric)
131
+ # assert_equal(30, @cap.fps)
132
+ end
133
+
134
+ def test_fourcc
135
+ assert_equal(String, @cap.fourcc.class)
136
+ end
137
+
138
+ def test_frame_count
139
+ assert(@cap.frame_count.is_a? Numeric)
140
+ end
141
+
142
+ def test_format
143
+ assert(@cap.format.is_a? Numeric)
144
+ end
145
+
146
+ def test_mode
147
+ assert(@cap.mode.is_a? Numeric)
148
+ end
149
+
150
+ def test_brightness
151
+ assert(@cap.brightness.is_a? Numeric)
152
+ end
153
+
154
+ def test_contrast
155
+ assert(@cap.contrast.is_a? Numeric)
156
+ end
157
+
158
+ def test_saturation
159
+ assert(@cap.saturation.is_a? Numeric)
160
+ end
161
+
162
+ def test_hue
163
+ assert(@cap.hue.is_a? Numeric)
164
+ end
165
+
166
+ def test_gain
167
+ assert(@cap.gain.is_a? Numeric)
168
+ end
169
+
170
+ def test_exposure
171
+ assert(@cap.exposure.is_a? Numeric)
172
+ end
173
+
174
+ def test_convert_rgb
175
+ assert((@cap.convert_rgb == true) ||
176
+ (@cap.convert_rgb == false))
177
+ end
178
+
179
+ def test_rectification
180
+ assert(@cap.rectification.is_a? Numeric)
181
+ end
182
+ end
183
+
@@ -0,0 +1,108 @@
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::CvChain
10
+ class TestCvChain < OpenCVTestCase
11
+ def test_APPROX_OPTION
12
+ assert_equal(:approx_simple, CvChain::APPROX_CHAIN_OPTION[:method])
13
+ assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:parameter])
14
+ assert_equal(0, CvChain::APPROX_CHAIN_OPTION[:minimal_perimeter])
15
+ assert_false(CvChain::APPROX_CHAIN_OPTION[:recursive])
16
+ end
17
+
18
+ def test_initialize
19
+ chain = CvChain.new
20
+ assert_not_nil(chain)
21
+ assert_equal(CvChain, chain.class)
22
+ assert(chain.is_a? CvSeq)
23
+ end
24
+
25
+ def test_origin
26
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
27
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
28
+ }
29
+ chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
30
+ assert_equal(CvChain, chain.class)
31
+ assert_equal(64, chain.origin.x)
32
+ assert_equal(32, chain.origin.y)
33
+
34
+ chain.origin = CvPoint.new(32, 64)
35
+ assert_equal(32, chain.origin.x)
36
+ assert_equal(64, chain.origin.y)
37
+ end
38
+
39
+ def test_codes
40
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
41
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
42
+ }
43
+ chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
44
+ assert_equal(Array, chain.codes.class)
45
+ assert(chain.codes.all? { |a| (a.class == Fixnum) and (a >= 0 and a <= 7) })
46
+ end
47
+
48
+ def test_points
49
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
50
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
51
+ }
52
+ chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
53
+ assert_equal(Array, chain.points.class)
54
+ assert(chain.points.all? { |a| a.class == CvPoint })
55
+ end
56
+
57
+ def test_approx_chains
58
+ mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
59
+ (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
60
+ }
61
+ chain = mat0.find_contours(:mode => CV_RETR_EXTERNAL, :method => CV_CHAIN_CODE)
62
+
63
+ contours = chain.approx_chains
64
+ assert_equal(CvChain, contours.class)
65
+ assert(contours.size > 0)
66
+ assert(contours.all? { |c| c.class == CvPoint })
67
+
68
+ [CV_CHAIN_APPROX_NONE, CV_CHAIN_APPROX_SIMPLE,
69
+ CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS,
70
+ :approx_none, :approx_simple, :approx_tc89_l1, :approx_tc89_kcos].each { |method|
71
+ contours = chain.approx_chains(:method => method)
72
+ assert_equal(CvChain, contours.class)
73
+ assert(contours.size > 0)
74
+ assert(contours.all? { |c| c.class == CvPoint })
75
+ }
76
+
77
+ contours = chain.approx_chains(:minimal_parameter => 10)
78
+ assert_equal(CvChain, contours.class)
79
+ assert(contours.size > 0)
80
+ assert(contours.all? { |c| c.class == CvPoint })
81
+
82
+ contours = chain.approx_chains(:minimal_perimeter => (32 * 2 * Math::PI).ceil)
83
+ assert_nil(contours)
84
+
85
+ [true, false].each { |recursive|
86
+ contours = chain.approx_chains(:recursive => recursive)
87
+ assert_equal(CvChain, contours.class)
88
+ assert(contours.size > 0)
89
+ assert(contours.all? { |c| c.class == CvPoint })
90
+ }
91
+
92
+ contours = chain.approx_chains(:method => :approx_simple,
93
+ :minimal_parameter => 100, :recursive => false)
94
+ assert_equal(CvChain, contours.class)
95
+ assert(contours.size > 0)
96
+ assert(contours.all? { |c| c.class == CvPoint })
97
+
98
+ # Uncomment the following lines to show the result
99
+ # contours = chain.approx_chains
100
+ # dst = mat0.clone.zero
101
+ # begin
102
+ # dst.draw_contours!(contours, CvColor::White, CvColor::Black, 2,
103
+ # :thickness => 1, :line_type => :aa)
104
+ # end while (contours = contours.h_next)
105
+ # snap dst
106
+ end
107
+ end
108
+