ruby-opencv 0.0.9.pre2-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +8 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +227 -0
- data/README.md +98 -0
- data/Rakefile +90 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/matching_to_many_images.rb +16 -0
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +3 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +506 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +233 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +296 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5848 -0
- data/ext/opencv/cvmat.h +284 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +245 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +192 -0
- data/ext/opencv/cvutils.h +30 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/extconf.rb +83 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +644 -0
- data/ext/opencv/iplimage.h +73 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +722 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +274 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +3 -0
- data/ruby-opencv.gemspec +44 -0
- data/test/helper.rb +166 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/chessboard.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +2947 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2025 -0
- data/test/test_cvmat_matching.rb +57 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +236 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +324 -0
- data/test/test_pointset.rb +126 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +386 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
pointset.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_POINTSET_H
|
11
|
+
#define RUBY_OPENCV_POINTSET_H
|
12
|
+
|
13
|
+
#define __NAMESPACE_BEGIN_POINT_SET namespace mPointSet {
|
14
|
+
#define __NAMESPACE_END_POINT_SET }
|
15
|
+
|
16
|
+
#include "opencv.h"
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_POINT_SET
|
20
|
+
|
21
|
+
VALUE rb_module();
|
22
|
+
|
23
|
+
void define_ruby_module();
|
24
|
+
VALUE rb_contour_area(int argc, VALUE *argv, VALUE self);
|
25
|
+
VALUE rb_fit_ellipse2(VALUE self);
|
26
|
+
VALUE rb_convex_hull2(int argc, VALUE *argv, VALUE self);
|
27
|
+
VALUE rb_fit_line(int argc, VALUE *argv, VALUE self);
|
28
|
+
VALUE rb_check_contour_convexity(VALUE self);
|
29
|
+
VALUE rb_convexity_defects(VALUE self, VALUE hull);
|
30
|
+
VALUE rb_min_area_rect2(VALUE self);
|
31
|
+
VALUE rb_min_enclosing_circle(VALUE self);
|
32
|
+
|
33
|
+
__NAMESPACE_END_POINT_SET
|
34
|
+
|
35
|
+
#define POINT_SET_P(object) rb_obj_is_kind_of(object, cCvSeq::rb_class()) && CV_IS_SEQ_POINT_SET(CVSEQ(object))
|
36
|
+
|
37
|
+
/*
|
38
|
+
inline CvPoint*
|
39
|
+
POINTSET(VALUE object)
|
40
|
+
{
|
41
|
+
CvPoint *pointset = (CvPoint*)cvAlloc(CVSEQ(object)->total * sizeof(CvPoint));
|
42
|
+
cvCvtSeqToArray(CVSEQ(object), pointset, CV_WHOLE_SEQ);
|
43
|
+
if (cCvSeq::seqblock_class(CVSEQ(object)) == cCvPoint2D32f::rb_class()) {
|
44
|
+
for(int i =0; i < CVSEQ(object)->total; i++)
|
45
|
+
pointset[i] = cvPointFrom32f(((CvPoint2D32f*)pointset)[i]);
|
46
|
+
}
|
47
|
+
return pointset;
|
48
|
+
}
|
49
|
+
|
50
|
+
inline CvPoint2D32f*
|
51
|
+
POINTSET2D32f(VALUE object)
|
52
|
+
{
|
53
|
+
CvPoint2D32f *pointset = (CvPoint2D32f*)cvAlloc(CVSEQ(object)->total * sizeof(CvPoint2D32f));
|
54
|
+
cvCvtSeqToArray(CVSEQ(object), pointset, CV_WHOLE_SEQ);
|
55
|
+
if (cCvSeq::seqblock_class(CVSEQ(object)) == cCvPoint::rb_class()) {
|
56
|
+
for(int i = 0; i < CVSEQ(object)->total; i++)
|
57
|
+
pointset[i] = cvPointTo32f(((CvPoint*)pointset)[i]);
|
58
|
+
}
|
59
|
+
return pointset;
|
60
|
+
}
|
61
|
+
*/
|
62
|
+
|
63
|
+
int CVPOINTS_FROM_POINT_SET(VALUE object, CvPoint **pointset);
|
64
|
+
CvSeq* VALUE_TO_POINT_SET(VALUE object);
|
65
|
+
|
66
|
+
__NAMESPACE_END_OPENCV
|
67
|
+
|
68
|
+
#endif // RUBY_OPENCV_POINTSET_H
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
trackbar.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "trackbar.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::GUI::Trackbar
|
13
|
+
*
|
14
|
+
* Simple Trackbar wedget. OpenCV::GUI::Window can treat trackbar.
|
15
|
+
* Trackbar can treat only positive-integer value.
|
16
|
+
*/
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_GUI
|
20
|
+
__NAMESPACE_BEGIN_TRACKBAR
|
21
|
+
|
22
|
+
VALUE rb_klass;
|
23
|
+
|
24
|
+
VALUE rb_class() {
|
25
|
+
return rb_klass;
|
26
|
+
}
|
27
|
+
|
28
|
+
void define_ruby_class() {
|
29
|
+
if (rb_klass)
|
30
|
+
return;
|
31
|
+
/*
|
32
|
+
* opencv = rb_define_module("OpenCV");
|
33
|
+
* GUI = rb_define_module_under(opencv, "GUI");
|
34
|
+
*
|
35
|
+
* note: this comment is used by rdoc.
|
36
|
+
*/
|
37
|
+
VALUE GUI = rb_module_GUI();
|
38
|
+
rb_klass = rb_define_class_under(GUI, "Trackbar", rb_cObject);
|
39
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
40
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
41
|
+
rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0);
|
42
|
+
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
|
43
|
+
rb_define_method(rb_klass, "value", RUBY_METHOD_FUNC(rb_value), 0);
|
44
|
+
rb_define_method(rb_klass, "value=", RUBY_METHOD_FUNC(rb_set_value), 1);
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE rb_allocate(VALUE klass) {
|
48
|
+
Trackbar *ptr;
|
49
|
+
return Data_Make_Struct(klass, Trackbar, trackbar_mark, trackbar_free, ptr);
|
50
|
+
}
|
51
|
+
|
52
|
+
void trackbar_mark(void *ptr) {
|
53
|
+
rb_gc_mark(((Trackbar*)ptr)->block);
|
54
|
+
}
|
55
|
+
|
56
|
+
void trackbar_free(void *ptr) {
|
57
|
+
Trackbar *trackbar = (Trackbar*)ptr;
|
58
|
+
free(trackbar->name);
|
59
|
+
free(trackbar);
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* new(<i>name,maxval[,val],&block</i>)
|
65
|
+
* new(<i>name,maxval[,val]</i>){|value| ... }
|
66
|
+
*
|
67
|
+
* Create new Trackbar.
|
68
|
+
* <i>name</i> should be String.
|
69
|
+
* <i>maxval</i> and <i>val</i> should be Fixnum.
|
70
|
+
* When Trackbar adjuster changed, block will be called.
|
71
|
+
*/
|
72
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self) {
|
73
|
+
VALUE name, maxval, val, block;
|
74
|
+
rb_scan_args(argc, argv, "21&", &name, &maxval, &val, &block);
|
75
|
+
if (NIL_P(block))
|
76
|
+
rb_raise(rb_eArgError, "block not given.");
|
77
|
+
Check_Type(name, T_STRING);
|
78
|
+
Trackbar *trackbar = TRACKBAR(self);
|
79
|
+
trackbar->name = strcpy(ALLOC_N(char, RSTRING_LEN(name) + 1), StringValueCStr(name));
|
80
|
+
trackbar->maxval = NUM2INT(maxval);
|
81
|
+
trackbar->val = IF_INT(val, 0);
|
82
|
+
trackbar->block = block;
|
83
|
+
return self;
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* Return trackbar name.
|
88
|
+
*/
|
89
|
+
VALUE rb_name(VALUE self) {
|
90
|
+
return rb_str_new2(TRACKBAR(self)->name);
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
* Return the maximum value that can be taken this trackbar.
|
95
|
+
*/
|
96
|
+
VALUE rb_max(VALUE self) {
|
97
|
+
return INT2NUM(TRACKBAR(self)->maxval);
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* Return the value of this trackbar.
|
102
|
+
*/
|
103
|
+
VALUE rb_value(VALUE self) {
|
104
|
+
return INT2NUM(TRACKBAR(self)->val);
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* value = <i>val</i>
|
110
|
+
*
|
111
|
+
* Set trackbar value.
|
112
|
+
*/
|
113
|
+
VALUE rb_set_value(VALUE self, VALUE val) {
|
114
|
+
TRACKBAR(self)->val = NUM2INT(val);
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
__NAMESPACE_END_TRACKBAR
|
119
|
+
__NAMESPACE_END_GUI
|
120
|
+
__NAMESPACE_END_OPENCV
|
121
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
trackbar.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_GUI_H
|
11
|
+
#include "gui.h"
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#ifndef RUBY_OPENCV_GUI_TRACKBAR_H
|
15
|
+
#define RUBY_OPENCV_GUI_TRACKBAR_H
|
16
|
+
|
17
|
+
#include "opencv.h"
|
18
|
+
|
19
|
+
#define __NAMESPACE_BEGIN_TRACKBAR namespace cTrackbar {
|
20
|
+
#define __NAMESPACE_END_TRACKBAR }
|
21
|
+
|
22
|
+
__NAMESPACE_BEGIN_OPENCV
|
23
|
+
__NAMESPACE_BEGIN_GUI
|
24
|
+
|
25
|
+
typedef struct Trackbar {
|
26
|
+
char *name;
|
27
|
+
int maxval;
|
28
|
+
int val;
|
29
|
+
VALUE block;
|
30
|
+
} Trackbar;
|
31
|
+
|
32
|
+
__NAMESPACE_BEGIN_TRACKBAR
|
33
|
+
|
34
|
+
VALUE rb_class();
|
35
|
+
|
36
|
+
void define_ruby_class();
|
37
|
+
VALUE rb_allocate(VALUE klass);
|
38
|
+
|
39
|
+
void trackbar_mark(void *ptr);
|
40
|
+
void trackbar_free(void *ptr);
|
41
|
+
|
42
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
43
|
+
VALUE rb_name(VALUE self);
|
44
|
+
VALUE rb_max(VALUE self);
|
45
|
+
VALUE rb_value(VALUE self);
|
46
|
+
VALUE rb_set_value(VALUE self, VALUE val);
|
47
|
+
|
48
|
+
__NAMESPACE_END_TRACKBAR
|
49
|
+
|
50
|
+
inline Trackbar*
|
51
|
+
TRACKBAR(VALUE object) {
|
52
|
+
Trackbar *ptr;
|
53
|
+
Data_Get_Struct(object, Trackbar, ptr);
|
54
|
+
return ptr;
|
55
|
+
}
|
56
|
+
|
57
|
+
inline Trackbar*
|
58
|
+
TRACKBAR_WITH_CHECK(VALUE object) {
|
59
|
+
if (!rb_obj_is_kind_of(object, cTrackbar::rb_class())) {
|
60
|
+
raise_typeerror(object, cTrackbar::rb_class());
|
61
|
+
}
|
62
|
+
return TRACKBAR(object);
|
63
|
+
}
|
64
|
+
|
65
|
+
__NAMESPACE_END_GUI
|
66
|
+
__NAMESPACE_END_OPENCV
|
67
|
+
|
68
|
+
#endif // RUBY_OPENCV_GUI_TRACKBAR_H
|
69
|
+
|
@@ -0,0 +1,357 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
window.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "window.h"
|
11
|
+
|
12
|
+
/*
|
13
|
+
* Document-class: OpenCV::GUI::Window
|
14
|
+
*
|
15
|
+
* Simple Window wedget to show images(CvMat/IplImage).
|
16
|
+
*
|
17
|
+
* Sample:
|
18
|
+
* image = OpenCV::IplImage::load("opencv.bmp") #=> load image
|
19
|
+
* window = OpenCV::GUI::Window.new("simple viewer")#=> create new window named "simaple viewer"
|
20
|
+
* window.show(image) #=> show image
|
21
|
+
*/
|
22
|
+
__NAMESPACE_BEGIN_OPENCV
|
23
|
+
__NAMESPACE_BEGIN_GUI
|
24
|
+
__NAMESPACE_BEGIN_WINDOW
|
25
|
+
|
26
|
+
int num_windows = 0;
|
27
|
+
VALUE rb_klass;
|
28
|
+
|
29
|
+
VALUE
|
30
|
+
rb_class()
|
31
|
+
{
|
32
|
+
return rb_klass;
|
33
|
+
}
|
34
|
+
|
35
|
+
void
|
36
|
+
define_ruby_class()
|
37
|
+
{
|
38
|
+
if (rb_klass)
|
39
|
+
return;
|
40
|
+
/*
|
41
|
+
* opencv = rb_define_module("OpenCV");
|
42
|
+
* GUI = rb_define_module_under(opencv, "GUI");
|
43
|
+
*
|
44
|
+
* note: this comment is used by rdoc.
|
45
|
+
*/
|
46
|
+
VALUE GUI = rb_module_GUI();
|
47
|
+
rb_klass = rb_define_class_under(GUI, "Window", rb_cObject);
|
48
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
49
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
50
|
+
rb_define_method(rb_klass, "alive?", RUBY_METHOD_FUNC(rb_alive_q), 0);
|
51
|
+
rb_define_method(rb_klass, "destroy", RUBY_METHOD_FUNC(rb_destroy), 0);
|
52
|
+
rb_define_singleton_method(rb_klass, "destroy_all", RUBY_METHOD_FUNC(rb_destroy_all), 0);
|
53
|
+
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -1);
|
54
|
+
rb_define_method(rb_klass, "move", RUBY_METHOD_FUNC(rb_move), -1);
|
55
|
+
rb_define_method(rb_klass, "show_image", RUBY_METHOD_FUNC(rb_show_image), 1);
|
56
|
+
rb_define_alias(rb_klass, "show", "show_image");
|
57
|
+
rb_define_method(rb_klass, "set_trackbar", RUBY_METHOD_FUNC(rb_set_trackbar), -1);
|
58
|
+
rb_define_method(rb_klass, "set_mouse_callback", RUBY_METHOD_FUNC(rb_set_mouse_callback), -1);
|
59
|
+
rb_define_alias(rb_klass, "on_mouse", "set_mouse_callback");
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE
|
63
|
+
rb_allocate(VALUE klass)
|
64
|
+
{
|
65
|
+
Window *ptr;
|
66
|
+
return Data_Make_Struct(klass, Window, window_mark, window_free, ptr);
|
67
|
+
}
|
68
|
+
|
69
|
+
void
|
70
|
+
window_mark(void *ptr)
|
71
|
+
{
|
72
|
+
Window* window_ptr = (Window*)ptr;
|
73
|
+
rb_gc_mark(window_ptr->name);
|
74
|
+
rb_gc_mark(window_ptr->image);
|
75
|
+
rb_gc_mark(window_ptr->trackbars);
|
76
|
+
rb_gc_mark(window_ptr->blocks);
|
77
|
+
}
|
78
|
+
|
79
|
+
void
|
80
|
+
window_free(void *ptr)
|
81
|
+
{
|
82
|
+
free(ptr);
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* new(<i>name[, flags]</i>)
|
88
|
+
*
|
89
|
+
* Create new window named <i>name</i>.
|
90
|
+
* If <i>flags</i> is CV_WINDOW_AUTOSIZE (default), window size automatically resize when image given.
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
94
|
+
{
|
95
|
+
VALUE name, flags;
|
96
|
+
rb_scan_args(argc, argv, "11", &name, &flags);
|
97
|
+
Check_Type(name, T_STRING);
|
98
|
+
char* name_str = StringValueCStr(name);
|
99
|
+
if (cvGetWindowHandle(name_str) != NULL) {
|
100
|
+
rb_raise(rb_eStandardError, "window name should be unique.");
|
101
|
+
}
|
102
|
+
|
103
|
+
int mode = CV_WINDOW_AUTOSIZE;
|
104
|
+
if (argc == 2) {
|
105
|
+
Check_Type(flags, T_FIXNUM);
|
106
|
+
mode = FIX2INT(flags);
|
107
|
+
}
|
108
|
+
|
109
|
+
Window* self_ptr = WINDOW(self);
|
110
|
+
self_ptr->name = name;
|
111
|
+
self_ptr->trackbars = rb_ary_new();
|
112
|
+
self_ptr->blocks = rb_ary_new();
|
113
|
+
try {
|
114
|
+
cvNamedWindow(name_str, mode);
|
115
|
+
}
|
116
|
+
catch (cv::Exception& e) {
|
117
|
+
raise_cverror(e);
|
118
|
+
}
|
119
|
+
num_windows++;
|
120
|
+
return self;
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Return alive status of window. Return true if alive, otherwise return false.
|
125
|
+
*/
|
126
|
+
VALUE
|
127
|
+
rb_alive_q(VALUE self)
|
128
|
+
{
|
129
|
+
const char* name_str = GET_WINDOW_NAME(self);
|
130
|
+
return (cvGetWindowHandle(name_str) == NULL) ? Qfalse : Qtrue;
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* Destroys a window. alive status of window be false.
|
135
|
+
*/
|
136
|
+
VALUE
|
137
|
+
rb_destroy(VALUE self)
|
138
|
+
{
|
139
|
+
const char* name_str = GET_WINDOW_NAME(self);
|
140
|
+
try {
|
141
|
+
cvDestroyWindow(name_str);
|
142
|
+
}
|
143
|
+
catch (cv::Exception& e) {
|
144
|
+
raise_cverror(e);
|
145
|
+
}
|
146
|
+
num_windows--;
|
147
|
+
return self;
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
* Destorys all the windows.
|
152
|
+
*/
|
153
|
+
VALUE
|
154
|
+
rb_destroy_all(VALUE klass)
|
155
|
+
{
|
156
|
+
if (num_windows > 0) {
|
157
|
+
try {
|
158
|
+
cvDestroyAllWindows();
|
159
|
+
}
|
160
|
+
catch (cv::Exception& e) {
|
161
|
+
raise_cverror(e);
|
162
|
+
}
|
163
|
+
num_windows = 0;
|
164
|
+
}
|
165
|
+
return Qnil;
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* call-seq:
|
170
|
+
* resize(<i>size</i>)
|
171
|
+
* resize(<i>width, height</i>)
|
172
|
+
*
|
173
|
+
* Set window size.
|
174
|
+
*/
|
175
|
+
VALUE
|
176
|
+
rb_resize(int argc, VALUE *argv, VALUE self)
|
177
|
+
{
|
178
|
+
int width = 0;
|
179
|
+
int height = 0;
|
180
|
+
switch (argc) {
|
181
|
+
case 1: {
|
182
|
+
CvSize size = VALUE_TO_CVSIZE(argv[0]);
|
183
|
+
width = size.width;
|
184
|
+
height = size.height;
|
185
|
+
break;
|
186
|
+
}
|
187
|
+
case 2:
|
188
|
+
width = NUM2INT(argv[0]);
|
189
|
+
height = NUM2INT(argv[1]);
|
190
|
+
break;
|
191
|
+
default:
|
192
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
193
|
+
break;
|
194
|
+
}
|
195
|
+
try {
|
196
|
+
cvResizeWindow(GET_WINDOW_NAME(self), width, height);
|
197
|
+
}
|
198
|
+
catch (cv::Exception& e) {
|
199
|
+
raise_cverror(e);
|
200
|
+
}
|
201
|
+
return self;
|
202
|
+
}
|
203
|
+
|
204
|
+
/*
|
205
|
+
* call-seq:
|
206
|
+
* move(<i>point</i>)
|
207
|
+
* move(<i>x, y</i>)
|
208
|
+
*
|
209
|
+
* Set window position.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
rb_move(int argc, VALUE *argv, VALUE self)
|
213
|
+
{
|
214
|
+
int x = 0;
|
215
|
+
int y = 0;
|
216
|
+
switch (argc) {
|
217
|
+
case 1: {
|
218
|
+
CvPoint point = VALUE_TO_CVPOINT(argv[0]);
|
219
|
+
x = point.x;
|
220
|
+
y = point.y;
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
case 2:
|
224
|
+
x = NUM2INT(argv[0]);
|
225
|
+
y = NUM2INT(argv[1]);
|
226
|
+
break;
|
227
|
+
default:
|
228
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
try {
|
232
|
+
cvMoveWindow(GET_WINDOW_NAME(self), x, y);
|
233
|
+
}
|
234
|
+
catch (cv::Exception& e) {
|
235
|
+
raise_cverror(e);
|
236
|
+
}
|
237
|
+
return self;
|
238
|
+
}
|
239
|
+
|
240
|
+
/*
|
241
|
+
* call-seq:
|
242
|
+
* show_image(<i>image</i>)
|
243
|
+
*
|
244
|
+
* Show the image. If the window was created with <i>flags</i> = CV_WINDOW_AUTOSIZE then the image is shown
|
245
|
+
* with its original size, otherwize the image is scaled to fit the window.
|
246
|
+
*/
|
247
|
+
VALUE
|
248
|
+
rb_show_image(VALUE self, VALUE img)
|
249
|
+
{
|
250
|
+
CvArr* image = CVARR_WITH_CHECK(img);
|
251
|
+
WINDOW(self)->image = img;
|
252
|
+
try {
|
253
|
+
cvShowImage(GET_WINDOW_NAME(self), image);
|
254
|
+
}
|
255
|
+
catch (cv::Exception& e) {
|
256
|
+
raise_cverror(e);
|
257
|
+
}
|
258
|
+
return self;
|
259
|
+
}
|
260
|
+
|
261
|
+
void
|
262
|
+
trackbar_callback(int value, void* block)
|
263
|
+
{
|
264
|
+
rb_funcall((VALUE)block, rb_intern("call"), 1, INT2NUM(value));
|
265
|
+
}
|
266
|
+
|
267
|
+
/*
|
268
|
+
* call-seq:
|
269
|
+
* set_trackbar(<i>trackbar</i>)
|
270
|
+
* set_trackbar(<i>name,maxval[,val],&block</i>)
|
271
|
+
* set_trackbar(<i>name,maxval[,val]</i>){|value| ... }
|
272
|
+
*
|
273
|
+
* Create Trackbar on this window. Return new Trackbar.
|
274
|
+
* see Trackbar.new
|
275
|
+
*/
|
276
|
+
VALUE
|
277
|
+
rb_set_trackbar(int argc, VALUE *argv, VALUE self)
|
278
|
+
{
|
279
|
+
VALUE trackbar;
|
280
|
+
if (argc == 1) {
|
281
|
+
trackbar = argv[0];
|
282
|
+
}
|
283
|
+
else {
|
284
|
+
trackbar = cTrackbar::rb_initialize(argc, argv, cTrackbar::rb_allocate(cTrackbar::rb_class()));
|
285
|
+
}
|
286
|
+
Trackbar *trackbar_ptr = TRACKBAR_WITH_CHECK(trackbar);
|
287
|
+
try {
|
288
|
+
cv::createTrackbar(trackbar_ptr->name, GET_WINDOW_NAME(self), &(trackbar_ptr->val), trackbar_ptr->maxval,
|
289
|
+
(cv::TrackbarCallback)trackbar_callback, (void*)(trackbar_ptr->block));
|
290
|
+
}
|
291
|
+
catch (cv::Exception& e) {
|
292
|
+
raise_cverror(e);
|
293
|
+
}
|
294
|
+
rb_ary_push(WINDOW(self)->trackbars, trackbar);
|
295
|
+
|
296
|
+
return trackbar;
|
297
|
+
}
|
298
|
+
|
299
|
+
void
|
300
|
+
on_mouse(int event, int x, int y, int flags, void* param)
|
301
|
+
{
|
302
|
+
VALUE block = (VALUE)param;
|
303
|
+
if (rb_obj_is_kind_of(block, rb_cProc)) {
|
304
|
+
rb_funcall(block, rb_intern("call"), 1, cMouseEvent::new_object(event, x, y, flags));
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
/*
|
309
|
+
* call-seq:
|
310
|
+
* set_mouse_callback(&block)
|
311
|
+
* set_mouse_callback {|mouse_event| ... }
|
312
|
+
*
|
313
|
+
* Set mouse callback.
|
314
|
+
* When the mouse is operated on the window, block will be called.
|
315
|
+
* Return Proc object.
|
316
|
+
* block given mouse event object, see GUI::Window::MouseEvent
|
317
|
+
*
|
318
|
+
* e.g. display mouse event on console.
|
319
|
+
* window = OpenCV::GUI::Window.new "sample window"
|
320
|
+
* image = OpenCV::IplImage::load "sample.png"
|
321
|
+
* window.show(image)
|
322
|
+
* window.set_mouse_callback {|mouse|
|
323
|
+
* e = "#{mouse.x}, #{mouse.y} : #{mouse.event} : "
|
324
|
+
* e << "<L>" if mouse.left_button?
|
325
|
+
* e << "<R>" if mouse.right_button?
|
326
|
+
* e << "<M>" if mouse.middle_button?
|
327
|
+
* e << "[CTRL]" if mouse.ctrl_key?
|
328
|
+
* e << "[SHIFT]" if mouse.shift_key?
|
329
|
+
* e << "[ALT]" if mouse.alt_key?
|
330
|
+
* puts e
|
331
|
+
* }
|
332
|
+
* OpenCV::GUI::wait_key
|
333
|
+
*/
|
334
|
+
VALUE
|
335
|
+
rb_set_mouse_callback(int argc, VALUE* argv, VALUE self)
|
336
|
+
{
|
337
|
+
if (!rb_block_given_p()) {
|
338
|
+
rb_raise(rb_eArgError, "block not given.");
|
339
|
+
}
|
340
|
+
|
341
|
+
VALUE block = Qnil;
|
342
|
+
rb_scan_args(argc, argv, "0&", &block);
|
343
|
+
try {
|
344
|
+
cvSetMouseCallback(GET_WINDOW_NAME(self), on_mouse, (void*)block);
|
345
|
+
}
|
346
|
+
catch (cv::Exception& e) {
|
347
|
+
raise_cverror(e);
|
348
|
+
}
|
349
|
+
|
350
|
+
rb_ary_push(WINDOW(self)->blocks, block);
|
351
|
+
return block;
|
352
|
+
}
|
353
|
+
|
354
|
+
__NAMESPACE_END_WINDOW
|
355
|
+
__NAMESPACE_END_GUI
|
356
|
+
__NAMESPACE_END_OPENCV
|
357
|
+
|