opencv 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +115 -0
- data/README.txt +47 -0
- data/Rakefile +34 -0
- data/examples/convexhull.rb +41 -0
- data/examples/face_detect.rb +25 -0
- data/examples/houghcircle.rb +23 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +43 -0
- data/examples/paint.rb +72 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/ext/curve.cpp +103 -0
- data/ext/curve.h +34 -0
- data/ext/cvavgcomp.cpp +67 -0
- data/ext/cvavgcomp.h +39 -0
- data/ext/cvbox2d.cpp +114 -0
- data/ext/cvbox2d.h +53 -0
- data/ext/cvcapture.cpp +276 -0
- data/ext/cvcapture.h +54 -0
- data/ext/cvchain.cpp +184 -0
- data/ext/cvchain.h +43 -0
- data/ext/cvchaincode.cpp +49 -0
- data/ext/cvchaincode.h +43 -0
- data/ext/cvcircle32f.cpp +90 -0
- data/ext/cvcircle32f.h +53 -0
- data/ext/cvcondensation.cpp +230 -0
- data/ext/cvcondensation.h +49 -0
- data/ext/cvconnectedcomp.cpp +115 -0
- data/ext/cvconnectedcomp.h +46 -0
- data/ext/cvcontour.cpp +219 -0
- data/ext/cvcontour.h +47 -0
- data/ext/cvcontourtree.cpp +86 -0
- data/ext/cvcontourtree.h +41 -0
- data/ext/cvconvexitydefect.cpp +103 -0
- data/ext/cvconvexitydefect.h +42 -0
- data/ext/cverror.cpp +140 -0
- data/ext/cverror.h +79 -0
- data/ext/cvfont.cpp +173 -0
- data/ext/cvfont.h +56 -0
- data/ext/cvhaarclassifiercascade.cpp +159 -0
- data/ext/cvhaarclassifiercascade.h +41 -0
- data/ext/cvhistogram.cpp +200 -0
- data/ext/cvhistogram.h +51 -0
- data/ext/cvindex.cpp +73 -0
- data/ext/cvindex.h +40 -0
- data/ext/cvline.cpp +106 -0
- data/ext/cvline.h +52 -0
- data/ext/cvmat.cpp +4809 -0
- data/ext/cvmat.h +286 -0
- data/ext/cvmatnd.cpp +44 -0
- data/ext/cvmatnd.h +28 -0
- data/ext/cvmemstorage.cpp +64 -0
- data/ext/cvmemstorage.h +53 -0
- data/ext/cvmoments.cpp +204 -0
- data/ext/cvmoments.h +48 -0
- data/ext/cvpoint.cpp +229 -0
- data/ext/cvpoint.h +59 -0
- data/ext/cvpoint2d32f.cpp +213 -0
- data/ext/cvpoint2d32f.h +61 -0
- data/ext/cvpoint3d32f.cpp +245 -0
- data/ext/cvpoint3d32f.h +64 -0
- data/ext/cvrect.cpp +340 -0
- data/ext/cvrect.h +79 -0
- data/ext/cvscalar.cpp +227 -0
- data/ext/cvscalar.h +63 -0
- data/ext/cvseq.cpp +583 -0
- data/ext/cvseq.h +71 -0
- data/ext/cvset.cpp +63 -0
- data/ext/cvset.h +39 -0
- data/ext/cvsize.cpp +223 -0
- data/ext/cvsize.h +63 -0
- data/ext/cvsize2d32f.cpp +180 -0
- data/ext/cvsize2d32f.h +59 -0
- data/ext/cvslice.cpp +82 -0
- data/ext/cvslice.h +53 -0
- data/ext/cvsparsemat.cpp +44 -0
- data/ext/cvsparsemat.h +28 -0
- data/ext/cvtermcriteria.cpp +183 -0
- data/ext/cvtermcriteria.h +71 -0
- data/ext/cvtwopoints.cpp +98 -0
- data/ext/cvtwopoints.h +50 -0
- data/ext/cvvector.cpp +206 -0
- data/ext/cvvector.h +54 -0
- data/ext/cvvideowriter.cpp +116 -0
- data/ext/cvvideowriter.h +41 -0
- data/ext/extconf.rb +61 -0
- data/ext/gui.cpp +65 -0
- data/ext/gui.h +33 -0
- data/ext/iplconvkernel.cpp +177 -0
- data/ext/iplconvkernel.h +52 -0
- data/ext/iplimage.cpp +238 -0
- data/ext/iplimage.h +54 -0
- data/ext/mouseevent.cpp +184 -0
- data/ext/mouseevent.h +59 -0
- data/ext/opencv.cpp +481 -0
- data/ext/opencv.h +356 -0
- data/ext/point3dset.cpp +41 -0
- data/ext/point3dset.h +31 -0
- data/ext/pointset.cpp +238 -0
- data/ext/pointset.h +69 -0
- data/ext/trackbar.cpp +122 -0
- data/ext/trackbar.h +65 -0
- data/ext/window.cpp +368 -0
- data/ext/window.h +56 -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 +3 -0
- data/lib/version.rb +3 -0
- data/setup/setup.cygwin.rb +120 -0
- data/setup/setup.mingw.rb +99 -0
- data/setup/setup.mswin32.rb +103 -0
- data/test/test_opencv.rb +4 -0
- metadata +191 -0
data/ext/cvvector.h
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvvector.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVVECTOR_H
|
11
|
+
#define RUBY_OPENCV_CVVECTOR_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CVVECTOR namespace cCvVector{
|
16
|
+
#define __NAMESPACE_END_CVVECTOR }
|
17
|
+
|
18
|
+
typedef struct CvVector{
|
19
|
+
float x;
|
20
|
+
float y;
|
21
|
+
} CvVector;
|
22
|
+
|
23
|
+
__NAMESPACE_BEGIN_OPENCV
|
24
|
+
__NAMESPACE_BEGIN_CVVECTOR
|
25
|
+
|
26
|
+
VALUE rb_class();
|
27
|
+
|
28
|
+
void define_ruby_class();
|
29
|
+
|
30
|
+
VALUE rb_compatible_q(VALUE klass, VALUE object);
|
31
|
+
|
32
|
+
VALUE rb_allocate(VALUE klass);
|
33
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
34
|
+
VALUE rb_x(VALUE self);
|
35
|
+
VALUE rb_set_x(VALUE self, VALUE x);
|
36
|
+
VALUE rb_y(VALUE self);
|
37
|
+
VALUE rb_set_y(VALUE self, VALUE y);
|
38
|
+
|
39
|
+
VALUE rb_to_s(VALUE self);
|
40
|
+
VALUE rb_to_ary(VALUE self);
|
41
|
+
|
42
|
+
VALUE new_object(CvVector vector);
|
43
|
+
|
44
|
+
__NAMESPACE_END_CVVECTOR
|
45
|
+
|
46
|
+
inline CvVector *CVVECTOR(VALUE object){
|
47
|
+
CvVector *ptr;
|
48
|
+
Data_Get_Struct(object, CvVector, ptr);
|
49
|
+
return ptr;
|
50
|
+
}
|
51
|
+
|
52
|
+
__NAMESPACE_END_OPENCV
|
53
|
+
|
54
|
+
#endif // RUBY_OPENCV_CVVECTOR_H
|
@@ -0,0 +1,116 @@
|
|
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>filanem, fourcc, fps, size</i>) -> cvvideowriter
|
49
|
+
* CvVideoWriter.new(<i>filanem, fourcc, fps, size</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;
|
59
|
+
rb_scan_args(argc, argv, "40", &filename, &fourcc, &fps, &size);
|
60
|
+
char codec[4] = {' ', ' ', ' ', ' '};
|
61
|
+
int codec_number;
|
62
|
+
Check_Type(filename, T_STRING);
|
63
|
+
if (RSTRING(filename)->len == 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(fourcc)->len > 4)
|
70
|
+
rb_raise(rb_eStandardError, "argument 2 (fourcc) should be specific 4-character. (i.e \"PIM1\",\"MJPG\")");
|
71
|
+
else {
|
72
|
+
for (int i = 0; i < RSTRING(fourcc)->len; i++)
|
73
|
+
codec[i] = RSTRING(fourcc)->ptr[i];
|
74
|
+
codec_number = CV_FOURCC(codec[0], codec[1], codec[2], codec[3]);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
DATA_PTR(self) = cvCreateVideoWriter(StringValueCStr(filename), codec_number, FIX2INT(fps), VALUE_TO_CVSIZE(size));
|
78
|
+
if (rb_block_given_p()) {
|
79
|
+
rb_yield(self);
|
80
|
+
rb_close(self);
|
81
|
+
return Qnil;
|
82
|
+
} else {
|
83
|
+
return self;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
/*
|
88
|
+
* call-seq:
|
89
|
+
* write(<i>frame</i>)
|
90
|
+
*
|
91
|
+
* Write image as frame of video stream.
|
92
|
+
* <i>frame</i> should be CvMat or subclass.
|
93
|
+
*/
|
94
|
+
VALUE
|
95
|
+
rb_write(VALUE self, VALUE frame)
|
96
|
+
{
|
97
|
+
if (!rb_obj_is_kind_of(frame, cCvMat::rb_class()))
|
98
|
+
rb_raise(rb_eTypeError, "argument 1 (frame) should be %s or subclass", rb_class2name(cCvMat::rb_class()));
|
99
|
+
cvWriteFrame(CVVIDEOWRITER(self), IPLIMAGE(frame));
|
100
|
+
return self;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* Close vidoe writer.
|
105
|
+
*/
|
106
|
+
VALUE
|
107
|
+
rb_close(VALUE self)
|
108
|
+
{
|
109
|
+
CvVideoWriter *writer = CVVIDEOWRITER(self);
|
110
|
+
cvReleaseVideoWriter(&writer);
|
111
|
+
return Qnil;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
__NAMESPACE_END_CVVIDEOWRITER
|
116
|
+
__NAMESPACE_END_OPENCV
|
data/ext/cvvideowriter.h
ADDED
@@ -0,0 +1,41 @@
|
|
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 *ptr;
|
35
|
+
Data_Get_Struct(object, CvVideoWriter, ptr);
|
36
|
+
return ptr;
|
37
|
+
}
|
38
|
+
|
39
|
+
__NAMESPACE_END_OPENCV
|
40
|
+
|
41
|
+
#endif // RUBY_OPENCV_CVVIDEOWRITER_H
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/env ruby
|
2
|
+
#/usr/local/bin/ruby
|
3
|
+
=begin
|
4
|
+
create Makefile script for Ruby/OpenCV
|
5
|
+
|
6
|
+
usage : ruby extconf.rb
|
7
|
+
make && make install
|
8
|
+
|
9
|
+
VC : ruby extconf.rb
|
10
|
+
nmake
|
11
|
+
=end
|
12
|
+
require "mkmf"
|
13
|
+
|
14
|
+
# option "opencv"
|
15
|
+
# extconf.rb --with-opencv-lib=/path/to/opencv/lib
|
16
|
+
# extconf.rb --with-opencv-include=/path/to/opencv/include
|
17
|
+
|
18
|
+
dir_config("opencv", "/usr/local/include/opencv", "/usr/local/lib")
|
19
|
+
dir_config("ffcall", "/usr/local/include", "/usr/local/lib")
|
20
|
+
|
21
|
+
opencv_libraries = ["cxcore", "cv", "highgui"]
|
22
|
+
|
23
|
+
puts ">> check require libraries..."
|
24
|
+
case CONFIG["arch"]
|
25
|
+
when /mswin32/
|
26
|
+
have_library("msvcrt", nil)
|
27
|
+
opencv_libraries.each{|lib|
|
28
|
+
have_library(lib)
|
29
|
+
}
|
30
|
+
else
|
31
|
+
opencv_libraries.each{|lib|
|
32
|
+
raise "lib#{lib} not found." unless have_library(lib)
|
33
|
+
}
|
34
|
+
#have_library("ml")
|
35
|
+
have_library("stdc++")
|
36
|
+
end
|
37
|
+
|
38
|
+
# check require headers
|
39
|
+
puts ">> check require headers..."
|
40
|
+
opencv_libraries.map{|lib| "#{lib}.h"}.each{|header|
|
41
|
+
raise "#{header} not found." unless have_header(header)
|
42
|
+
}
|
43
|
+
#have_header("ml.h")
|
44
|
+
have_header("stdarg.h")
|
45
|
+
|
46
|
+
# check require functions.
|
47
|
+
# todo
|
48
|
+
|
49
|
+
# optional libraies check.
|
50
|
+
puts ">> ----- optional -----"
|
51
|
+
puts ">> check ffcall..."
|
52
|
+
# check ffcall
|
53
|
+
if have_library("callback") && have_header("callback.h")
|
54
|
+
puts ">> support OpenCV::GUI"
|
55
|
+
else
|
56
|
+
puts ">> ! unsupport OpenCV::GUI (if need it. install ffcall)"
|
57
|
+
puts "http://www.haible.de/bruno/packages-ffcall.html"
|
58
|
+
end
|
59
|
+
|
60
|
+
# step-final. create Makefile
|
61
|
+
create_makefile("opencv")
|
data/ext/gui.cpp
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
gui.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifdef HAVE_CALLBACK_H
|
11
|
+
|
12
|
+
#include "gui.h"
|
13
|
+
/*
|
14
|
+
* Document-module: OpenCV::GUI
|
15
|
+
*
|
16
|
+
* OpenCV simple GUI interface. Provides Window, Trackbar.
|
17
|
+
* This GUI work on GTK or Microsoft Windows native GUI.
|
18
|
+
*/
|
19
|
+
__NAMESPACE_BEGIN_OPENCV
|
20
|
+
__NAMESPACE_BEGIN_GUI
|
21
|
+
|
22
|
+
VALUE rb_module;
|
23
|
+
|
24
|
+
VALUE
|
25
|
+
rb_module_GUI()
|
26
|
+
{
|
27
|
+
return rb_module;
|
28
|
+
}
|
29
|
+
|
30
|
+
void
|
31
|
+
define_ruby_module()
|
32
|
+
{
|
33
|
+
if(rb_module)
|
34
|
+
return;
|
35
|
+
/*
|
36
|
+
* opencv = rb_define_module("OpenCV");
|
37
|
+
*
|
38
|
+
* note: this comment is used by rdoc.
|
39
|
+
*/
|
40
|
+
VALUE opencv = rb_module_opencv();
|
41
|
+
rb_module = rb_define_module_under(opencv, "GUI");
|
42
|
+
rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
|
43
|
+
}
|
44
|
+
|
45
|
+
/*
|
46
|
+
* call-seq:
|
47
|
+
* wait_key(<i>[delay]</i>) -> int or nil
|
48
|
+
*
|
49
|
+
* Waits for a pressed key each GUI wedget.
|
50
|
+
* Return the code of the pressed key or nil if no key were pressed until the specified timeout has elapsed.
|
51
|
+
* <i>delay</i> should be Fixnum. Wait <i>delay</i> millisecond.
|
52
|
+
*/
|
53
|
+
VALUE
|
54
|
+
rb_wait_key(int argc, VALUE *argv, VALUE self)
|
55
|
+
{
|
56
|
+
VALUE delay;
|
57
|
+
rb_scan_args(argc, argv, "01", &delay);
|
58
|
+
int keycode = 0;
|
59
|
+
return ((keycode = cvWaitKey(IF_INT(delay, 0))) < 0) ? Qnil : INT2FIX(keycode);
|
60
|
+
}
|
61
|
+
|
62
|
+
__NAMESPACE_END_GUI
|
63
|
+
__NAMESPACE_END_OPENCV
|
64
|
+
|
65
|
+
#endif // HAVE_CALLBACK_H
|
data/ext/gui.h
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
gui.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifdef HAVE_CALLBACK_H
|
11
|
+
|
12
|
+
#define __NAMESPACE_BEGIN_GUI namespace mGUI{
|
13
|
+
#define __NAMESPACE_END_GUI }
|
14
|
+
|
15
|
+
#ifndef RUBY_OPENCV_GUI_H
|
16
|
+
#define RUBY_OPENCV_GUI_H
|
17
|
+
|
18
|
+
#include "opencv.h"
|
19
|
+
|
20
|
+
__NAMESPACE_BEGIN_OPENCV
|
21
|
+
__NAMESPACE_BEGIN_GUI
|
22
|
+
|
23
|
+
VALUE rb_module_GUI();
|
24
|
+
void define_ruby_module();
|
25
|
+
|
26
|
+
VALUE rb_wait_key(int argc, VALUE *argv, VALUE self);
|
27
|
+
|
28
|
+
__NAMESPACE_END_GUI
|
29
|
+
__NAMESPACE_END_OPENCV
|
30
|
+
|
31
|
+
#endif // RUBY_OPENCV_GUI_H
|
32
|
+
|
33
|
+
#endif // HAVE_CALLBACK_H
|
@@ -0,0 +1,177 @@
|
|
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 OPENCV_OBJECT(klass, 0);
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* IplConvKernel.new(shape, rows, cols, anchor_x, anchor_y)
|
65
|
+
*
|
66
|
+
* Creates structuring element.
|
67
|
+
* shape
|
68
|
+
* Shape of the structuring element; may have the following values:
|
69
|
+
* :rect
|
70
|
+
* :cross
|
71
|
+
* :ellipse
|
72
|
+
* cols
|
73
|
+
* Number of columns in the structuring element.
|
74
|
+
* rows
|
75
|
+
* Number of rows in the structuring element.
|
76
|
+
* anchor_x
|
77
|
+
* Relative horizontal offset of the anchor point.
|
78
|
+
* anchor_y
|
79
|
+
* Relative vertical offset of the anchor point.
|
80
|
+
*
|
81
|
+
*/
|
82
|
+
VALUE
|
83
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
84
|
+
{
|
85
|
+
VALUE shape, rows, cols, anchor_x, anchor_y;
|
86
|
+
rb_scan_args(argc, argv, "50", &shape, &rows, &cols, &anchor_x, &anchor_y);
|
87
|
+
Check_Type(shape, T_SYMBOL);
|
88
|
+
const char *shape_name = rb_id2name(SYM2ID(shape));
|
89
|
+
int shape_type = 0;
|
90
|
+
if (!strcmp(shape_name, "rect"))
|
91
|
+
shape_type = CV_SHAPE_RECT;
|
92
|
+
else if (!strcmp(shape_name, "corss"))
|
93
|
+
shape_type = CV_SHAPE_CROSS;
|
94
|
+
else if (!strcmp(shape_name, "ellipse"))
|
95
|
+
shape_type = CV_SHAPE_ELLIPSE;
|
96
|
+
else
|
97
|
+
rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse.");
|
98
|
+
DATA_PTR(self) = cvCreateStructuringElementEx(NUM2INT(cols), NUM2INT(rows), NUM2INT(anchor_x), NUM2INT(anchor_y), shape_type);
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
/*
|
103
|
+
* call-seq:
|
104
|
+
* size -> cvsize
|
105
|
+
*
|
106
|
+
* Return the structuring element's size.
|
107
|
+
*/
|
108
|
+
VALUE
|
109
|
+
rb_size(VALUE self)
|
110
|
+
{
|
111
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
112
|
+
return cCvSize::new_object(cvSize(kernel->nCols, kernel->nRows));
|
113
|
+
}
|
114
|
+
|
115
|
+
/*
|
116
|
+
* call-seq:
|
117
|
+
* cols -> int
|
118
|
+
*
|
119
|
+
* Return number of columns in the structuring element.
|
120
|
+
*/
|
121
|
+
VALUE
|
122
|
+
rb_cols(VALUE self)
|
123
|
+
{
|
124
|
+
return INT2NUM(IPLCONVKERNEL(self)->nCols);
|
125
|
+
}
|
126
|
+
|
127
|
+
/*
|
128
|
+
* call-seq:
|
129
|
+
* rows -> int
|
130
|
+
*
|
131
|
+
* Return number of rows in the structuring element.
|
132
|
+
*/
|
133
|
+
VALUE
|
134
|
+
rb_rows(VALUE self)
|
135
|
+
{
|
136
|
+
return INT2NUM(IPLCONVKERNEL(self)->nRows);
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* call-seq:
|
141
|
+
* anchor -> cvpoint
|
142
|
+
*
|
143
|
+
* Return anchor of the structuring element.
|
144
|
+
*/
|
145
|
+
VALUE
|
146
|
+
rb_anchor(VALUE self)
|
147
|
+
{
|
148
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
149
|
+
return cCvPoint::new_object(cvPoint(kernel->anchorX, kernel->anchorY));
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* call-seq:
|
154
|
+
* anchor_x -> int
|
155
|
+
*
|
156
|
+
* Return relative horizontal offset of the anchor point.
|
157
|
+
*/
|
158
|
+
VALUE
|
159
|
+
rb_anchor_x(VALUE self)
|
160
|
+
{
|
161
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorX);
|
162
|
+
}
|
163
|
+
|
164
|
+
/*
|
165
|
+
* call-seq:
|
166
|
+
* anchor_y -> int
|
167
|
+
*
|
168
|
+
* Return relative vertical offset of the anchor point.
|
169
|
+
*/
|
170
|
+
VALUE
|
171
|
+
rb_anchor_y(VALUE self)
|
172
|
+
{
|
173
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorY);
|
174
|
+
}
|
175
|
+
|
176
|
+
__NAMESPACE_END_IPLCONVKERNEL
|
177
|
+
__NAMESPACE_END_OPENCV
|