ruby-opencv 0.0.9-x86-mswin32 → 0.0.10.pre-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/History.txt +5 -5
  4. data/README.md +1 -1
  5. data/examples/contours/contour_retrieval_modes.rb +139 -139
  6. data/examples/face_detect.rb +20 -20
  7. data/examples/houghcircle.rb +22 -22
  8. data/examples/paint.rb +70 -70
  9. data/examples/snake.rb +43 -43
  10. data/ext/opencv/cvcondensation.cpp +282 -282
  11. data/ext/opencv/cvcondensation.h +49 -49
  12. data/ext/opencv/cvmat.cpp +6 -6
  13. data/ext/opencv/cvmatnd.cpp +44 -44
  14. data/ext/opencv/cvmatnd.h +28 -28
  15. data/ext/opencv/cvmemstorage.cpp +68 -68
  16. data/ext/opencv/cvmemstorage.h +53 -53
  17. data/ext/opencv/cvmoments.h +75 -75
  18. data/ext/opencv/cvpoint.h +64 -64
  19. data/ext/opencv/cvpoint2d32f.h +63 -63
  20. data/ext/opencv/cvpoint3d32f.h +66 -66
  21. data/ext/opencv/cvrect.h +79 -79
  22. data/ext/opencv/cvscalar.h +71 -71
  23. data/ext/opencv/cvsize.h +65 -65
  24. data/ext/opencv/cvsize2d32f.h +64 -64
  25. data/ext/opencv/cvslice.h +61 -61
  26. data/ext/opencv/cvsparsemat.cpp +44 -44
  27. data/ext/opencv/cvsparsemat.h +28 -28
  28. data/ext/opencv/cvsurfparams.h +58 -58
  29. data/ext/opencv/cvsurfpoint.h +52 -52
  30. data/ext/opencv/cvtermcriteria.h +71 -71
  31. data/ext/opencv/cvtwopoints.cpp +116 -116
  32. data/ext/opencv/cvtwopoints.h +51 -51
  33. data/ext/opencv/cvvideowriter.h +43 -43
  34. data/ext/opencv/gui.cpp +68 -68
  35. data/ext/opencv/gui.h +30 -30
  36. data/ext/opencv/iplconvkernel.h +71 -71
  37. data/ext/opencv/mouseevent.cpp +181 -181
  38. data/ext/opencv/mouseevent.h +56 -56
  39. data/ext/opencv/opencv.cpp +5 -0
  40. data/ext/opencv/trackbar.h +69 -69
  41. data/ext/opencv/window.h +66 -66
  42. data/lib/opencv/version.rb +1 -1
  43. data/ruby-opencv.gemspec +7 -7
  44. data/test/test_cvmat_imageprocessing.rb +15 -25
  45. data/test/test_opencv.rb +7 -2
  46. metadata +7 -7
@@ -1,43 +1,43 @@
1
- /************************************************************
2
-
3
- cvvideowriter.h -
4
-
5
- $Author: lsxi $
6
-
7
- Copyright (C) 2005-2006 Masakazu Yonekura
8
-
9
- ************************************************************/
10
- #ifndef RUBY_OPENCV_CVVIDEOWRITER_H
11
- #define RUBY_OPENCV_CVVIDEOWRITER_H
12
-
13
- #include "opencv.h"
14
-
15
- #define __NAMESPACE_BEGIN_CVVIDEOWRITER namespace cCvVideoWriter {
16
- #define __NAMESPACE_END_CVVIDEOWRITER }
17
-
18
- __NAMESPACE_BEGIN_OPENCV
19
- __NAMESPACE_BEGIN_CVVIDEOWRITER
20
-
21
- VALUE rb_class();
22
-
23
- void define_ruby_class();
24
-
25
- VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
26
- VALUE rb_write(VALUE self, VALUE frame);
27
- VALUE rb_close(VALUE self);
28
-
29
- __NAMESPACE_END_CVVIDEOWRITER
30
-
31
- inline CvVideoWriter*
32
- CVVIDEOWRITER(VALUE object)
33
- {
34
- // CvVideoWriter is
35
- // CvVideoWriter *ptr;
36
- // Data_Get_Struct(object, CvVideoWriter, ptr);
37
- // return ptr;
38
- return (CvVideoWriter*)DATA_PTR(object);
39
- }
40
-
41
- __NAMESPACE_END_OPENCV
42
-
43
- #endif // RUBY_OPENCV_CVVIDEOWRITER_H
1
+ /************************************************************
2
+
3
+ cvvideowriter.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_CVVIDEOWRITER_H
11
+ #define RUBY_OPENCV_CVVIDEOWRITER_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_CVVIDEOWRITER namespace cCvVideoWriter {
16
+ #define __NAMESPACE_END_CVVIDEOWRITER }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_CVVIDEOWRITER
20
+
21
+ VALUE rb_class();
22
+
23
+ void define_ruby_class();
24
+
25
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
26
+ VALUE rb_write(VALUE self, VALUE frame);
27
+ VALUE rb_close(VALUE self);
28
+
29
+ __NAMESPACE_END_CVVIDEOWRITER
30
+
31
+ inline CvVideoWriter*
32
+ CVVIDEOWRITER(VALUE object)
33
+ {
34
+ // CvVideoWriter is
35
+ // CvVideoWriter *ptr;
36
+ // Data_Get_Struct(object, CvVideoWriter, ptr);
37
+ // return ptr;
38
+ return (CvVideoWriter*)DATA_PTR(object);
39
+ }
40
+
41
+ __NAMESPACE_END_OPENCV
42
+
43
+ #endif // RUBY_OPENCV_CVVIDEOWRITER_H
@@ -1,68 +1,68 @@
1
- /************************************************************
2
-
3
- gui.cpp -
4
-
5
- $Author: lsxi $
6
-
7
- Copyright (C) 2005-2006 Masakazu Yonekura
8
-
9
- ************************************************************/
10
- #include "gui.h"
11
- /*
12
- * Document-module: OpenCV::GUI
13
- *
14
- * OpenCV simple GUI interface. Provides Window, Trackbar.
15
- * This GUI work on GTK or Microsoft Windows native GUI.
16
- */
17
- __NAMESPACE_BEGIN_OPENCV
18
- __NAMESPACE_BEGIN_GUI
19
-
20
- VALUE rb_module;
21
-
22
- VALUE
23
- rb_module_GUI()
24
- {
25
- return rb_module;
26
- }
27
-
28
- void
29
- define_ruby_module()
30
- {
31
- if (rb_module)
32
- return;
33
- /*
34
- * opencv = rb_define_module("OpenCV");
35
- *
36
- * note: this comment is used by rdoc.
37
- */
38
- VALUE opencv = rb_module_opencv();
39
- rb_module = rb_define_module_under(opencv, "GUI");
40
- rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
41
- }
42
-
43
- /*
44
- * call-seq:
45
- * wait_key(<i>[delay]</i>) -> int or nil
46
- *
47
- * Waits for a pressed key each GUI wedget.
48
- * Return the code of the pressed key or nil if no key were pressed until the specified timeout has elapsed.
49
- * <i>delay</i> should be Fixnum. Wait <i>delay</i> millisecond.
50
- */
51
- VALUE
52
- rb_wait_key(int argc, VALUE *argv, VALUE self)
53
- {
54
- VALUE delay;
55
- rb_scan_args(argc, argv, "01", &delay);
56
- int keycode = 0;
57
- try {
58
- keycode = cvWaitKey(IF_INT(delay, 0));
59
- }
60
- catch (cv::Exception& e) {
61
- raise_cverror(e);
62
- }
63
- return (keycode < 0) ? Qnil : INT2NUM(keycode);
64
- }
65
-
66
- __NAMESPACE_END_GUI
67
- __NAMESPACE_END_OPENCV
68
-
1
+ /************************************************************
2
+
3
+ gui.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "gui.h"
11
+ /*
12
+ * Document-module: OpenCV::GUI
13
+ *
14
+ * OpenCV simple GUI interface. Provides Window, Trackbar.
15
+ * This GUI work on GTK or Microsoft Windows native GUI.
16
+ */
17
+ __NAMESPACE_BEGIN_OPENCV
18
+ __NAMESPACE_BEGIN_GUI
19
+
20
+ VALUE rb_module;
21
+
22
+ VALUE
23
+ rb_module_GUI()
24
+ {
25
+ return rb_module;
26
+ }
27
+
28
+ void
29
+ define_ruby_module()
30
+ {
31
+ if (rb_module)
32
+ return;
33
+ /*
34
+ * opencv = rb_define_module("OpenCV");
35
+ *
36
+ * note: this comment is used by rdoc.
37
+ */
38
+ VALUE opencv = rb_module_opencv();
39
+ rb_module = rb_define_module_under(opencv, "GUI");
40
+ rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * wait_key(<i>[delay]</i>) -> int or nil
46
+ *
47
+ * Waits for a pressed key each GUI wedget.
48
+ * Return the code of the pressed key or nil if no key were pressed until the specified timeout has elapsed.
49
+ * <i>delay</i> should be Fixnum. Wait <i>delay</i> millisecond.
50
+ */
51
+ VALUE
52
+ rb_wait_key(int argc, VALUE *argv, VALUE self)
53
+ {
54
+ VALUE delay;
55
+ rb_scan_args(argc, argv, "01", &delay);
56
+ int keycode = 0;
57
+ try {
58
+ keycode = cvWaitKey(IF_INT(delay, 0));
59
+ }
60
+ catch (cv::Exception& e) {
61
+ raise_cverror(e);
62
+ }
63
+ return (keycode < 0) ? Qnil : INT2NUM(keycode);
64
+ }
65
+
66
+ __NAMESPACE_END_GUI
67
+ __NAMESPACE_END_OPENCV
68
+
@@ -1,30 +1,30 @@
1
- /************************************************************
2
-
3
- gui.h -
4
-
5
- $Author: lsxi $
6
-
7
- Copyright (C) 2005-2006 Masakazu Yonekura
8
-
9
- ************************************************************/
10
- #ifndef RUBY_OPENCV_GUI_H
11
- #define RUBY_OPENCV_GUI_H
12
-
13
- #define __NAMESPACE_BEGIN_GUI namespace mGUI {
14
- #define __NAMESPACE_END_GUI }
15
-
16
- #include "opencv.h"
17
-
18
- __NAMESPACE_BEGIN_OPENCV
19
- __NAMESPACE_BEGIN_GUI
20
-
21
- VALUE rb_module_GUI();
22
- void define_ruby_module();
23
-
24
- VALUE rb_wait_key(int argc, VALUE *argv, VALUE self);
25
-
26
- __NAMESPACE_END_GUI
27
- __NAMESPACE_END_OPENCV
28
-
29
- #endif // RUBY_OPENCV_GUI_H
30
-
1
+ /************************************************************
2
+
3
+ gui.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_GUI_H
11
+ #define RUBY_OPENCV_GUI_H
12
+
13
+ #define __NAMESPACE_BEGIN_GUI namespace mGUI {
14
+ #define __NAMESPACE_END_GUI }
15
+
16
+ #include "opencv.h"
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_GUI
20
+
21
+ VALUE rb_module_GUI();
22
+ void define_ruby_module();
23
+
24
+ VALUE rb_wait_key(int argc, VALUE *argv, VALUE self);
25
+
26
+ __NAMESPACE_END_GUI
27
+ __NAMESPACE_END_OPENCV
28
+
29
+ #endif // RUBY_OPENCV_GUI_H
30
+
@@ -1,71 +1,71 @@
1
- /************************************************************
2
-
3
- iplconvkernel.h -
4
-
5
- $Author: lsxi $
6
-
7
- Copyright (C) 2005-2006 Masakazu Yonekura
8
-
9
- ************************************************************/
10
- #ifndef RUBY_OPENCV_IPLCONVKERNEL_H
11
- #define RUBY_OPENCV_IPLCONVKERNEL_H
12
-
13
- #include "opencv.h"
14
-
15
- #define __NAMESPACE_BEGIN_IPLCONVKERNEL namespace cIplConvKernel {
16
- #define __NAMESPACE_END_IPLCONVKERNEL }
17
-
18
- __NAMESPACE_BEGIN_OPENCV
19
- __NAMESPACE_BEGIN_IPLCONVKERNEL
20
-
21
- VALUE rb_class();
22
- VALUE rb_allocate(VALUE klass);
23
-
24
- void define_ruby_class();
25
- VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
26
- VALUE rb_size(VALUE self);
27
- VALUE rb_cols(VALUE self);
28
- VALUE rb_rows(VALUE self);
29
- VALUE rb_anchor(VALUE self);
30
- VALUE rb_anchor_x(VALUE self);
31
- VALUE rb_anchor_y(VALUE self);
32
-
33
- __NAMESPACE_END_IPLCONVKERNEL
34
-
35
- inline IplConvKernel*
36
- IPLCONVKERNEL(VALUE object)
37
- {
38
- IplConvKernel *ptr;
39
- Data_Get_Struct(object, IplConvKernel, ptr);
40
- return ptr;
41
- }
42
-
43
- inline IplConvKernel*
44
- IPLCONVKERNEL_WITH_CHECK(VALUE object)
45
- {
46
- if (!rb_obj_is_kind_of(object, cIplConvKernel::rb_class()))
47
- raise_typeerror(object, cIplConvKernel::rb_class());
48
- return IPLCONVKERNEL(object);
49
- }
50
-
51
- /*
52
- inline IplConvKernel*
53
- IPLCONVKERNEL(VALUE object)
54
- {
55
- IplConvKernel *ptr;
56
- if (NIL_P(object))
57
- return NULL;
58
- else if (rb_obj_is_kind_of(object, cIplConvKernel::rb_class())) {
59
- Data_Get_Struct(object, IplConvKernel, ptr);
60
- return ptr;
61
- }
62
- else {
63
- rb_warn("invalid kernel. use default kernel (3x3 rectangle).");
64
- return NULL;
65
- }
66
- }
67
- */
68
-
69
- __NAMESPACE_END_OPENCV
70
-
71
- #endif // RUBY_OPENCV_IPLCONVKERNEL_H
1
+ /************************************************************
2
+
3
+ iplconvkernel.h -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2006 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #ifndef RUBY_OPENCV_IPLCONVKERNEL_H
11
+ #define RUBY_OPENCV_IPLCONVKERNEL_H
12
+
13
+ #include "opencv.h"
14
+
15
+ #define __NAMESPACE_BEGIN_IPLCONVKERNEL namespace cIplConvKernel {
16
+ #define __NAMESPACE_END_IPLCONVKERNEL }
17
+
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_IPLCONVKERNEL
20
+
21
+ VALUE rb_class();
22
+ VALUE rb_allocate(VALUE klass);
23
+
24
+ void define_ruby_class();
25
+ VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
26
+ VALUE rb_size(VALUE self);
27
+ VALUE rb_cols(VALUE self);
28
+ VALUE rb_rows(VALUE self);
29
+ VALUE rb_anchor(VALUE self);
30
+ VALUE rb_anchor_x(VALUE self);
31
+ VALUE rb_anchor_y(VALUE self);
32
+
33
+ __NAMESPACE_END_IPLCONVKERNEL
34
+
35
+ inline IplConvKernel*
36
+ IPLCONVKERNEL(VALUE object)
37
+ {
38
+ IplConvKernel *ptr;
39
+ Data_Get_Struct(object, IplConvKernel, ptr);
40
+ return ptr;
41
+ }
42
+
43
+ inline IplConvKernel*
44
+ IPLCONVKERNEL_WITH_CHECK(VALUE object)
45
+ {
46
+ if (!rb_obj_is_kind_of(object, cIplConvKernel::rb_class()))
47
+ raise_typeerror(object, cIplConvKernel::rb_class());
48
+ return IPLCONVKERNEL(object);
49
+ }
50
+
51
+ /*
52
+ inline IplConvKernel*
53
+ IPLCONVKERNEL(VALUE object)
54
+ {
55
+ IplConvKernel *ptr;
56
+ if (NIL_P(object))
57
+ return NULL;
58
+ else if (rb_obj_is_kind_of(object, cIplConvKernel::rb_class())) {
59
+ Data_Get_Struct(object, IplConvKernel, ptr);
60
+ return ptr;
61
+ }
62
+ else {
63
+ rb_warn("invalid kernel. use default kernel (3x3 rectangle).");
64
+ return NULL;
65
+ }
66
+ }
67
+ */
68
+
69
+ __NAMESPACE_END_OPENCV
70
+
71
+ #endif // RUBY_OPENCV_IPLCONVKERNEL_H
@@ -1,181 +1,181 @@
1
- /************************************************************
2
-
3
- mouseevent.cpp -
4
-
5
- $Author: lsxi $
6
-
7
- Copyright (C) 2005-2007 Masakazu Yonekura
8
-
9
- ************************************************************/
10
- #include "mouseevent.h"
11
- /*
12
- * Document-module: OpenCV::GUI::MouseEvent
13
- *
14
- * MouseEvent object.
15
- * have
16
- * see OpenCV::GUI::Window#set_mouse_callback.
17
- */
18
- __NAMESPACE_BEGIN_OPENCV
19
- __NAMESPACE_BEGIN_GUI
20
- __NAMESPACE_BEGIN_MOUSEEVENT
21
-
22
- VALUE rb_klass;
23
-
24
- VALUE
25
- rb_class()
26
- {
27
- return rb_klass;
28
- }
29
-
30
- void
31
- define_ruby_class()
32
- {
33
- if (rb_klass)
34
- return;
35
- /*
36
- * opencv = rb_define_module("OpenCV");
37
- * GUI = rb_define_module_under(opencv, "GUI");
38
- * cvpoint = rb_define_class_under(opencv, "CvPoint", rb_cObject);
39
- */
40
- VALUE GUI = rb_module_GUI();
41
- VALUE cvpoint = cCvPoint::rb_class();
42
- rb_klass = rb_define_class_under(GUI, "MouseEvent", cvpoint);
43
- rb_define_alloc_func(rb_klass, rb_allocate);
44
- rb_define_method(rb_klass, "event", RUBY_METHOD_FUNC(rb_event), 0);
45
- rb_define_method(rb_klass, "left_button?", RUBY_METHOD_FUNC(rb_left_button_q), 0);
46
- rb_define_method(rb_klass, "right_button?", RUBY_METHOD_FUNC(rb_right_button_q), 0);
47
- rb_define_method(rb_klass, "middle_button?", RUBY_METHOD_FUNC(rb_middle_button_q), 0);
48
- rb_define_method(rb_klass, "ctrl_key?", RUBY_METHOD_FUNC(rb_ctrl_key_q), 0);
49
- rb_define_method(rb_klass, "shift_key?", RUBY_METHOD_FUNC(rb_shift_key_q), 0);
50
- rb_define_method(rb_klass, "alt_key?", RUBY_METHOD_FUNC(rb_alt_key_q), 0);
51
- }
52
-
53
- VALUE
54
- rb_allocate(VALUE klass)
55
- {
56
- MouseEvent *ptr;
57
- return Data_Make_Struct(klass, MouseEvent, 0, 0, ptr);
58
- }
59
-
60
- /*
61
- * call-seq:
62
- * event -> symbol
63
- *
64
- * Return Symbol about mouse event.
65
- *
66
- * Currently, return these symbol:
67
- * :move
68
- * When mouse move.
69
- * :right_button_down
70
- * When mouse right button down.
71
- * :left_button_down
72
- * When mosue left button down.
73
- * :middle_button_down
74
- * When mosue middle button down.
75
- * :left_button_up
76
- * When mouse left button down.
77
- * :right_button_up
78
- * When mouse right button down.
79
- * :middle_button_up
80
- * When mouse middle button down.
81
- *
82
- * note: original OpenCV define "double-click" event(e.g. CV_EVENT_LBUTTONDBLCLK).
83
- * But never call these event. Is it bug?
84
- */
85
- VALUE rb_event(VALUE self)
86
- {
87
- switch(MOUSEEVENT(self)->event) {
88
- case CV_EVENT_MOUSEMOVE:
89
- return ID2SYM(rb_intern("move"));
90
- case CV_EVENT_LBUTTONDOWN:
91
- return ID2SYM(rb_intern("left_button_down"));
92
- case CV_EVENT_RBUTTONDOWN:
93
- return ID2SYM(rb_intern("right_button_down"));
94
- case CV_EVENT_MBUTTONDOWN:
95
- return ID2SYM(rb_intern("middle_button_down"));
96
- case CV_EVENT_LBUTTONUP:
97
- return ID2SYM(rb_intern("left_button_up"));
98
- case CV_EVENT_RBUTTONUP:
99
- return ID2SYM(rb_intern("right_button_up"));
100
- case CV_EVENT_MBUTTONUP:
101
- return ID2SYM(rb_intern("middle_button_up"));
102
- case CV_EVENT_LBUTTONDBLCLK:
103
- return ID2SYM(rb_intern("left_button_double_click"));
104
- case CV_EVENT_RBUTTONDBLCLK:
105
- return ID2SYM(rb_intern("right_button_double_click"));
106
- case CV_EVENT_MBUTTONDBLCLK:
107
- return ID2SYM(rb_intern("middle_button_double_click"));
108
- }
109
- return Qnil;
110
- }
111
-
112
- /*
113
- * Return true when mouse left button is pushed. Otherwise return false.
114
- */
115
- VALUE
116
- rb_left_button_q(VALUE self)
117
- {
118
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_LBUTTON ? Qtrue : Qfalse;
119
- }
120
-
121
- /*
122
- * Return true when mouse right button is pushed. Otherwise return false.
123
- */
124
- VALUE
125
- rb_right_button_q(VALUE self)
126
- {
127
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_RBUTTON ? Qtrue : Qfalse;
128
- }
129
-
130
- /*
131
- * Return true when mouse middle button is pushed. Otherwise return false.
132
- */
133
- VALUE
134
- rb_middle_button_q(VALUE self)
135
- {
136
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_MBUTTON ? Qtrue : Qfalse;
137
- }
138
-
139
- /*
140
- * Return true when CTRL key is pushed. Otherwise return false.
141
- */
142
- VALUE
143
- rb_ctrl_key_q(VALUE self)
144
- {
145
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_CTRLKEY ? Qtrue : Qfalse;
146
- }
147
-
148
- /*
149
- * Return true when shift key is pushed. Otherwise return false.
150
- */
151
- VALUE
152
- rb_shift_key_q(VALUE self)
153
- {
154
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_SHIFTKEY ? Qtrue : Qfalse;
155
- }
156
-
157
- /*
158
- * Return true when ALT key is pushed. Otherwise return false.
159
- */
160
- VALUE
161
- rb_alt_key_q(VALUE self)
162
- {
163
- return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_ALTKEY ? Qtrue : Qfalse;
164
- }
165
-
166
- VALUE
167
- new_object(int event, int x, int y, int flags)
168
- {
169
- VALUE object = rb_allocate(rb_class());
170
- MouseEvent *mouseevent = MOUSEEVENT(object);
171
- mouseevent->point.x = x;
172
- mouseevent->point.y = y;
173
- mouseevent->event = event;
174
- mouseevent->flags = flags;
175
- return object;
176
- }
177
-
178
- __NAMESPACE_END_MOUSEEVENT
179
- __NAMESPACE_END_GUI
180
- __NAMESPACE_END_OPENCV
181
-
1
+ /************************************************************
2
+
3
+ mouseevent.cpp -
4
+
5
+ $Author: lsxi $
6
+
7
+ Copyright (C) 2005-2007 Masakazu Yonekura
8
+
9
+ ************************************************************/
10
+ #include "mouseevent.h"
11
+ /*
12
+ * Document-module: OpenCV::GUI::MouseEvent
13
+ *
14
+ * MouseEvent object.
15
+ * have
16
+ * see OpenCV::GUI::Window#set_mouse_callback.
17
+ */
18
+ __NAMESPACE_BEGIN_OPENCV
19
+ __NAMESPACE_BEGIN_GUI
20
+ __NAMESPACE_BEGIN_MOUSEEVENT
21
+
22
+ VALUE rb_klass;
23
+
24
+ VALUE
25
+ rb_class()
26
+ {
27
+ return rb_klass;
28
+ }
29
+
30
+ void
31
+ define_ruby_class()
32
+ {
33
+ if (rb_klass)
34
+ return;
35
+ /*
36
+ * opencv = rb_define_module("OpenCV");
37
+ * GUI = rb_define_module_under(opencv, "GUI");
38
+ * cvpoint = rb_define_class_under(opencv, "CvPoint", rb_cObject);
39
+ */
40
+ VALUE GUI = rb_module_GUI();
41
+ VALUE cvpoint = cCvPoint::rb_class();
42
+ rb_klass = rb_define_class_under(GUI, "MouseEvent", cvpoint);
43
+ rb_define_alloc_func(rb_klass, rb_allocate);
44
+ rb_define_method(rb_klass, "event", RUBY_METHOD_FUNC(rb_event), 0);
45
+ rb_define_method(rb_klass, "left_button?", RUBY_METHOD_FUNC(rb_left_button_q), 0);
46
+ rb_define_method(rb_klass, "right_button?", RUBY_METHOD_FUNC(rb_right_button_q), 0);
47
+ rb_define_method(rb_klass, "middle_button?", RUBY_METHOD_FUNC(rb_middle_button_q), 0);
48
+ rb_define_method(rb_klass, "ctrl_key?", RUBY_METHOD_FUNC(rb_ctrl_key_q), 0);
49
+ rb_define_method(rb_klass, "shift_key?", RUBY_METHOD_FUNC(rb_shift_key_q), 0);
50
+ rb_define_method(rb_klass, "alt_key?", RUBY_METHOD_FUNC(rb_alt_key_q), 0);
51
+ }
52
+
53
+ VALUE
54
+ rb_allocate(VALUE klass)
55
+ {
56
+ MouseEvent *ptr;
57
+ return Data_Make_Struct(klass, MouseEvent, 0, 0, ptr);
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * event -> symbol
63
+ *
64
+ * Return Symbol about mouse event.
65
+ *
66
+ * Currently, return these symbol:
67
+ * :move
68
+ * When mouse move.
69
+ * :right_button_down
70
+ * When mouse right button down.
71
+ * :left_button_down
72
+ * When mosue left button down.
73
+ * :middle_button_down
74
+ * When mosue middle button down.
75
+ * :left_button_up
76
+ * When mouse left button down.
77
+ * :right_button_up
78
+ * When mouse right button down.
79
+ * :middle_button_up
80
+ * When mouse middle button down.
81
+ *
82
+ * note: original OpenCV define "double-click" event(e.g. CV_EVENT_LBUTTONDBLCLK).
83
+ * But never call these event. Is it bug?
84
+ */
85
+ VALUE rb_event(VALUE self)
86
+ {
87
+ switch(MOUSEEVENT(self)->event) {
88
+ case CV_EVENT_MOUSEMOVE:
89
+ return ID2SYM(rb_intern("move"));
90
+ case CV_EVENT_LBUTTONDOWN:
91
+ return ID2SYM(rb_intern("left_button_down"));
92
+ case CV_EVENT_RBUTTONDOWN:
93
+ return ID2SYM(rb_intern("right_button_down"));
94
+ case CV_EVENT_MBUTTONDOWN:
95
+ return ID2SYM(rb_intern("middle_button_down"));
96
+ case CV_EVENT_LBUTTONUP:
97
+ return ID2SYM(rb_intern("left_button_up"));
98
+ case CV_EVENT_RBUTTONUP:
99
+ return ID2SYM(rb_intern("right_button_up"));
100
+ case CV_EVENT_MBUTTONUP:
101
+ return ID2SYM(rb_intern("middle_button_up"));
102
+ case CV_EVENT_LBUTTONDBLCLK:
103
+ return ID2SYM(rb_intern("left_button_double_click"));
104
+ case CV_EVENT_RBUTTONDBLCLK:
105
+ return ID2SYM(rb_intern("right_button_double_click"));
106
+ case CV_EVENT_MBUTTONDBLCLK:
107
+ return ID2SYM(rb_intern("middle_button_double_click"));
108
+ }
109
+ return Qnil;
110
+ }
111
+
112
+ /*
113
+ * Return true when mouse left button is pushed. Otherwise return false.
114
+ */
115
+ VALUE
116
+ rb_left_button_q(VALUE self)
117
+ {
118
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_LBUTTON ? Qtrue : Qfalse;
119
+ }
120
+
121
+ /*
122
+ * Return true when mouse right button is pushed. Otherwise return false.
123
+ */
124
+ VALUE
125
+ rb_right_button_q(VALUE self)
126
+ {
127
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_RBUTTON ? Qtrue : Qfalse;
128
+ }
129
+
130
+ /*
131
+ * Return true when mouse middle button is pushed. Otherwise return false.
132
+ */
133
+ VALUE
134
+ rb_middle_button_q(VALUE self)
135
+ {
136
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_MBUTTON ? Qtrue : Qfalse;
137
+ }
138
+
139
+ /*
140
+ * Return true when CTRL key is pushed. Otherwise return false.
141
+ */
142
+ VALUE
143
+ rb_ctrl_key_q(VALUE self)
144
+ {
145
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_CTRLKEY ? Qtrue : Qfalse;
146
+ }
147
+
148
+ /*
149
+ * Return true when shift key is pushed. Otherwise return false.
150
+ */
151
+ VALUE
152
+ rb_shift_key_q(VALUE self)
153
+ {
154
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_SHIFTKEY ? Qtrue : Qfalse;
155
+ }
156
+
157
+ /*
158
+ * Return true when ALT key is pushed. Otherwise return false.
159
+ */
160
+ VALUE
161
+ rb_alt_key_q(VALUE self)
162
+ {
163
+ return MOUSEEVENT(self)->flags & CV_EVENT_FLAG_ALTKEY ? Qtrue : Qfalse;
164
+ }
165
+
166
+ VALUE
167
+ new_object(int event, int x, int y, int flags)
168
+ {
169
+ VALUE object = rb_allocate(rb_class());
170
+ MouseEvent *mouseevent = MOUSEEVENT(object);
171
+ mouseevent->point.x = x;
172
+ mouseevent->point.y = y;
173
+ mouseevent->event = event;
174
+ mouseevent->flags = flags;
175
+ return object;
176
+ }
177
+
178
+ __NAMESPACE_END_MOUSEEVENT
179
+ __NAMESPACE_END_GUI
180
+ __NAMESPACE_END_OPENCV
181
+