spyglass 0.0.4.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/window_events.rb +22 -0
- data/ext/spyglass/background_subtractor.h +3 -0
- data/ext/spyglass/cascade_classifier.h +3 -0
- data/ext/spyglass/color.h +3 -0
- data/ext/spyglass/contour.h +3 -0
- data/ext/spyglass/image.h +3 -0
- data/ext/spyglass/point.h +3 -0
- data/ext/spyglass/prelude.h +0 -10
- data/ext/spyglass/rect.h +3 -0
- data/ext/spyglass/size.h +3 -0
- data/ext/spyglass/video_capture.h +3 -0
- data/ext/spyglass/window.cc +69 -23
- data/ext/spyglass/window.h +13 -1
- data/lib/spyglass/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8e0f9a857a304d3a87857e05baecfc761eae686
|
4
|
+
data.tar.gz: 56fe04d59eb6700545daae2f3c910185ca97d166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
|
data/ext/spyglass/color.h
CHANGED
data/ext/spyglass/contour.h
CHANGED
data/ext/spyglass/image.h
CHANGED
data/ext/spyglass/point.h
CHANGED
data/ext/spyglass/prelude.h
CHANGED
@@ -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
data/ext/spyglass/size.h
CHANGED
data/ext/spyglass/window.cc
CHANGED
@@ -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
|
-
|
27
|
-
|
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(
|
31
|
-
if(title
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
77
|
-
|
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
|
-
|
87
|
-
|
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
|
}
|
data/ext/spyglass/window.h
CHANGED
@@ -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(
|
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_
|
data/lib/spyglass/version.rb
CHANGED
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
|
+
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-
|
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
|