bonanza-ruby-opencv 0.0.13.20140330211753
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.
- 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,46 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
facerecognizer.h
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_FACERECOGNIZER_H
|
11
|
+
#define RUBY_OPENCV_FACERECOGNIZER_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_FACERECOGNIZER namespace cFaceRecognizer {
|
16
|
+
#define __NAMESPACE_END_FACERECOGNIZER }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_FACERECOGNIZER
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
VALUE rb_train(VALUE self, VALUE src, VALUE labels);
|
25
|
+
VALUE rb_predict(VALUE self, VALUE src);
|
26
|
+
VALUE rb_save(VALUE self, VALUE filename);
|
27
|
+
VALUE rb_load(VALUE self, VALUE filename);
|
28
|
+
|
29
|
+
void guard_facerecognizer(void* data_ptr, cv::Ptr<cv::FaceRecognizer> ptr);
|
30
|
+
void release_facerecognizer(void *data_ptr);
|
31
|
+
VALUE allocate_facerecognizer(VALUE klass);
|
32
|
+
|
33
|
+
__NAMESPACE_END_FACERECOGNIZER
|
34
|
+
|
35
|
+
inline cv::FaceRecognizer*
|
36
|
+
FACERECOGNIZER(VALUE object)
|
37
|
+
{
|
38
|
+
cv::FaceRecognizer *ptr;
|
39
|
+
Data_Get_Struct(object, cv::FaceRecognizer, ptr);
|
40
|
+
return ptr;
|
41
|
+
}
|
42
|
+
|
43
|
+
__NAMESPACE_END_OPENCV
|
44
|
+
|
45
|
+
#endif // RUBY_OPENCV_FACERECOGNIZER_H
|
46
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
fisherfaces.cpp -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include <stdio.h>
|
11
|
+
#include "fisherfaces.h"
|
12
|
+
/*
|
13
|
+
* Document-class: OpenCV::FisherFaces
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_FISHERFACES
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* call-seq:
|
29
|
+
* FisherFaces.new(num_components=0, threshold=DBL_MAX)
|
30
|
+
*/
|
31
|
+
VALUE
|
32
|
+
rb_initialize(int argc, VALUE argv[], VALUE self)
|
33
|
+
{
|
34
|
+
VALUE num_components_val, threshold_val;
|
35
|
+
rb_scan_args(argc, argv, "02", &num_components_val, &threshold_val);
|
36
|
+
|
37
|
+
int num_components = NIL_P(num_components_val) ? 0 : NUM2INT(num_components_val);
|
38
|
+
double threshold = NIL_P(threshold_val) ? DBL_MAX : NUM2DBL(threshold_val);
|
39
|
+
|
40
|
+
free(DATA_PTR(self));
|
41
|
+
cv::Ptr<cv::FaceRecognizer> ptr = cv::createFisherFaceRecognizer(num_components, threshold);
|
42
|
+
DATA_PTR(self) = ptr;
|
43
|
+
|
44
|
+
cFaceRecognizer::guard_facerecognizer(DATA_PTR(self), ptr);
|
45
|
+
|
46
|
+
return self;
|
47
|
+
}
|
48
|
+
|
49
|
+
void
|
50
|
+
init_ruby_class()
|
51
|
+
{
|
52
|
+
#if 0
|
53
|
+
// For documentation using YARD
|
54
|
+
VALUE opencv = rb_define_module("OpenCV");
|
55
|
+
VALUE alghorithm = rb_define_class_under(opencv, "Algorithm", rb_cObject);
|
56
|
+
VALUE face_recognizer = rb_define_class_under(opencv, "FaceRecognizer", alghorithm);
|
57
|
+
#endif
|
58
|
+
|
59
|
+
if (rb_klass)
|
60
|
+
return;
|
61
|
+
/*
|
62
|
+
* opencv = rb_define_module("OpenCV");
|
63
|
+
*
|
64
|
+
* note: this comment is used by rdoc.
|
65
|
+
*/
|
66
|
+
VALUE opencv = rb_module_opencv();
|
67
|
+
VALUE face_recognizer = cFaceRecognizer::rb_class();
|
68
|
+
rb_klass = rb_define_class_under(opencv, "FisherFaces", face_recognizer);
|
69
|
+
rb_define_alloc_func(rb_klass, cFaceRecognizer::allocate_facerecognizer);
|
70
|
+
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
71
|
+
}
|
72
|
+
|
73
|
+
__NAMESPACE_END_FISHERFACES
|
74
|
+
__NAMESPACE_END_OPENCV
|
75
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
fisherfaces.h
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_FISHERFACES_H
|
11
|
+
#define RUBY_OPENCV_FISHERFACES_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_FISHERFACES namespace cFisherFaces {
|
16
|
+
#define __NAMESPACE_END_FISHERFACES }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_FISHERFACES
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
VALUE rb_initialize(int argc, VALUE argv[], VALUE self);
|
25
|
+
|
26
|
+
__NAMESPACE_END_FISHERFACES
|
27
|
+
__NAMESPACE_END_OPENCV
|
28
|
+
|
29
|
+
#endif // RUBY_OPENCV_FISHERFACES_H
|
30
|
+
|
data/ext/opencv/gui.cpp
ADDED
@@ -0,0 +1,71 @@
|
|
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
|
+
__NAMESPACE_BEGIN_OPENCV
|
15
|
+
__NAMESPACE_BEGIN_GUI
|
16
|
+
|
17
|
+
VALUE rb_module;
|
18
|
+
|
19
|
+
VALUE
|
20
|
+
rb_module_GUI()
|
21
|
+
{
|
22
|
+
return rb_module;
|
23
|
+
}
|
24
|
+
|
25
|
+
/*
|
26
|
+
* Waits for a pressed key.
|
27
|
+
*
|
28
|
+
* @overload wait_key(delay = 0)
|
29
|
+
* @param delay [Integer] Delay in milliseconds. 0 is the special value that means "forever".
|
30
|
+
* @return [Number] The code of the pressed key or <tt>nil</tt> if no key was pressed
|
31
|
+
* before the specified time had elapsed.
|
32
|
+
* @opencv_func cvWaitKey
|
33
|
+
*/
|
34
|
+
VALUE
|
35
|
+
rb_wait_key(int argc, VALUE *argv, VALUE self)
|
36
|
+
{
|
37
|
+
VALUE delay;
|
38
|
+
rb_scan_args(argc, argv, "01", &delay);
|
39
|
+
int keycode = 0;
|
40
|
+
try {
|
41
|
+
keycode = cvWaitKey(IF_INT(delay, 0));
|
42
|
+
}
|
43
|
+
catch (cv::Exception& e) {
|
44
|
+
raise_cverror(e);
|
45
|
+
}
|
46
|
+
return (keycode < 0) ? Qnil : INT2NUM(keycode);
|
47
|
+
}
|
48
|
+
|
49
|
+
void
|
50
|
+
init_ruby_module()
|
51
|
+
{
|
52
|
+
#if 0
|
53
|
+
// For documentation using YARD
|
54
|
+
VALUE opencv = rb_define_module("OpenCV");
|
55
|
+
#endif
|
56
|
+
|
57
|
+
if (rb_module)
|
58
|
+
return;
|
59
|
+
/*
|
60
|
+
* opencv = rb_define_module("OpenCV");
|
61
|
+
*
|
62
|
+
* note: this comment is used by rdoc.
|
63
|
+
*/
|
64
|
+
VALUE opencv = rb_module_opencv();
|
65
|
+
rb_module = rb_define_module_under(opencv, "GUI");
|
66
|
+
rb_define_singleton_method(rb_module, "wait_key", RUBY_METHOD_FUNC(rb_wait_key), -1);
|
67
|
+
}
|
68
|
+
|
69
|
+
__NAMESPACE_END_GUI
|
70
|
+
__NAMESPACE_END_OPENCV
|
71
|
+
|
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 init_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,198 @@
|
|
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
|
+
VALUE
|
33
|
+
rb_allocate(VALUE klass)
|
34
|
+
{
|
35
|
+
return IPLCONVKERNEL_OBJECT(klass, 0);
|
36
|
+
}
|
37
|
+
|
38
|
+
/*
|
39
|
+
* call-seq:
|
40
|
+
* IplConvKernel.new(cols, rows, anchor_x, anchor_y, shape [,values = nil])
|
41
|
+
*
|
42
|
+
* Creates structuring element.
|
43
|
+
* cols
|
44
|
+
* Number of columns in the structuring element.
|
45
|
+
* rows
|
46
|
+
* Number of rows in the structuring element.
|
47
|
+
* anchor_x
|
48
|
+
* Relative horizontal offset of the anchor point.
|
49
|
+
* anchor_y
|
50
|
+
* Relative vertical offset of the anchor point.
|
51
|
+
* shape
|
52
|
+
* Shape of the structuring element; may have the following values:
|
53
|
+
* :rect
|
54
|
+
* :cross
|
55
|
+
* :ellipse
|
56
|
+
* :custom
|
57
|
+
*
|
58
|
+
*/
|
59
|
+
VALUE
|
60
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
61
|
+
{
|
62
|
+
VALUE shape, rows, cols, anchor_x, anchor_y, values;
|
63
|
+
rb_scan_args(argc, argv, "51", &cols, &rows, &anchor_x, &anchor_y, &shape, &values);
|
64
|
+
int shape_type;
|
65
|
+
int _cols = NUM2INT(cols);
|
66
|
+
int _rows = NUM2INT(rows);
|
67
|
+
int num_values;
|
68
|
+
int *_values = NULL;
|
69
|
+
const int INVALID_SHAPE = -1;
|
70
|
+
|
71
|
+
shape_type = CVMETHOD("STRUCTURING_ELEMENT_SHAPE", shape, INVALID_SHAPE);
|
72
|
+
if (shape_type == INVALID_SHAPE)
|
73
|
+
rb_raise(rb_eTypeError, "argument 1 (shape) should be :rect or :cross or :ellipse or :custom.");
|
74
|
+
if (shape_type == CV_SHAPE_CUSTOM) {
|
75
|
+
if (NIL_P(values))
|
76
|
+
rb_raise(rb_eArgError, "argument 6 (values) should not be nil when the shape is :custom.");
|
77
|
+
num_values = RARRAY_LEN(values);
|
78
|
+
_values = ALLOCA_N(int, num_values);
|
79
|
+
VALUE *values_ptr = RARRAY_PTR(values);
|
80
|
+
for (int i = 0; i < num_values; ++i)
|
81
|
+
_values[i] = NUM2INT(values_ptr[i]);
|
82
|
+
}
|
83
|
+
try {
|
84
|
+
DATA_PTR(self) = rb_cvCreateStructuringElementEx(_cols, _rows, NUM2INT(anchor_x), NUM2INT(anchor_y),
|
85
|
+
shape_type, _values);
|
86
|
+
}
|
87
|
+
catch (cv::Exception& e) {
|
88
|
+
raise_cverror(e);
|
89
|
+
}
|
90
|
+
return self;
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
* call-seq:
|
95
|
+
* size -> cvsize
|
96
|
+
*
|
97
|
+
* Return the structuring element's size.
|
98
|
+
*/
|
99
|
+
VALUE
|
100
|
+
rb_size(VALUE self)
|
101
|
+
{
|
102
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
103
|
+
return cCvSize::new_object(cvSize(kernel->nCols, kernel->nRows));
|
104
|
+
}
|
105
|
+
|
106
|
+
/*
|
107
|
+
* call-seq:
|
108
|
+
* cols -> int
|
109
|
+
*
|
110
|
+
* Return number of columns in the structuring element.
|
111
|
+
*/
|
112
|
+
VALUE
|
113
|
+
rb_cols(VALUE self)
|
114
|
+
{
|
115
|
+
return INT2NUM(IPLCONVKERNEL(self)->nCols);
|
116
|
+
}
|
117
|
+
|
118
|
+
/*
|
119
|
+
* call-seq:
|
120
|
+
* rows -> int
|
121
|
+
*
|
122
|
+
* Return number of rows in the structuring element.
|
123
|
+
*/
|
124
|
+
VALUE
|
125
|
+
rb_rows(VALUE self)
|
126
|
+
{
|
127
|
+
return INT2NUM(IPLCONVKERNEL(self)->nRows);
|
128
|
+
}
|
129
|
+
|
130
|
+
/*
|
131
|
+
* call-seq:
|
132
|
+
* anchor -> cvpoint
|
133
|
+
*
|
134
|
+
* Return anchor of the structuring element.
|
135
|
+
*/
|
136
|
+
VALUE
|
137
|
+
rb_anchor(VALUE self)
|
138
|
+
{
|
139
|
+
IplConvKernel *kernel = IPLCONVKERNEL(self);
|
140
|
+
return cCvPoint::new_object(cvPoint(kernel->anchorX, kernel->anchorY));
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* anchor_x -> int
|
146
|
+
*
|
147
|
+
* Return relative horizontal offset of the anchor point.
|
148
|
+
*/
|
149
|
+
VALUE
|
150
|
+
rb_anchor_x(VALUE self)
|
151
|
+
{
|
152
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorX);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* anchor_y -> int
|
158
|
+
*
|
159
|
+
* Return relative vertical offset of the anchor point.
|
160
|
+
*/
|
161
|
+
VALUE
|
162
|
+
rb_anchor_y(VALUE self)
|
163
|
+
{
|
164
|
+
return INT2NUM(IPLCONVKERNEL(self)->anchorY);
|
165
|
+
}
|
166
|
+
|
167
|
+
void
|
168
|
+
init_ruby_class()
|
169
|
+
{
|
170
|
+
#if 0
|
171
|
+
// For documentation using YARD
|
172
|
+
VALUE opencv = rb_define_module("OpenCV");
|
173
|
+
#endif
|
174
|
+
|
175
|
+
if (rb_klass)
|
176
|
+
return;
|
177
|
+
/*
|
178
|
+
* opencv = rb_define_module("OpenCV");
|
179
|
+
*
|
180
|
+
* note: this comment is used by rdoc.
|
181
|
+
*/
|
182
|
+
VALUE opencv = rb_module_opencv();
|
183
|
+
rb_klass = rb_define_class_under(opencv, "IplConvKernel", rb_cObject);
|
184
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
185
|
+
|
186
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
187
|
+
rb_define_method(rb_klass, "size", RUBY_METHOD_FUNC(rb_size), 0);
|
188
|
+
rb_define_method(rb_klass, "cols", RUBY_METHOD_FUNC(rb_cols), 0);
|
189
|
+
rb_define_alias(rb_klass, "columns", "cols");
|
190
|
+
rb_define_method(rb_klass, "rows", RUBY_METHOD_FUNC(rb_rows), 0);
|
191
|
+
rb_define_method(rb_klass, "anchor", RUBY_METHOD_FUNC(rb_anchor), 0);
|
192
|
+
rb_define_method(rb_klass, "anchor_x", RUBY_METHOD_FUNC(rb_anchor_x), 0);
|
193
|
+
rb_define_method(rb_klass, "anchor_y", RUBY_METHOD_FUNC(rb_anchor_y), 0);
|
194
|
+
}
|
195
|
+
|
196
|
+
__NAMESPACE_END_IPLCONVKERNEL
|
197
|
+
__NAMESPACE_END_OPENCV
|
198
|
+
|