ruby-opencv 0.0.10-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +26 -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 +727 -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/1.9/opencv.so +0 -0
  136. data/lib/2.0/opencv.so +0 -0
  137. data/lib/opencv.rb +12 -0
  138. data/lib/opencv/psyched_yaml.rb +22 -0
  139. data/lib/opencv/version.rb +3 -0
  140. data/ruby-opencv.gemspec +44 -0
  141. data/test/helper.rb +166 -0
  142. data/test/runner.rb +30 -0
  143. data/test/samples/airplane.jpg +0 -0
  144. data/test/samples/baboon.jpg +0 -0
  145. data/test/samples/baboon200.jpg +0 -0
  146. data/test/samples/baboon200_rotated.jpg +0 -0
  147. data/test/samples/blank0.jpg +0 -0
  148. data/test/samples/blank1.jpg +0 -0
  149. data/test/samples/blank2.jpg +0 -0
  150. data/test/samples/blank3.jpg +0 -0
  151. data/test/samples/blank4.jpg +0 -0
  152. data/test/samples/blank5.jpg +0 -0
  153. data/test/samples/blank6.jpg +0 -0
  154. data/test/samples/blank7.jpg +0 -0
  155. data/test/samples/blank8.jpg +0 -0
  156. data/test/samples/blank9.jpg +0 -0
  157. data/test/samples/cat.jpg +0 -0
  158. data/test/samples/chessboard.jpg +0 -0
  159. data/test/samples/contours.jpg +0 -0
  160. data/test/samples/fruits.jpg +0 -0
  161. data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
  162. data/test/samples/inpaint-mask.bmp +0 -0
  163. data/test/samples/lena-256x256.jpg +0 -0
  164. data/test/samples/lena-32x32.jpg +0 -0
  165. data/test/samples/lena-eyes.jpg +0 -0
  166. data/test/samples/lena-inpaint.jpg +0 -0
  167. data/test/samples/lena.jpg +0 -0
  168. data/test/samples/lines.jpg +0 -0
  169. data/test/samples/messy0.jpg +0 -0
  170. data/test/samples/messy1.jpg +0 -0
  171. data/test/samples/movie_sample.avi +0 -0
  172. data/test/samples/one_way_train_0000.jpg +0 -0
  173. data/test/samples/one_way_train_0001.jpg +0 -0
  174. data/test/samples/partially_blank0.jpg +0 -0
  175. data/test/samples/partially_blank1.jpg +0 -0
  176. data/test/samples/smooth0.jpg +0 -0
  177. data/test/samples/smooth1.jpg +0 -0
  178. data/test/samples/smooth2.jpg +0 -0
  179. data/test/samples/smooth3.jpg +0 -0
  180. data/test/samples/smooth4.jpg +0 -0
  181. data/test/samples/smooth5.jpg +0 -0
  182. data/test/samples/smooth6.jpg +0 -0
  183. data/test/samples/str-cv-rotated.jpg +0 -0
  184. data/test/samples/str-cv.jpg +0 -0
  185. data/test/samples/str-ov.jpg +0 -0
  186. data/test/samples/stuff.jpg +0 -0
  187. data/test/test_curve.rb +43 -0
  188. data/test/test_cvavgcomp.rb +24 -0
  189. data/test/test_cvbox2d.rb +76 -0
  190. data/test/test_cvcapture.rb +183 -0
  191. data/test/test_cvchain.rb +108 -0
  192. data/test/test_cvcircle32f.rb +41 -0
  193. data/test/test_cvconnectedcomp.rb +61 -0
  194. data/test/test_cvcontour.rb +150 -0
  195. data/test/test_cvcontourtree.rb +43 -0
  196. data/test/test_cverror.rb +50 -0
  197. data/test/test_cvfeaturetree.rb +65 -0
  198. data/test/test_cvfont.rb +58 -0
  199. data/test/test_cvhaarclassifiercascade.rb +63 -0
  200. data/test/test_cvhistogram.rb +271 -0
  201. data/test/test_cvhumoments.rb +83 -0
  202. data/test/test_cvline.rb +50 -0
  203. data/test/test_cvmat.rb +2947 -0
  204. data/test/test_cvmat_drawing.rb +349 -0
  205. data/test/test_cvmat_dxt.rb +150 -0
  206. data/test/test_cvmat_imageprocessing.rb +2015 -0
  207. data/test/test_cvmat_matching.rb +57 -0
  208. data/test/test_cvmoments.rb +180 -0
  209. data/test/test_cvpoint.rb +75 -0
  210. data/test/test_cvpoint2d32f.rb +75 -0
  211. data/test/test_cvpoint3d32f.rb +93 -0
  212. data/test/test_cvrect.rb +144 -0
  213. data/test/test_cvscalar.rb +113 -0
  214. data/test/test_cvseq.rb +295 -0
  215. data/test/test_cvsize.rb +75 -0
  216. data/test/test_cvsize2d32f.rb +75 -0
  217. data/test/test_cvslice.rb +31 -0
  218. data/test/test_cvsurfparams.rb +57 -0
  219. data/test/test_cvsurfpoint.rb +66 -0
  220. data/test/test_cvtermcriteria.rb +56 -0
  221. data/test/test_cvtwopoints.rb +40 -0
  222. data/test/test_cvvideowriter.rb +58 -0
  223. data/test/test_iplconvkernel.rb +54 -0
  224. data/test/test_iplimage.rb +236 -0
  225. data/test/test_mouseevent.rb +17 -0
  226. data/test/test_opencv.rb +329 -0
  227. data/test/test_pointset.rb +126 -0
  228. data/test/test_preliminary.rb +130 -0
  229. data/test/test_trackbar.rb +47 -0
  230. data/test/test_window.rb +115 -0
  231. metadata +386 -0
data/examples/snake.rb ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # snake.rb
3
+ require "rubygems"
4
+ require "opencv"
5
+ include OpenCV
6
+
7
+ puts <<USAGE
8
+ usage:
9
+ left-click: set a point
10
+ right-click: do snake
11
+ USAGE
12
+
13
+ window = GUI::Window.new "snake demo"
14
+ image = CvMat.new(256, 256, :cv8u, 1).clear!
15
+ image.circle!(CvPoint.new(128,128), 40, :color => CvColor::White, :thickness => -1)
16
+ display = image.GRAY2BGR
17
+
18
+ window.show display
19
+
20
+ points = []
21
+
22
+ window.on_mouse{|mouse|
23
+ case mouse.event
24
+ when :left_button_down
25
+ display.circle!(mouse, 1, :color => CvColor::Red, :thickness => 2)
26
+ puts "set point (#{mouse.x},#{mouse.y})"
27
+ points << CvPoint.new(mouse.x, mouse.y)
28
+ window.show display
29
+ when :right_button_down
30
+ if points.length < 3
31
+ puts "please set more point!"
32
+ next
33
+ end
34
+ snake_points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
35
+ display = image.GRAY2BGR
36
+ display.poly_line!([snake_points], :color => CvColor::Red, :is_closed => true, :thickness => 2)
37
+ window.show display
38
+ points.clear
39
+ end
40
+ }
41
+
42
+ GUI::wait_key
43
+
Binary file
Binary file
@@ -0,0 +1,112 @@
1
+ /************************************************************
2
+
3
+ curve.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "curve.h"
11
+ /*
12
+ * Document-class: OpenCV::Curve
13
+ *
14
+ * Curve sequence.
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_CURVE
18
+
19
+ VALUE module;
20
+
21
+ VALUE
22
+ rb_module()
23
+ {
24
+ return module;
25
+ }
26
+
27
+ void
28
+ define_ruby_module()
29
+ {
30
+ if (module)
31
+ return;
32
+ /*
33
+ * opencv = rb_define_module("OpenCV");
34
+ *
35
+ * note: this comment is used by rdoc.
36
+ */
37
+ VALUE opencv = rb_module_opencv();
38
+ module = rb_define_module_under(opencv, "Curve");
39
+ rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
40
+ rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
41
+ rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
42
+ rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
43
+ rb_define_method(module, "arc_length", RUBY_METHOD_FUNC(rb_arc_length), -1);
44
+ }
45
+
46
+ /*
47
+ * If curve is closed, return true. Otherwise return false.
48
+ */
49
+ VALUE
50
+ rb_closed_q(VALUE self)
51
+ {
52
+ return CV_IS_SEQ_CLOSED(CVSEQ(self)) ? Qtrue : Qfalse;
53
+ }
54
+
55
+ /*
56
+ * If curve is convex, return true. Otherwise return false.
57
+ */
58
+ VALUE
59
+ rb_convex_q(VALUE self)
60
+ {
61
+ return CV_IS_SEQ_CONVEX(CVSEQ(self)) ? Qtrue : Qfalse;
62
+ }
63
+
64
+ /*
65
+ * If curve is hole(inner contour), return true. Otherwise return false.
66
+ */
67
+ VALUE
68
+ rb_hole_q(VALUE self)
69
+ {
70
+ return CV_IS_SEQ_HOLE(CVSEQ(self)) ? Qtrue : Qfalse;
71
+ }
72
+
73
+ /*
74
+ * no idia.
75
+ */
76
+ VALUE
77
+ rb_simple_q(VALUE self)
78
+ {
79
+ return CV_IS_SEQ_SIMPLE(CVSEQ(self)) ? Qtrue : Qfalse;
80
+ }
81
+
82
+ /*
83
+ * call-seq:
84
+ * arc_length(<i>[slice = nil][,is_closed = nil]</i>) -> float
85
+ *
86
+ * Calculates contour perimeter or curve length.
87
+ * <i>slice</i> is starting and ending points of the curve.
88
+ * <i>is_closed</i> is indicates whether the curve is closed or not. There are 3 cases:
89
+ * * is_closed = true - the curve is assumed to be unclosed.
90
+ * * is_closed = false - the curve is assumed to be closed.
91
+ * * is_closed = nil (default) use self#close?
92
+ */
93
+ VALUE
94
+ rb_arc_length(int argc, VALUE *argv, VALUE self)
95
+ {
96
+ VALUE slice, is_closed;
97
+ rb_scan_args(argc, argv, "02", &slice, &is_closed);
98
+ double length = 0;
99
+ try {
100
+ length = cvArcLength(CVARR(self),
101
+ NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
102
+ TRUE_OR_FALSE(is_closed, -1));
103
+ }
104
+ catch (cv::Exception& e) {
105
+ raise_cverror(e);
106
+ }
107
+ return rb_float_new(length);
108
+ }
109
+
110
+ __NAMESPACE_END_CURVE
111
+ __NAMESPACE_END_OPENCV
112
+
@@ -0,0 +1,34 @@
1
+ /************************************************************
2
+
3
+ curve.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVSEQ_CURVE_H
11
+ #define RUBY_OPENCV_CVSEQ_CURVE_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CURVE namespace mCurve {
16
+ #define __NAMESPACE_END_CURVE }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CURVE
20
+
21
+ VALUE rb_module();
22
+
23
+ void define_ruby_module();
24
+
25
+ VALUE rb_closed_q(VALUE self);
26
+ VALUE rb_convex_q(VALUE self);
27
+ VALUE rb_hole_q(VALUE self);
28
+ VALUE rb_simple_q(VALUE self);
29
+ VALUE rb_arc_length(int argc, VALUE *argv, VALUE self);
30
+
31
+ __NAMESPACE_END_CURVE
32
+ __NAMESPACE_END_OPENCV
33
+
34
+ #endif // RUBY_OPENCV_CVSEQ_CURVE_H
@@ -0,0 +1,67 @@
1
+ /************************************************************
2
+
3
+ cvavgcomp.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvavgcomp.h"
11
+ /*
12
+ * Document-class: OpenCV::CvAvgComp
13
+ *
14
+ * CvRect with parameter "neighbors".
15
+ * CvHaarClassifierCascade#detect_object.
16
+ *
17
+ * typedef struct CvAvgComp {
18
+ * CvRect rect;
19
+ * int neighbors;
20
+ * }
21
+ */
22
+ __NAMESPACE_BEGIN_OPENCV
23
+ __NAMESPACE_BEGIN_AVGCOMP
24
+
25
+ VALUE rb_klass;
26
+
27
+ VALUE
28
+ rb_class()
29
+ {
30
+ return rb_klass;
31
+ }
32
+
33
+ void
34
+ define_ruby_class()
35
+ {
36
+ if (rb_klass)
37
+ return;
38
+ /*
39
+ * opencv = rb_define_module("OpenCV");
40
+ * cvrect = rb_define_class_under(opencv, "CvRect", rb_cObject);
41
+ *
42
+ * note: this comment is used by rdoc.
43
+ */
44
+ VALUE opencv = rb_module_opencv(), cvrect = cCvRect::rb_class();
45
+ rb_klass = rb_define_class_under(opencv, "CvAvgComp", cvrect);
46
+ rb_define_alloc_func(rb_klass, rb_allocate);
47
+ rb_define_method(rb_klass, "neighbors", RUBY_METHOD_FUNC(rb_neighbors), 0);
48
+ }
49
+
50
+ VALUE
51
+ rb_allocate(VALUE klass)
52
+ {
53
+ CvAvgComp *ptr;
54
+ return Data_Make_Struct(klass, CvAvgComp, 0, -1, ptr);
55
+ }
56
+
57
+ /*
58
+ * Return neighbors.
59
+ */
60
+ VALUE
61
+ rb_neighbors(VALUE self)
62
+ {
63
+ return INT2NUM(CVAVGCOMP(self)->neighbors);
64
+ }
65
+
66
+ __NAMESPACE_END_AVGCOMP
67
+ __NAMESPACE_END_OPENCV
@@ -0,0 +1,39 @@
1
+ /**********************************************************************
2
+
3
+ cvavgcomp.h
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ **********************************************************************/
10
+ #ifndef RUBY_OPENCV_AVGCOMP_H
11
+ #define RUBY_OPENCV_AVGCOMP_H
12
+
13
+ #define __NAMESPACE_BEGIN_AVGCOMP namespace cCvAvgComp {
14
+ #define __NAMESPACE_END_AVGCOMP }
15
+
16
+ #include <opencv.h>
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_AVGCOMP
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_allocate(VALUE klass);
26
+ VALUE rb_neighbors(VALUE self);
27
+
28
+ __NAMESPACE_END_AVGCOMP
29
+
30
+ inline CvAvgComp *CVAVGCOMP(VALUE object){
31
+ CvAvgComp *ptr;
32
+ Data_Get_Struct(object, CvAvgComp, ptr);
33
+ return ptr;
34
+ }
35
+
36
+ __NAMESPACE_END_OPENCV
37
+
38
+
39
+ #endif // RUBY_OPENCV_AVGCOMP_H
@@ -0,0 +1,197 @@
1
+ /************************************************************
2
+
3
+ cvbox2d.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "cvbox2d.h"
11
+ /*
12
+ * Document-class: OpenCV::CvBox2D
13
+ *
14
+ * C structure is here.
15
+ * typdef struct CvBox2D {
16
+ * CvPoint2D32f center; // center of the box.
17
+ * CvSize2D32f size; // box width and length
18
+ * float angle; // angle between the horizonal axis and the first side (i.e length) in radians
19
+ * } CvBox2D;
20
+ */
21
+ __NAMESPACE_BEGIN_OPENCV
22
+ __NAMESPACE_BEGIN_CVBOX2D
23
+
24
+ VALUE rb_klass;
25
+
26
+ VALUE
27
+ rb_class()
28
+ {
29
+ return rb_klass;
30
+ }
31
+
32
+ void
33
+ define_ruby_class()
34
+ {
35
+ if (rb_klass)
36
+ return;
37
+ /*
38
+ * opencv = rb_define_module("OpenCV");
39
+ *
40
+ * note: this comment is used by rdoc.
41
+ */
42
+ VALUE opencv = rb_module_opencv();
43
+ rb_klass = rb_define_class_under(opencv, "CvBox2D", rb_cObject);
44
+ rb_define_alloc_func(rb_klass, rb_allocate);
45
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
46
+ rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
47
+ rb_define_method(rb_klass, "center=", RUBY_METHOD_FUNC(rb_set_center), 1);
48
+ rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
49
+ rb_define_method(rb_klass, "size=", RUBY_METHOD_FUNC(rb_set_size), 1);
50
+ rb_define_method(rb_klass, "angle", RUBY_METHOD_FUNC(rb_angle), 0);
51
+ rb_define_method(rb_klass, "angle=", RUBY_METHOD_FUNC(rb_set_angle), 1);
52
+ rb_define_method(rb_klass, "points", RUBY_METHOD_FUNC(rb_points), 0);
53
+ }
54
+
55
+ VALUE
56
+ rb_allocate(VALUE klass)
57
+ {
58
+ CvBox2D *ptr;
59
+ return Data_Make_Struct(klass, CvBox2D, 0, -1, ptr);
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * CvBox2D.new(<i>[center][, size][, angle]</i>) -> cvbox2d
65
+ *
66
+ * Create a box
67
+ */
68
+ VALUE
69
+ rb_initialize(int argc, VALUE *argv, VALUE self)
70
+ {
71
+ VALUE center, size, angle;
72
+ CvBox2D* self_ptr = CVBOX2D(self);
73
+ rb_scan_args(argc, argv, "03", &center, &size, &angle);
74
+
75
+ if (!NIL_P(center)) {
76
+ self_ptr->center = VALUE_TO_CVPOINT2D32F(center);
77
+ }
78
+ if (!NIL_P(size)) {
79
+ self_ptr->size = VALUE_TO_CVSIZE2D32F(size);
80
+ self_ptr->angle = NUM2DBL(angle);
81
+ }
82
+
83
+ return self;
84
+ }
85
+
86
+ /*
87
+ * call-seq:
88
+ * center -> cvpoint2d32f
89
+ * Return center point of box as CvPoint2D32f.
90
+ */
91
+ VALUE
92
+ rb_center(VALUE self)
93
+ {
94
+ return REFER_OBJECT(cCvPoint2D32f::rb_class(), &CVBOX2D(self)->center, self);
95
+ }
96
+
97
+ /*
98
+ * call-seq:
99
+ * center = <i>value</i>
100
+ *
101
+ * Set center to <i>value</i>
102
+ */
103
+ VALUE
104
+ rb_set_center(VALUE self, VALUE value)
105
+ {
106
+ CVBOX2D(self)->center = VALUE_TO_CVPOINT2D32F(value);
107
+ return self;
108
+ }
109
+
110
+ /*
111
+ * call-seq:
112
+ * size -> cvsize2d32f
113
+ * Return size of box as CvSize2D32f.
114
+ */
115
+ VALUE
116
+ rb_size(VALUE self)
117
+ {
118
+ return REFER_OBJECT(cCvSize2D32f::rb_class(), &CVBOX2D(self)->size, self);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * size = <i>value</i>
124
+ *
125
+ * Set size to <i>value</i>
126
+ */
127
+ VALUE
128
+ rb_set_size(VALUE self, VALUE value)
129
+ {
130
+ CVBOX2D(self)->size = VALUE_TO_CVSIZE2D32F(value);
131
+ return self;
132
+ }
133
+
134
+ /*
135
+ * call-seq:
136
+ * angle -> float
137
+ *
138
+ * Return angle of box as Float.
139
+ */
140
+ VALUE
141
+ rb_angle(VALUE self)
142
+ {
143
+ return rb_float_new(CVBOX2D(self)->angle);
144
+ }
145
+
146
+ /*
147
+ * call-seq:
148
+ * angle = <i>value</i>
149
+ *
150
+ * Set angle to <i>value</i>
151
+ */
152
+ VALUE
153
+ rb_set_angle(VALUE self, VALUE value)
154
+ {
155
+ CVBOX2D(self)->angle = NUM2DBL(value);
156
+ return self;
157
+ }
158
+
159
+ /*
160
+ * call-seq:
161
+ * points -> array(include cvpoint2d32f)
162
+ * Find box vertices. Return Array contain 4 CvPoint2D32f.
163
+ */
164
+ VALUE
165
+ rb_points(VALUE self)
166
+ {
167
+ const int n = 4;
168
+ CvPoint2D32f p[n];
169
+ try {
170
+ cvBoxPoints(*CVBOX2D(self), p);
171
+ }
172
+ catch (cv::Exception& e) {
173
+ raise_cverror(e);
174
+ }
175
+ VALUE points = rb_ary_new2(n);
176
+ for (int i = 0; i < n; ++i) {
177
+ rb_ary_store(points, i, cCvPoint2D32f::new_object(p[i]));
178
+ }
179
+ return points;
180
+ }
181
+
182
+ VALUE
183
+ new_object()
184
+ {
185
+ return rb_allocate(cCvBox2D::rb_class());
186
+ }
187
+
188
+ VALUE
189
+ new_object(CvBox2D box)
190
+ {
191
+ VALUE object = rb_allocate(rb_klass);
192
+ *CVBOX2D(object) = box;
193
+ return object;
194
+ }
195
+
196
+ __NAMESPACE_END_CVBOX2D
197
+ __NAMESPACE_END_OPENCV