spyglass 0.0.4.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa5d2efe1d75f4c772e76ee0c391e724796a5be9
4
- data.tar.gz: ebc53f2c758d1fca38a8e76ae24472eebfd317df
3
+ metadata.gz: d8e0f9a857a304d3a87857e05baecfc761eae686
4
+ data.tar.gz: 56fe04d59eb6700545daae2f3c910185ca97d166
5
5
  SHA512:
6
- metadata.gz: 6ad7ddc01fe98b6e3625e6570450f65f45ab336539f16a7cbda679a0be0cfa44ab7b1163e276c6c5f03247116338ca017e24c0a562c23276769b788e77090ae0
7
- data.tar.gz: bf510a98a7e42ee00a407f3e91bec06b8b9949c905e4e93edd5bd4f6930618684deab57d54d708becf19f000e543c376c3d74881ec37118b5a5bdc24c9b28664
6
+ metadata.gz: 39b41c955236f3868616647e3bc264d4f3cdc17546f49b44386f2b71c8ce1f486b062265fbc7a25b9758b36eeb8d2301bfe826c0c4c7119b8a335bf380705851
7
+ data.tar.gz: 90d5814cc51555ce8b7fce8a4d6a4ea8a810da0295cf316a8d130bf39d4b7fceb585bdf68cc46b3ec5b7ba69f2811dfbd7b53b2f701d5bb1c72f8aec3bba17f2
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift('lib')
2
+ require 'spyglass'
3
+
4
+ include Spyglass
5
+
6
+ window = GUI::Window.new "Original"
7
+ card = Image.load File.expand_path('images/card.jpg', File.dirname(__FILE__))
8
+
9
+ window.on_click do |x, y|
10
+ puts "CLICKED: #{ x }, #{ y }"
11
+ end
12
+
13
+ window.on_right_click do |x, y|
14
+ puts "RIGHT CLICKED: #{ x }, #{ y }"
15
+ end
16
+
17
+ window.show(card)
18
+
19
+ loop do
20
+ break if GUI::wait_key(10) > 0
21
+ end
22
+
@@ -6,6 +6,9 @@
6
6
  #include "bgslib_dp_prati_mediod_bgs.h"
7
7
 
8
8
  namespace Spyglass {
9
+
10
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_BG_SUBTRACTOR, cv::BackgroundSubtractor);
11
+
9
12
  namespace BackgroundSubtractor {
10
13
  void define_ruby_types();
11
14
  VALUE get_ruby_module();
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_CLASSIFIER, cv::CascadeClassifier);
9
+
7
10
  namespace CascadeClassifier {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
data/ext/spyglass/color.h CHANGED
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_COLOR, cv::Scalar);
9
+
7
10
  namespace Color {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_CONTOUR, std::vector<cv::Point *>);
9
+
7
10
  namespace Contour {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
data/ext/spyglass/image.h CHANGED
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_IMAGE, cv::Mat);
9
+
7
10
  namespace Image {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
data/ext/spyglass/point.h CHANGED
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_POINT, cv::Point);
9
+
7
10
  namespace Point {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
@@ -15,16 +15,6 @@
15
15
  return ptr; \
16
16
  }
17
17
 
18
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_BG_SUBTRACTOR, cv::BackgroundSubtractor);
19
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_CLASSIFIER, cv::CascadeClassifier);
20
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_COLOR, cv::Scalar);
21
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_CONTOUR, std::vector<cv::Point *>);
22
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_IMAGE, cv::Mat);
23
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_POINT, cv::Point);
24
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_RECT, cv::Rect);
25
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_SIZE, cv::Size);
26
- SG_GEN_GET_OBJECT_FUNCTION(SG_GET_VIDEO_CAPTURE, cv::VideoCapture);
27
-
28
18
  #define SG_OPTION(opts, type, key, default, expr) \
29
19
  type key = default; \
30
20
  if(RTEST(opts)) { \
data/ext/spyglass/rect.h CHANGED
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_RECT, cv::Rect);
9
+
7
10
  namespace Rect {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
data/ext/spyglass/size.h CHANGED
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_SIZE, cv::Size);
9
+
7
10
  namespace Size {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
@@ -4,6 +4,9 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_VIDEO_CAPTURE, cv::VideoCapture);
9
+
7
10
  namespace VideoCapture {
8
11
  void define_ruby_class();
9
12
  VALUE get_ruby_class();
@@ -14,6 +14,9 @@ namespace Spyglass {
14
14
  // Instance methods
15
15
  rb_define_method(WindowClass, "hide", RUBY_METHOD_FUNC(rb_hide), 0);
16
16
  rb_define_method(WindowClass, "move", RUBY_METHOD_FUNC(rb_move), 2);
17
+ rb_define_method(WindowClass, "on_click", RUBY_METHOD_FUNC(rb_on_click), 0);
18
+ rb_define_method(WindowClass, "on_right_click", RUBY_METHOD_FUNC(rb_on_right_click), 0);
19
+ rb_define_method(WindowClass, "on_move", RUBY_METHOD_FUNC(rb_on_move), 0);
17
20
  rb_define_method(WindowClass, "show", RUBY_METHOD_FUNC(rb_show), 1);
18
21
  rb_define_method(WindowClass, "title", RUBY_METHOD_FUNC(rb_get_title), 0);
19
22
  }
@@ -23,43 +26,90 @@ namespace Spyglass {
23
26
  }
24
27
 
25
28
  static VALUE rb_alloc(VALUE self) {
26
- char *title = NULL;
27
- return Data_Wrap_Struct(WindowClass, NULL, rb_free, title);
29
+ window_data *window = (window_data *)malloc(sizeof(window_data));
30
+ window->title = NULL;
31
+ return Data_Wrap_Struct(WindowClass, NULL, rb_free, window);
28
32
  }
29
33
 
30
- static void rb_free(char *title) {
31
- if(title != NULL)
32
- free(title);
34
+ static void rb_free(window_data *window) {
35
+ if(window->title)
36
+ free(window->title);
37
+ free(window);
33
38
  }
34
39
 
40
+ static void _on_mouse_event(int event, int x, int y, int flags, void *obj) {
41
+ window_data *window = (window_data *)obj;
42
+ VALUE self = window->robj;
43
+
44
+ VALUE block = 0;
45
+ switch(event) {
46
+ case cv::EVENT_LBUTTONDOWN:
47
+ block = rb_ivar_get(self, rb_intern("@_click_block"));
48
+ break;
49
+
50
+ case cv::EVENT_RBUTTONDOWN:
51
+ block = rb_ivar_get(self, rb_intern("@_right_click_block"));
52
+ break;
53
+
54
+ case cv::EVENT_MOUSEMOVE:
55
+ block = rb_ivar_get(self, rb_intern("@_mouse_move_block"));
56
+ break;
57
+ }
58
+
59
+ if(block == 0 || !RTEST(block))
60
+ return;
61
+
62
+ rb_funcall(block, rb_intern("call"), 2, INT2FIX(x), INT2FIX(y));
63
+ }
64
+
65
+
35
66
  static VALUE rb_initialize(VALUE self, VALUE title) {
36
67
  Check_Type(title, T_STRING);
37
68
 
38
- char *_title = strdup(StringValueCStr(title));
39
- cv::namedWindow(_title);
40
- Data_Set_Struct(self, _title);
69
+ window_data *window = SG_GET_WINDOW(self);
70
+ window->title = (char *)malloc(rb_str_length(title) + 1);
71
+ strncpy(window->title, StringValuePtr(title), rb_str_length(title));
41
72
 
73
+ window->robj = self;
74
+
75
+ cv::namedWindow(window->title);
76
+ cv::setMouseCallback(window->title, _on_mouse_event, window);
42
77
  return self;
43
78
  }
44
79
 
45
80
  static VALUE rb_hide(VALUE self) {
46
- char *title;
47
- Data_Get_Struct(self, char, title);
81
+ window_data *window = SG_GET_WINDOW(self);
48
82
 
49
- cv::destroyWindow(title);
83
+ cv::destroyWindow(window->title);
50
84
  cv::waitKey(1);
51
85
 
52
86
  return self;
53
87
  }
54
88
 
89
+ static VALUE rb_on_click(VALUE self) {
90
+ rb_need_block();
91
+ rb_ivar_set(self, rb_intern("@_click_block"), rb_block_proc());
92
+ return self;
93
+ }
94
+
95
+ static VALUE rb_on_right_click(VALUE self) {
96
+ rb_need_block();
97
+ rb_ivar_set(self, rb_intern("@_right_click_block"), rb_block_proc());
98
+ return self;
99
+ }
100
+
101
+ static VALUE rb_on_move(VALUE self) {
102
+ rb_need_block();
103
+ rb_ivar_set(self, rb_intern("@_mouse_move_block"), rb_block_proc());
104
+ return self;
105
+ }
106
+
55
107
  static VALUE rb_move(VALUE self, VALUE x, VALUE y) {
56
108
  Check_Type(x, T_FIXNUM);
57
109
  Check_Type(y, T_FIXNUM);
58
110
 
59
- char *title;
60
- Data_Get_Struct(self, char, title);
61
-
62
- cv::moveWindow(title, FIX2INT(x), FIX2INT(y));
111
+ window_data *window = SG_GET_WINDOW(self);
112
+ cv::moveWindow(window->title, FIX2INT(x), FIX2INT(y));
63
113
  cv::waitKey(1);
64
114
 
65
115
  return self;
@@ -73,20 +123,16 @@ namespace Spyglass {
73
123
 
74
124
  cv::Mat *img = SG_GET_IMAGE(image);
75
125
 
76
- char *title;
77
- Data_Get_Struct(self, char, title);
78
-
79
- cv::imshow(title, *img);
126
+ window_data *window = SG_GET_WINDOW(self);
127
+ cv::imshow(window->title, *img);
80
128
  cv::waitKey(1);
81
129
 
82
130
  return self;
83
131
  }
84
132
 
85
133
  static VALUE rb_get_title(VALUE self) {
86
- char *title;
87
- Data_Get_Struct(self, char, title);
88
-
89
- return rb_str_new2(title);
134
+ window_data *window = SG_GET_WINDOW(self);
135
+ return rb_str_new2(window->title);
90
136
  }
91
137
  }
92
138
  }
@@ -4,20 +4,32 @@
4
4
  #include "spyglass.h"
5
5
 
6
6
  namespace Spyglass {
7
+
8
+ typedef struct window_data {
9
+ char *title;
10
+ VALUE robj;
11
+ } window_data;
12
+
13
+ SG_GEN_GET_OBJECT_FUNCTION(SG_GET_WINDOW, window_data);
14
+
7
15
  namespace GUI {
8
16
  namespace Window {
9
17
  void define_ruby_class();
10
18
  VALUE get_ruby_class();
11
19
 
12
20
  static VALUE rb_alloc(VALUE self);
13
- static void rb_free(char *title);
21
+ static void rb_free(window_data *window);
14
22
  static VALUE rb_initialize(VALUE self, VALUE title);
15
23
  static VALUE rb_hide(VALUE self);
16
24
  static VALUE rb_move(VALUE self, VALUE x, VALUE y);
25
+ static VALUE rb_on_click(VALUE self);
26
+ static VALUE rb_on_right_click(VALUE self);
27
+ static VALUE rb_on_move(VALUE self);
17
28
  static VALUE rb_show(VALUE self, VALUE image);
18
29
  static VALUE rb_get_title(VALUE self);
19
30
  }
20
31
  }
21
32
  }
22
33
 
34
+
23
35
  #endif // SPYGLASS_WINDOW_H_
@@ -1,3 +1,3 @@
1
1
  module Spyglass
2
- VERSION = "0.0.4.1"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyglass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Medeiros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-14 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - examples/images/beach.jpg
90
90
  - examples/images/card.jpg
91
91
  - examples/video_capture.rb
92
+ - examples/window_events.rb
92
93
  - ext/spyglass/background_subtractor.cc
93
94
  - ext/spyglass/background_subtractor.h
94
95
  - ext/spyglass/bgslib_bgs.h