afeld-opencv 0.0.8
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.
- data/.gitignore +23 -0
- data/Gemfile +6 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +217 -0
- data/README.rdoc +161 -0
- data/Rakefile +52 -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/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 +499 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +230 -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 +297 -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 +5627 -0
- data/ext/opencv/cvmat.h +280 -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 +246 -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 +72 -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 +194 -0
- data/ext/opencv/cvutils.h +29 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -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 +576 -0
- data/ext/opencv/iplimage.h +70 -0
- data/ext/opencv/lib/opencv.rb +3 -0
- data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
- data/ext/opencv/lib/opencv/version.rb +3 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +710 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +284 -0
- data/ext/opencv/pointset.h +69 -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/extconf.rb +65 -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/test/helper.rb +146 -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/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 +2752 -0
- data/test/test_cvmat_drawing.rb +318 -0
- data/test/test_cvmat_dxt.rb +147 -0
- data/test/test_cvmat_imageprocessing.rb +1943 -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 +156 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +340 -0
- data/test/test_pointset.rb +130 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +399 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvvideowriter.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvvideowriter.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvVideoWriter
|
13
|
+
*
|
14
|
+
* Create video stream from images.
|
15
|
+
*
|
16
|
+
* C structure is "black box".
|
17
|
+
*/
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVVIDEOWRITER
|
20
|
+
|
21
|
+
VALUE rb_klass;
|
22
|
+
|
23
|
+
VALUE
|
24
|
+
rb_class()
|
25
|
+
{
|
26
|
+
return rb_klass;
|
27
|
+
}
|
28
|
+
|
29
|
+
void
|
30
|
+
define_ruby_class()
|
31
|
+
{
|
32
|
+
if (rb_klass)
|
33
|
+
return;
|
34
|
+
/*
|
35
|
+
* opencv = rb_define_module("OpenCV");
|
36
|
+
*
|
37
|
+
* note: this comment is used by rdoc.
|
38
|
+
*/
|
39
|
+
VALUE opencv = rb_module_opencv();
|
40
|
+
rb_klass = rb_define_class_under(opencv, "CvVideoWriter", rb_cObject);
|
41
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
42
|
+
rb_define_method(rb_klass, "write", RUBY_METHOD_FUNC(rb_write), 1);
|
43
|
+
rb_define_method(rb_klass, "close", RUBY_METHOD_FUNC(rb_close), 0);
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* call-seq:
|
48
|
+
* CvVideoWriter.new(<i>filname, fourcc, fps, size[, is_color]</i>) -> cvvideowriter
|
49
|
+
* CvVideoWriter.new(<i>filname, fourcc, fps, size[, is_color]</i>){|vw| ... } -> nil
|
50
|
+
*
|
51
|
+
* Open new video writer. If block given, writer is closed automatically when end of block.
|
52
|
+
*
|
53
|
+
* note: if <i>fourcc</i> is nil, popup codec select dialog (Windows only).
|
54
|
+
*/
|
55
|
+
VALUE
|
56
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
57
|
+
{
|
58
|
+
VALUE filename, fourcc, fps, size, is_color_val;
|
59
|
+
rb_scan_args(argc, argv, "41", &filename, &fourcc, &fps, &size, &is_color_val);
|
60
|
+
char codec[4] = {' ', ' ', ' ', ' '};
|
61
|
+
int codec_number;
|
62
|
+
Check_Type(filename, T_STRING);
|
63
|
+
if (RSTRING_LEN(filename) == 0)
|
64
|
+
rb_raise(rb_eArgError, "argument 1 (file name) dose not given");
|
65
|
+
if (NIL_P(fourcc))
|
66
|
+
codec_number = -1;
|
67
|
+
else {
|
68
|
+
Check_Type(fourcc, T_STRING);
|
69
|
+
if (RSTRING_LEN(fourcc) > 4)
|
70
|
+
rb_raise(rb_eStandardError, "argument 2 (fourcc) should be specific 4-character. (i.e \"PIM1\",\"MJPG\")");
|
71
|
+
else {
|
72
|
+
int len = RSTRING_LEN(fourcc);
|
73
|
+
for (int i = 0; i < len; ++i)
|
74
|
+
codec[i] = RSTRING_PTR(fourcc)[i];
|
75
|
+
codec_number = CV_FOURCC(codec[0], codec[1], codec[2], codec[3]);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
int is_color;
|
79
|
+
if (NIL_P(is_color_val))
|
80
|
+
is_color = 1;
|
81
|
+
else
|
82
|
+
is_color = (is_color_val == Qtrue) ? 1 : 0;
|
83
|
+
try {
|
84
|
+
DATA_PTR(self) = cvCreateVideoWriter(StringValueCStr(filename), codec_number,
|
85
|
+
NUM2DBL(fps), VALUE_TO_CVSIZE(size), is_color);
|
86
|
+
}
|
87
|
+
catch (cv::Exception& e) {
|
88
|
+
raise_cverror(e);
|
89
|
+
}
|
90
|
+
if (rb_block_given_p()) {
|
91
|
+
rb_yield(self);
|
92
|
+
rb_close(self);
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
else
|
96
|
+
return self;
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
* call-seq:
|
101
|
+
* write(<i>frame</i>)
|
102
|
+
*
|
103
|
+
* Write image as frame of video stream.
|
104
|
+
* <i>frame</i> should be IplImage
|
105
|
+
*/
|
106
|
+
VALUE
|
107
|
+
rb_write(VALUE self, VALUE frame)
|
108
|
+
{
|
109
|
+
try {
|
110
|
+
cvWriteFrame(CVVIDEOWRITER(self), IPLIMAGE_WITH_CHECK(frame));
|
111
|
+
}
|
112
|
+
catch (cv::Exception& e) {
|
113
|
+
raise_cverror(e);
|
114
|
+
}
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
/*
|
119
|
+
* Close vidoe writer.
|
120
|
+
*/
|
121
|
+
VALUE
|
122
|
+
rb_close(VALUE self)
|
123
|
+
{
|
124
|
+
CvVideoWriter *writer = CVVIDEOWRITER(self);
|
125
|
+
try {
|
126
|
+
if (writer)
|
127
|
+
cvReleaseVideoWriter(&writer);
|
128
|
+
}
|
129
|
+
catch (cv::Exception& e) {
|
130
|
+
raise_cverror(e);
|
131
|
+
}
|
132
|
+
return Qnil;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
__NAMESPACE_END_CVVIDEOWRITER
|
137
|
+
__NAMESPACE_END_OPENCV
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvvideowriter.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVVIDEOWRITER_H
|
11
|
+
#define RUBY_OPENCV_CVVIDEOWRITER_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVVIDEOWRITER namespace cCvVideoWriter {
|
16
|
+
#define __NAMESPACE_END_CVVIDEOWRITER }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVVIDEOWRITER
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
26
|
+
VALUE rb_write(VALUE self, VALUE frame);
|
27
|
+
VALUE rb_close(VALUE self);
|
28
|
+
|
29
|
+
__NAMESPACE_END_CVVIDEOWRITER
|
30
|
+
|
31
|
+
inline CvVideoWriter*
|
32
|
+
CVVIDEOWRITER(VALUE object)
|
33
|
+
{
|
34
|
+
// CvVideoWriter is
|
35
|
+
// CvVideoWriter *ptr;
|
36
|
+
// Data_Get_Struct(object, CvVideoWriter, ptr);
|
37
|
+
// return ptr;
|
38
|
+
return (CvVideoWriter*)DATA_PTR(object);
|
39
|
+
}
|
40
|
+
|
41
|
+
__NAMESPACE_END_OPENCV
|
42
|
+
|
43
|
+
#endif // RUBY_OPENCV_CVVIDEOWRITER_H
|
data/ext/opencv/gui.cpp
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
gui.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "gui.h"
|
11
|
+
/*
|
12
|
+
* Document-module: OpenCV::GUI
|
13
|
+
*
|
14
|
+
* OpenCV simple GUI interface. Provides Window, Trackbar.
|
15
|
+
* This GUI work on GTK or Microsoft Windows native GUI.
|
16
|
+
*/
|
17
|
+
__NAMESPACE_BEGIN_OPENCV
|
18
|
+
__NAMESPACE_BEGIN_GUI
|
19
|
+
|
20
|
+
VALUE rb_module;
|
21
|
+
|
22
|
+
VALUE
|
23
|
+
rb_module_GUI()
|
24
|
+
{
|
25
|
+
return rb_module;
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
define_ruby_module()
|
30
|
+
{
|
31
|
+
if (rb_module)
|
32
|
+
return;
|
33
|
+
/*
|
34
|
+
* opencv = rb_define_module("OpenCV");
|
35
|
+
*
|
36
|
+
* note: this comment is used by rdoc.
|
37
|
+
*/
|
38
|
+
VALUE opencv = rb_module_opencv();
|
39
|
+
rb_module = rb_define_module_under(opencv, "GUI");
|
40
|
+
rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* wait_key(<i>[delay]</i>) -> int or nil
|
46
|
+
*
|
47
|
+
* Waits for a pressed key each GUI wedget.
|
48
|
+
* Return the code of the pressed key or nil if no key were pressed until the specified timeout has elapsed.
|
49
|
+
* <i>delay</i> should be Fixnum. Wait <i>delay</i> millisecond.
|
50
|
+
*/
|
51
|
+
VALUE
|
52
|
+
rb_wait_key(int argc, VALUE *argv, VALUE self)
|
53
|
+
{
|
54
|
+
VALUE delay;
|
55
|
+
rb_scan_args(argc, argv, "01", &delay);
|
56
|
+
int keycode = 0;
|
57
|
+
try {
|
58
|
+
keycode = cvWaitKey(IF_INT(delay, 0));
|
59
|
+
}
|
60
|
+
catch (cv::Exception& e) {
|
61
|
+
raise_cverror(e);
|
62
|
+
}
|
63
|
+
return (keycode < 0) ? Qnil : INT2NUM(keycode);
|
64
|
+
}
|
65
|
+
|
66
|
+
__NAMESPACE_END_GUI
|
67
|
+
__NAMESPACE_END_OPENCV
|
68
|
+
|
data/ext/opencv/gui.h
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
gui.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_GUI_H
|
11
|
+
#define RUBY_OPENCV_GUI_H
|
12
|
+
|
13
|
+
#define __NAMESPACE_BEGIN_GUI namespace mGUI {
|
14
|
+
#define __NAMESPACE_END_GUI }
|
15
|
+
|
16
|
+
#include "opencv.h"
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_GUI
|
20
|
+
|
21
|
+
VALUE rb_module_GUI();
|
22
|
+
void define_ruby_module();
|
23
|
+
|
24
|
+
VALUE rb_wait_key(int argc, VALUE *argv, VALUE self);
|
25
|
+
|
26
|
+
__NAMESPACE_END_GUI
|
27
|
+
__NAMESPACE_END_OPENCV
|
28
|
+
|
29
|
+
#endif // RUBY_OPENCV_GUI_H
|
30
|
+
|
@@ -0,0 +1,192 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
iplconvkernel.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "iplconvkernel.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::IplConvKernel
|
13
|
+
*
|
14
|
+
* Structuring element can be used in the morphological operations.
|
15
|
+
*
|
16
|
+
* CvMat#erode, CvMat#dilate, CvMat#morphology_open, CvMat#morphology_close,
|
17
|
+
* CvMat#morphology_gradient, CvMat#morphology_tophat, CvMat#morphology_blackhat
|
18
|
+
*
|
19
|
+
* Create by IplConvKernel.new or CvMat#to_IplConvKernel
|
20
|
+
*/
|
21
|
+
__NAMESPACE_BEGIN_OPENCV
|
22
|
+
__NAMESPACE_BEGIN_IPLCONVKERNEL
|
23
|
+
|
24
|
+
VALUE rb_klass;
|
25
|
+
|
26
|
+
VALUE
|
27
|
+
rb_class()
|
28
|
+
{
|
29
|
+
return rb_klass;
|
30
|
+
}
|
31
|
+
|
32
|
+
void
|
33
|
+
define_ruby_class()
|
34
|
+
{
|
35
|
+
if (rb_klass)
|
36
|
+
return;
|
37
|
+
/*
|
38
|
+
* opencv = rb_define_module("OpenCV");
|
39
|
+
*
|
40
|
+
* note: this comment is used by rdoc.
|
41
|
+
*/
|
42
|
+
VALUE opencv = rb_module_opencv();
|
43
|
+
rb_klass = rb_define_class_under(opencv, "IplConvKernel", rb_cObject);
|
44
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
45
|
+
|
46
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
47
|
+
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
|
48
|
+
rb_define_method(rb_klass, "cols", RUBY_METHOD_FUNC(rb_cols), 0);
|
49
|
+
rb_define_alias(rb_klass, "columns", "cols");
|
50
|
+
rb_define_method(rb_klass, "rows", RUBY_METHOD_FUNC(rb_rows), 0);
|
51
|
+
rb_define_method(rb_klass, "anchor", RUBY_METHOD_FUNC(rb_anchor), 0);
|
52
|
+
rb_define_method(rb_klass, "anchor_x", RUBY_METHOD_FUNC(rb_anchor_x), 0);
|
53
|
+
rb_define_method(rb_klass, "anchor_y", RUBY_METHOD_FUNC(rb_anchor_y), 0);
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE
|
57
|
+
rb_allocate(VALUE klass)
|
58
|
+
{
|
59
|
+
return IPLCONVKERNEL_OBJECT(klass, 0);
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* IplConvKernel.new(cols, rows, anchor_x, anchor_y, shape [,values = nil])
|
65
|
+
*
|
66
|
+
* Creates structuring element.
|
67
|
+
* cols
|
68
|
+
* Number of columns in the structuring element.
|
69
|
+
* rows
|
70
|
+
* Number of rows in the structuring element.
|
71
|
+
* anchor_x
|
72
|
+
* Relative horizontal offset of the anchor point.
|
73
|
+
* anchor_y
|
74
|
+
* Relative vertical offset of the anchor point.
|
75
|
+
* shape
|
76
|
+
* Shape of the structuring element; may have the following values:
|
77
|
+
* :rect
|
78
|
+
* :cross
|
79
|
+
* :ellipse
|
80
|
+
* :custom
|
81
|
+
*
|
82
|
+
*/
|
83
|
+
VALUE
|
84
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
85
|
+
{
|
86
|
+
VALUE shape, rows, cols, anchor_x, anchor_y, values;
|
87
|
+
rb_scan_args(argc, argv, "51", &cols, &rows, &anchor_x, &anchor_y, &shape, &values);
|
88
|
+
int shape_type;
|
89
|
+
int _cols = NUM2INT(cols);
|
90
|
+
int _rows = NUM2INT(rows);
|
91
|
+
int num_values;
|
92
|
+
int *_values = NULL;
|
93
|
+
const int INVALID_SHAPE = -1;
|
94
|
+
|
95
|
+
shape_type = CVMETHOD("STRUCTURING_ELEMENT_SHAPE", shape, INVALID_SHAPE);
|
96
|
+
if (shape_type == INVALID_SHAPE)
|
97
|
+
rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse or :custom.");
|
98
|
+
if (shape_type == CV_SHAPE_CUSTOM) {
|
99
|
+
if (NIL_P(values))
|
100
|
+
rb_raise(rb_eArgError, "argument 6 (values) should not be nil when the shape is :custom.");
|
101
|
+
num_values = RARRAY_LEN(values);
|
102
|
+
_values = ALLOCA_N(int, num_values);
|
103
|
+
VALUE *values_ptr = RARRAY_PTR(values);
|
104
|
+
for (int i = 0; i < num_values; ++i)
|
105
|
+
_values[i] = NUM2INT(values_ptr[i]);
|
106
|
+
}
|
107
|
+
try {
|
108
|
+
DATA_PTR(self) = rb_cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),
|
109
|
+
shape_type, _values);
|
110
|
+
}
|
111
|
+
catch (cv::Exception& e) {
|
112
|
+
raise_cverror(e);
|
113
|
+
}
|
114
|
+
return self;
|
115
|
+
}
|
116
|
+
|
117
|
+
/*
|
118
|
+
* call-seq:
|
119
|
+
* size -> cvsize
|
120
|
+
*
|
121
|
+
* Return the structuring element's size.
|
122
|
+
*/
|
123
|
+
VALUE
|
124
|
+
rb_size(VALUE self)
|
125
|
+
{
|
126
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
127
|
+
return cCvSize::new_object(cvSize(kernel->nCols, kernel->nRows));
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* call-seq:
|
132
|
+
* cols -> int
|
133
|
+
*
|
134
|
+
* Return number of columns in the structuring element.
|
135
|
+
*/
|
136
|
+
VALUE
|
137
|
+
rb_cols(VALUE self)
|
138
|
+
{
|
139
|
+
return INT2NUM(IPLCONVKERNEL(self)->nCols);
|
140
|
+
}
|
141
|
+
|
142
|
+
/*
|
143
|
+
* call-seq:
|
144
|
+
* rows -> int
|
145
|
+
*
|
146
|
+
* Return number of rows in the structuring element.
|
147
|
+
*/
|
148
|
+
VALUE
|
149
|
+
rb_rows(VALUE self)
|
150
|
+
{
|
151
|
+
return INT2NUM(IPLCONVKERNEL(self)->nRows);
|
152
|
+
}
|
153
|
+
|
154
|
+
/*
|
155
|
+
* call-seq:
|
156
|
+
* anchor -> cvpoint
|
157
|
+
*
|
158
|
+
* Return anchor of the structuring element.
|
159
|
+
*/
|
160
|
+
VALUE
|
161
|
+
rb_anchor(VALUE self)
|
162
|
+
{
|
163
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
164
|
+
return cCvPoint::new_object(cvPoint(kernel->anchorX, kernel->anchorY));
|
165
|
+
}
|
166
|
+
|
167
|
+
/*
|
168
|
+
* call-seq:
|
169
|
+
* anchor_x -> int
|
170
|
+
*
|
171
|
+
* Return relative horizontal offset of the anchor point.
|
172
|
+
*/
|
173
|
+
VALUE
|
174
|
+
rb_anchor_x(VALUE self)
|
175
|
+
{
|
176
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorX);
|
177
|
+
}
|
178
|
+
|
179
|
+
/*
|
180
|
+
* call-seq:
|
181
|
+
* anchor_y -> int
|
182
|
+
*
|
183
|
+
* Return relative vertical offset of the anchor point.
|
184
|
+
*/
|
185
|
+
VALUE
|
186
|
+
rb_anchor_y(VALUE self)
|
187
|
+
{
|
188
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorY);
|
189
|
+
}
|
190
|
+
|
191
|
+
__NAMESPACE_END_IPLCONVKERNEL
|
192
|
+
__NAMESPACE_END_OPENCV
|