Class: OpenCV::GUI::Window
- Inherits:
-
Object
- Object
- OpenCV::GUI::Window
- Defined in:
- ext/opencv/window.cpp,
ext/opencv/window.cpp
Overview
Class Method Summary collapse
-
.destroy_all ⇒ Object
Destorys all the windows.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Return alive status of window.
-
#destroy ⇒ Object
Destroys a window.
-
#new(name, flags = CV_WINDOW_AUTOSIZE) ⇒ Object
constructor
Creates a window.
-
#move(*args) ⇒ Object
Moves window to the specified position.
-
#resize(*args) ⇒ Object
Resizes window to the specified size.
-
#set_mouse_callback({ |mouse_event| ... }) {|mouse_event| ... } ⇒ Object
(also: #on_mouse)
Sets mouse handler for the specified window.
-
#set_trackbar(*args) ⇒ Object
Creates or sets a trackbar and attaches it to the specified window.
-
#show_image(image) ⇒ Object
(also: #show)
Displays an image in the specified window.
Constructor Details
#new(name, flags = CV_WINDOW_AUTOSIZE) ⇒ Object
Creates a window.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/opencv/window.cpp', line 70
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE name, flags;
rb_scan_args(argc, argv, "11", &name, &flags);
Check_Type(name, T_STRING);
char* name_str = StringValueCStr(name);
if (cvGetWindowHandle(name_str) != NULL) {
rb_raise(rb_eStandardError, "window name should be unique.");
}
int mode = CV_WINDOW_AUTOSIZE;
if (argc == 2) {
Check_Type(flags, T_FIXNUM);
mode = FIX2INT(flags);
}
Window* self_ptr = WINDOW(self);
self_ptr->name = name;
self_ptr->trackbars = rb_ary_new();
self_ptr->blocks = rb_ary_new();
try {
cvNamedWindow(name_str, mode);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
num_windows++;
return self;
}
|
Class Method Details
.destroy_all ⇒ Object
Destorys all the windows.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'ext/opencv/window.cpp', line 131
VALUE
rb_destroy_all(VALUE klass)
{
if (num_windows > 0) {
try {
cvDestroyAllWindows();
}
catch (cv::Exception& e) {
raise_cverror(e);
}
num_windows = 0;
}
return Qnil;
}
|
Instance Method Details
#alive? ⇒ Boolean
Return alive status of window. Return true if alive, otherwise return false.
104 105 106 107 108 109 |
# File 'ext/opencv/window.cpp', line 104
VALUE
rb_alive_q(VALUE self)
{
const char* name_str = GET_WINDOW_NAME(self);
return (cvGetWindowHandle(name_str) == NULL) ? Qfalse : Qtrue;
}
|
#destroy ⇒ Object
Destroys a window. alive status of window be false.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ext/opencv/window.cpp', line 114
VALUE
rb_destroy(VALUE self)
{
const char* name_str = GET_WINDOW_NAME(self);
try {
cvDestroyWindow(name_str);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
num_windows--;
return self;
}
|
#move(point) ⇒ Object #move(x, y) ⇒ Object
Moves window to the specified position.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'ext/opencv/window.cpp', line 195
VALUE
rb_move(int argc, VALUE *argv, VALUE self)
{
int x = 0;
int y = 0;
switch (argc) {
case 1: {
CvPoint point = VALUE_TO_CVPOINT(argv[0]);
x = point.x;
y = point.y;
break;
}
case 2:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
break;
}
try {
cvMoveWindow(GET_WINDOW_NAME(self), x, y);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#resize(size) ⇒ Object #resize(width, height) ⇒ Object
Resizes window to the specified size.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/opencv/window.cpp', line 156
VALUE
rb_resize(int argc, VALUE *argv, VALUE self)
{
int width = 0;
int height = 0;
switch (argc) {
case 1: {
CvSize size = VALUE_TO_CVSIZE(argv[0]);
width = size.width;
height = size.height;
break;
}
case 2:
width = NUM2INT(argv[0]);
height = NUM2INT(argv[1]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
break;
}
try {
cvResizeWindow(GET_WINDOW_NAME(self), width, height);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#set_mouse_callback({ |mouse_event| ... }) {|mouse_event| ... } ⇒ Object Also known as: on_mouse
Sets mouse handler for the specified window.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'ext/opencv/window.cpp', line 321
VALUE
rb_set_mouse_callback(int argc, VALUE* argv, VALUE self)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "block not given.");
}
VALUE block = Qnil;
rb_scan_args(argc, argv, "0&", &block);
try {
cvSetMouseCallback(GET_WINDOW_NAME(self), on_mouse, (void*)block);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
rb_ary_push(WINDOW(self)->blocks, block);
return block;
}
|
#set_trackbar(trackbar) ⇒ Object #set_trackbar(name, count, value = nil) {|value| ... } ⇒ Object
Creates or sets a trackbar and attaches it to the specified window.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/opencv/window.cpp', line 266
VALUE
rb_set_trackbar(int argc, VALUE *argv, VALUE self)
{
VALUE trackbar;
if (argc == 1) {
trackbar = argv[0];
}
else {
trackbar = cTrackbar::rb_initialize(argc, argv, cTrackbar::rb_allocate(cTrackbar::rb_class()));
}
Trackbar *trackbar_ptr = TRACKBAR_WITH_CHECK(trackbar);
try {
cv::createTrackbar(trackbar_ptr->name, GET_WINDOW_NAME(self), &(trackbar_ptr->val), trackbar_ptr->maxval,
(cv::TrackbarCallback)trackbar_callback, (void*)(trackbar_ptr->block));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
rb_ary_push(WINDOW(self)->trackbars, trackbar);
return trackbar;
}
|
#show_image(image) ⇒ Object Also known as: show
Displays an image in the specified window.
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'ext/opencv/window.cpp', line 231
VALUE
rb_show_image(VALUE self, VALUE img)
{
CvArr* image = CVARR_WITH_CHECK(img);
WINDOW(self)->image = img;
try {
cvShowImage(GET_WINDOW_NAME(self), image);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|