bonanza-ruby-opencv 0.0.13.20140330211753
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.yardopts +3 -0
- data/DEVELOPERS_NOTE.md +137 -0
- data/Gemfile +9 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +239 -0
- data/README.md +98 -0
- data/Rakefile +99 -0
- data/config.yml +7 -0
- data/examples/alpha_blend.rb +21 -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/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/images/box.png +0 -0
- data/examples/images/box_in_scene.png +0 -0
- data/examples/images/inpaint.png +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/images/lenna-rotated.jpg +0 -0
- data/examples/images/lenna.jpg +0 -0
- data/examples/images/stuff.jpg +0 -0
- data/examples/images/tiffany.jpg +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/match_template.rb +26 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/ext/opencv/algorithm.cpp +291 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/curve.cpp +127 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +64 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +195 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +607 -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 +126 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvconnectedcomp.cpp +156 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +332 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +96 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +92 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +115 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +123 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +228 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +148 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +715 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +178 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +159 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +6829 -0
- data/ext/opencv/cvmat.h +323 -0
- data/ext/opencv/cvmemstorage.cpp +73 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +293 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +265 -0
- data/ext/opencv/cvpoint.h +67 -0
- data/ext/opencv/cvpoint2d32f.cpp +216 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +252 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +441 -0
- data/ext/opencv/cvrect.h +88 -0
- data/ext/opencv/cvscalar.cpp +301 -0
- data/ext/opencv/cvscalar.h +76 -0
- data/ext/opencv/cvseq.cpp +605 -0
- data/ext/opencv/cvseq.h +74 -0
- data/ext/opencv/cvsize.cpp +227 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +215 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +126 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsurfparams.cpp +208 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +279 -0
- data/ext/opencv/cvsurfpoint.h +54 -0
- data/ext/opencv/cvtermcriteria.cpp +198 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +122 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +221 -0
- data/ext/opencv/cvutils.h +31 -0
- data/ext/opencv/cvvideowriter.cpp +142 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/eigenfaces.cpp +75 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +82 -0
- data/ext/opencv/facerecognizer.cpp +181 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +75 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/gui.cpp +71 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +198 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +666 -0
- data/ext/opencv/iplimage.h +75 -0
- data/ext/opencv/lbph.cpp +78 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/mouseevent.cpp +186 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +833 -0
- data/ext/opencv/opencv.h +405 -0
- data/ext/opencv/pointset.cpp +280 -0
- data/ext/opencv/pointset.h +68 -0
- data/ext/opencv/trackbar.cpp +127 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +377 -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/lib/opencv.rb +12 -0
- data/lib/opencv/psyched_yaml.rb +22 -0
- data/lib/opencv/version.rb +4 -0
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +166 -0
- data/test/lbph_save.xml +4304 -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 +3003 -0
- data/test/test_cvmat_drawing.rb +349 -0
- data/test/test_cvmat_dxt.rb +150 -0
- data/test/test_cvmat_imageprocessing.rb +2085 -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_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +232 -0
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +360 -0
- data/test/test_pointset.rb +128 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- data/yard_extension.rb +5 -0
- metadata +399 -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 init_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,127 @@
|
|
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
|
+
VALUE rb_allocate(VALUE klass) {
|
29
|
+
Trackbar *ptr;
|
30
|
+
return Data_Make_Struct(klass, Trackbar, trackbar_mark, trackbar_free, ptr);
|
31
|
+
}
|
32
|
+
|
33
|
+
void trackbar_mark(void *ptr) {
|
34
|
+
rb_gc_mark(((Trackbar*)ptr)->block);
|
35
|
+
}
|
36
|
+
|
37
|
+
void trackbar_free(void *ptr) {
|
38
|
+
Trackbar *trackbar = (Trackbar*)ptr;
|
39
|
+
free(trackbar->name);
|
40
|
+
free(trackbar);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* new(name,maxval[,val],&block)
|
46
|
+
* new(name,maxval[,val]){|value| ... }
|
47
|
+
*
|
48
|
+
* Create new Trackbar.
|
49
|
+
* <i>name</i> should be String.
|
50
|
+
* <i>maxval</i> and <i>val</i> should be Fixnum.
|
51
|
+
* When Trackbar adjuster changed, block will be called.
|
52
|
+
*/
|
53
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self) {
|
54
|
+
VALUE name, maxval, val, block;
|
55
|
+
rb_scan_args(argc, argv, "21&", &name, &maxval, &val, &block);
|
56
|
+
if (NIL_P(block))
|
57
|
+
rb_raise(rb_eArgError, "block not given.");
|
58
|
+
Check_Type(name, T_STRING);
|
59
|
+
Trackbar *trackbar = TRACKBAR(self);
|
60
|
+
trackbar->name = strcpy(ALLOC_N(char, RSTRING_LEN(name) + 1), StringValueCStr(name));
|
61
|
+
trackbar->maxval = NUM2INT(maxval);
|
62
|
+
trackbar->val = IF_INT(val, 0);
|
63
|
+
trackbar->block = block;
|
64
|
+
return self;
|
65
|
+
}
|
66
|
+
|
67
|
+
/*
|
68
|
+
* Return trackbar name.
|
69
|
+
*/
|
70
|
+
VALUE rb_name(VALUE self) {
|
71
|
+
return rb_str_new2(TRACKBAR(self)->name);
|
72
|
+
}
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Return the maximum value that can be taken this trackbar.
|
76
|
+
*/
|
77
|
+
VALUE rb_max(VALUE self) {
|
78
|
+
return INT2NUM(TRACKBAR(self)->maxval);
|
79
|
+
}
|
80
|
+
|
81
|
+
/*
|
82
|
+
* Return the value of this trackbar.
|
83
|
+
*/
|
84
|
+
VALUE rb_value(VALUE self) {
|
85
|
+
return INT2NUM(TRACKBAR(self)->val);
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* call-seq:
|
90
|
+
* value = <i>val</i>
|
91
|
+
*
|
92
|
+
* Set trackbar value.
|
93
|
+
*/
|
94
|
+
VALUE rb_set_value(VALUE self, VALUE val) {
|
95
|
+
TRACKBAR(self)->val = NUM2INT(val);
|
96
|
+
return self;
|
97
|
+
}
|
98
|
+
|
99
|
+
void init_ruby_class() {
|
100
|
+
#if 0
|
101
|
+
// For documentation using YARD
|
102
|
+
VALUE opencv = rb_define_module("OpenCV");
|
103
|
+
VALUE GUI = rb_define_module_under(opencv, "GUI");
|
104
|
+
#endif
|
105
|
+
|
106
|
+
if (rb_klass)
|
107
|
+
return;
|
108
|
+
/*
|
109
|
+
* opencv = rb_define_module("OpenCV");
|
110
|
+
* GUI = rb_define_module_under(opencv, "GUI");
|
111
|
+
*
|
112
|
+
* note: this comment is used by rdoc.
|
113
|
+
*/
|
114
|
+
VALUE GUI = rb_module_GUI();
|
115
|
+
rb_klass = rb_define_class_under(GUI, "Trackbar", rb_cObject);
|
116
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
117
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
118
|
+
rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0);
|
119
|
+
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
|
120
|
+
rb_define_method(rb_klass, "value", RUBY_METHOD_FUNC(rb_value), 0);
|
121
|
+
rb_define_method(rb_klass, "value=", RUBY_METHOD_FUNC(rb_set_value), 1);
|
122
|
+
}
|
123
|
+
|
124
|
+
__NAMESPACE_END_TRACKBAR
|
125
|
+
__NAMESPACE_END_GUI
|
126
|
+
__NAMESPACE_END_OPENCV
|
127
|
+
|
@@ -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 init_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,377 @@
|
|
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
|
+
VALUE
|
36
|
+
rb_allocate(VALUE klass)
|
37
|
+
{
|
38
|
+
Window *ptr;
|
39
|
+
return Data_Make_Struct(klass, Window, window_mark, window_free, ptr);
|
40
|
+
}
|
41
|
+
|
42
|
+
void
|
43
|
+
window_mark(void *ptr)
|
44
|
+
{
|
45
|
+
Window* window_ptr = (Window*)ptr;
|
46
|
+
rb_gc_mark(window_ptr->name);
|
47
|
+
rb_gc_mark(window_ptr->image);
|
48
|
+
rb_gc_mark(window_ptr->trackbars);
|
49
|
+
rb_gc_mark(window_ptr->blocks);
|
50
|
+
}
|
51
|
+
|
52
|
+
void
|
53
|
+
window_free(void *ptr)
|
54
|
+
{
|
55
|
+
free(ptr);
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Creates a window.
|
60
|
+
*
|
61
|
+
* @overload new(name, flags = CV_WINDOW_AUTOSIZE)
|
62
|
+
* @param name [String] Name of the window in the window caption that may be used as a window identifier.
|
63
|
+
* @param flags [Integer] Flags of the window. The supported flags are:
|
64
|
+
* * CV_WINDOW_AUTOSIZE - If this is set, the window size is automatically adjusted
|
65
|
+
* to fit the displayed image, and you cannot change the window size manually.
|
66
|
+
* * CV_WINDOW_NORMAL - If this is set, the user can resize the window (no constraint).
|
67
|
+
* * CV_WINDOW_OPENGL - If this is set, the window will be created with OpenGL support.
|
68
|
+
* @opencv_func cvNamedWindow
|
69
|
+
*/
|
70
|
+
VALUE
|
71
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
72
|
+
{
|
73
|
+
VALUE name, flags;
|
74
|
+
rb_scan_args(argc, argv, "11", &name, &flags);
|
75
|
+
Check_Type(name, T_STRING);
|
76
|
+
char* name_str = StringValueCStr(name);
|
77
|
+
if (cvGetWindowHandle(name_str) != NULL) {
|
78
|
+
rb_raise(rb_eStandardError, "window name should be unique.");
|
79
|
+
}
|
80
|
+
|
81
|
+
int mode = CV_WINDOW_AUTOSIZE;
|
82
|
+
if (argc == 2) {
|
83
|
+
Check_Type(flags, T_FIXNUM);
|
84
|
+
mode = FIX2INT(flags);
|
85
|
+
}
|
86
|
+
|
87
|
+
Window* self_ptr = WINDOW(self);
|
88
|
+
self_ptr->name = name;
|
89
|
+
self_ptr->trackbars = rb_ary_new();
|
90
|
+
self_ptr->blocks = rb_ary_new();
|
91
|
+
try {
|
92
|
+
cvNamedWindow(name_str, mode);
|
93
|
+
}
|
94
|
+
catch (cv::Exception& e) {
|
95
|
+
raise_cverror(e);
|
96
|
+
}
|
97
|
+
num_windows++;
|
98
|
+
return self;
|
99
|
+
}
|
100
|
+
|
101
|
+
/*
|
102
|
+
* Return alive status of window. Return true if alive, otherwise return false.
|
103
|
+
*/
|
104
|
+
VALUE
|
105
|
+
rb_alive_q(VALUE self)
|
106
|
+
{
|
107
|
+
const char* name_str = GET_WINDOW_NAME(self);
|
108
|
+
return (cvGetWindowHandle(name_str) == NULL) ? Qfalse : Qtrue;
|
109
|
+
}
|
110
|
+
|
111
|
+
/*
|
112
|
+
* Destroys a window. alive status of window be false.
|
113
|
+
*/
|
114
|
+
VALUE
|
115
|
+
rb_destroy(VALUE self)
|
116
|
+
{
|
117
|
+
const char* name_str = GET_WINDOW_NAME(self);
|
118
|
+
try {
|
119
|
+
cvDestroyWindow(name_str);
|
120
|
+
}
|
121
|
+
catch (cv::Exception& e) {
|
122
|
+
raise_cverror(e);
|
123
|
+
}
|
124
|
+
num_windows--;
|
125
|
+
return self;
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* Destorys all the windows.
|
130
|
+
*/
|
131
|
+
VALUE
|
132
|
+
rb_destroy_all(VALUE klass)
|
133
|
+
{
|
134
|
+
if (num_windows > 0) {
|
135
|
+
try {
|
136
|
+
cvDestroyAllWindows();
|
137
|
+
}
|
138
|
+
catch (cv::Exception& e) {
|
139
|
+
raise_cverror(e);
|
140
|
+
}
|
141
|
+
num_windows = 0;
|
142
|
+
}
|
143
|
+
return Qnil;
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Resizes window to the specified size.
|
148
|
+
*
|
149
|
+
* @overload resize(size)
|
150
|
+
* @param size [CvSize] The new window size.
|
151
|
+
* @overload resize(width, height)
|
152
|
+
* @param width [Integer] The new window width.
|
153
|
+
* @param height [Integer] The new window height.
|
154
|
+
* @opencv_func cvResizeWindow
|
155
|
+
*/
|
156
|
+
VALUE
|
157
|
+
rb_resize(int argc, VALUE *argv, VALUE self)
|
158
|
+
{
|
159
|
+
int width = 0;
|
160
|
+
int height = 0;
|
161
|
+
switch (argc) {
|
162
|
+
case 1: {
|
163
|
+
CvSize size = VALUE_TO_CVSIZE(argv[0]);
|
164
|
+
width = size.width;
|
165
|
+
height = size.height;
|
166
|
+
break;
|
167
|
+
}
|
168
|
+
case 2:
|
169
|
+
width = NUM2INT(argv[0]);
|
170
|
+
height = NUM2INT(argv[1]);
|
171
|
+
break;
|
172
|
+
default:
|
173
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
174
|
+
break;
|
175
|
+
}
|
176
|
+
try {
|
177
|
+
cvResizeWindow(GET_WINDOW_NAME(self), width, height);
|
178
|
+
}
|
179
|
+
catch (cv::Exception& e) {
|
180
|
+
raise_cverror(e);
|
181
|
+
}
|
182
|
+
return self;
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* Moves window to the specified position.
|
187
|
+
*
|
188
|
+
* @overload move(point)
|
189
|
+
* @param point [CvPoint] The new coordinate of the window.
|
190
|
+
* @overload move(x, y)
|
191
|
+
* @param x [Integer] The new x-coordinate of the window.
|
192
|
+
* @param y [Integer] The new y-coordinate of the window.
|
193
|
+
* @opencv_func cvMoveWindow
|
194
|
+
*/
|
195
|
+
VALUE
|
196
|
+
rb_move(int argc, VALUE *argv, VALUE self)
|
197
|
+
{
|
198
|
+
int x = 0;
|
199
|
+
int y = 0;
|
200
|
+
switch (argc) {
|
201
|
+
case 1: {
|
202
|
+
CvPoint point = VALUE_TO_CVPOINT(argv[0]);
|
203
|
+
x = point.x;
|
204
|
+
y = point.y;
|
205
|
+
break;
|
206
|
+
}
|
207
|
+
case 2:
|
208
|
+
x = NUM2INT(argv[0]);
|
209
|
+
y = NUM2INT(argv[1]);
|
210
|
+
break;
|
211
|
+
default:
|
212
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
213
|
+
break;
|
214
|
+
}
|
215
|
+
try {
|
216
|
+
cvMoveWindow(GET_WINDOW_NAME(self), x, y);
|
217
|
+
}
|
218
|
+
catch (cv::Exception& e) {
|
219
|
+
raise_cverror(e);
|
220
|
+
}
|
221
|
+
return self;
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* Displays an image in the specified window.
|
226
|
+
*
|
227
|
+
* @overload show_image(image)
|
228
|
+
* @param image [CvMat] Image to be shown.
|
229
|
+
* @opencv_func cvShowImage
|
230
|
+
*/
|
231
|
+
VALUE
|
232
|
+
rb_show_image(VALUE self, VALUE img)
|
233
|
+
{
|
234
|
+
CvArr* image = CVARR_WITH_CHECK(img);
|
235
|
+
WINDOW(self)->image = img;
|
236
|
+
try {
|
237
|
+
cvShowImage(GET_WINDOW_NAME(self), image);
|
238
|
+
}
|
239
|
+
catch (cv::Exception& e) {
|
240
|
+
raise_cverror(e);
|
241
|
+
}
|
242
|
+
return self;
|
243
|
+
}
|
244
|
+
|
245
|
+
void
|
246
|
+
trackbar_callback(int value, void* block)
|
247
|
+
{
|
248
|
+
rb_funcall((VALUE)block, rb_intern("call"), 1, INT2NUM(value));
|
249
|
+
}
|
250
|
+
|
251
|
+
/*
|
252
|
+
* Creates or sets a trackbar and attaches it to the specified window.
|
253
|
+
*
|
254
|
+
* @overload set_trackbar(trackbar)
|
255
|
+
* @param trackbar [TrackBar] The trackbar to set.
|
256
|
+
*
|
257
|
+
* @overload set_trackbar(name, count, value = nil) { |value| ... }
|
258
|
+
* @param name [String] Name of the created trackbar.
|
259
|
+
* @param count [Integer] Maximal position of the slider. The minimal position is always 0.
|
260
|
+
* @param value [Integer] Optional value to an integer variable whose value reflects the position of the slider.
|
261
|
+
* Upon creation, the slider position is defined by this variable.
|
262
|
+
* @yield [value] Function to be called every time the slider changes position.
|
263
|
+
* @yieldparam value [Integer] The trackbar position.
|
264
|
+
* @opencv_func cv::createTrackbar
|
265
|
+
*/
|
266
|
+
VALUE
|
267
|
+
rb_set_trackbar(int argc, VALUE *argv, VALUE self)
|
268
|
+
{
|
269
|
+
VALUE trackbar;
|
270
|
+
if (argc == 1) {
|
271
|
+
trackbar = argv[0];
|
272
|
+
}
|
273
|
+
else {
|
274
|
+
trackbar = cTrackbar::rb_initialize(argc, argv, cTrackbar::rb_allocate(cTrackbar::rb_class()));
|
275
|
+
}
|
276
|
+
Trackbar *trackbar_ptr = TRACKBAR_WITH_CHECK(trackbar);
|
277
|
+
try {
|
278
|
+
cv::createTrackbar(trackbar_ptr->name, GET_WINDOW_NAME(self), &(trackbar_ptr->val), trackbar_ptr->maxval,
|
279
|
+
(cv::TrackbarCallback)trackbar_callback, (void*)(trackbar_ptr->block));
|
280
|
+
}
|
281
|
+
catch (cv::Exception& e) {
|
282
|
+
raise_cverror(e);
|
283
|
+
}
|
284
|
+
rb_ary_push(WINDOW(self)->trackbars, trackbar);
|
285
|
+
|
286
|
+
return trackbar;
|
287
|
+
}
|
288
|
+
|
289
|
+
void
|
290
|
+
on_mouse(int event, int x, int y, int flags, void* param)
|
291
|
+
{
|
292
|
+
VALUE block = (VALUE)param;
|
293
|
+
if (rb_obj_is_kind_of(block, rb_cProc)) {
|
294
|
+
rb_funcall(block, rb_intern("call"), 1, cMouseEvent::new_object(event, x, y, flags));
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
/*
|
299
|
+
* Sets mouse handler for the specified window.
|
300
|
+
*
|
301
|
+
* @overload set_mouse_callback { |mouse_event| ... }
|
302
|
+
* @yield [mouse_event] Mouse callback.
|
303
|
+
* @yieldparam mouse_event [MouseEvent] Mouse event
|
304
|
+
*
|
305
|
+
* @example display mouse event on console
|
306
|
+
* window = OpenCV::GUI::Window.new "sample window"
|
307
|
+
* image = OpenCV::IplImage::load "sample.png"
|
308
|
+
* window.show(image)
|
309
|
+
* window.set_mouse_callback {|mouse|
|
310
|
+
* e = "#{mouse.x}, #{mouse.y} : #{mouse.event} : "
|
311
|
+
* e << "<L>" if mouse.left_button?
|
312
|
+
* e << "<R>" if mouse.right_button?
|
313
|
+
* e << "<M>" if mouse.middle_button?
|
314
|
+
* e << "[CTRL]" if mouse.ctrl_key?
|
315
|
+
* e << "[SHIFT]" if mouse.shift_key?
|
316
|
+
* e << "[ALT]" if mouse.alt_key?
|
317
|
+
* puts e
|
318
|
+
* }
|
319
|
+
* OpenCV::GUI::wait_key
|
320
|
+
*/
|
321
|
+
VALUE
|
322
|
+
rb_set_mouse_callback(int argc, VALUE* argv, VALUE self)
|
323
|
+
{
|
324
|
+
if (!rb_block_given_p()) {
|
325
|
+
rb_raise(rb_eArgError, "block not given.");
|
326
|
+
}
|
327
|
+
|
328
|
+
VALUE block = Qnil;
|
329
|
+
rb_scan_args(argc, argv, "0&", &block);
|
330
|
+
try {
|
331
|
+
cvSetMouseCallback(GET_WINDOW_NAME(self), on_mouse, (void*)block);
|
332
|
+
}
|
333
|
+
catch (cv::Exception& e) {
|
334
|
+
raise_cverror(e);
|
335
|
+
}
|
336
|
+
|
337
|
+
rb_ary_push(WINDOW(self)->blocks, block);
|
338
|
+
return block;
|
339
|
+
}
|
340
|
+
|
341
|
+
void
|
342
|
+
init_ruby_class()
|
343
|
+
{
|
344
|
+
#if 0
|
345
|
+
// For documentation using YARD
|
346
|
+
VALUE opencv = rb_define_module("OpenCV");
|
347
|
+
VALUE GUI = rb_define_module_under(opencv, "GUI");
|
348
|
+
#endif
|
349
|
+
|
350
|
+
if (rb_klass)
|
351
|
+
return;
|
352
|
+
/*
|
353
|
+
* opencv = rb_define_module("OpenCV");
|
354
|
+
* GUI = rb_define_module_under(opencv, "GUI");
|
355
|
+
*
|
356
|
+
* note: this comment is used by rdoc.
|
357
|
+
*/
|
358
|
+
VALUE GUI = rb_module_GUI();
|
359
|
+
rb_klass = rb_define_class_under(GUI, "Window", rb_cObject);
|
360
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
361
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
362
|
+
rb_define_method(rb_klass, "alive?", RUBY_METHOD_FUNC(rb_alive_q), 0);
|
363
|
+
rb_define_method(rb_klass, "destroy", RUBY_METHOD_FUNC(rb_destroy), 0);
|
364
|
+
rb_define_singleton_method(rb_klass, "destroy_all", RUBY_METHOD_FUNC(rb_destroy_all), 0);
|
365
|
+
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -1);
|
366
|
+
rb_define_method(rb_klass, "move", RUBY_METHOD_FUNC(rb_move), -1);
|
367
|
+
rb_define_method(rb_klass, "show_image", RUBY_METHOD_FUNC(rb_show_image), 1);
|
368
|
+
rb_define_alias(rb_klass, "show", "show_image");
|
369
|
+
rb_define_method(rb_klass, "set_trackbar", RUBY_METHOD_FUNC(rb_set_trackbar), -1);
|
370
|
+
rb_define_method(rb_klass, "set_mouse_callback", RUBY_METHOD_FUNC(rb_set_mouse_callback), -1);
|
371
|
+
rb_define_alias(rb_klass, "on_mouse", "set_mouse_callback");
|
372
|
+
}
|
373
|
+
|
374
|
+
__NAMESPACE_END_WINDOW
|
375
|
+
__NAMESPACE_END_GUI
|
376
|
+
__NAMESPACE_END_OPENCV
|
377
|
+
|