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,31 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvutils.h -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2011 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
|
11
|
+
#include <ruby.h>
|
12
|
+
#include "opencv2/core/core_c.h"
|
13
|
+
#include "opencv2/core/core.hpp"
|
14
|
+
#include "opencv2/core/internal.hpp"
|
15
|
+
#include "opencv2/imgproc/imgproc_c.h"
|
16
|
+
#include "opencv2/imgproc/imgproc.hpp"
|
17
|
+
|
18
|
+
#define raise_cverror(e) cCvError::raise(e)
|
19
|
+
|
20
|
+
void raise_typeerror(VALUE object, VALUE expected_class);
|
21
|
+
void raise_typeerror(VALUE object, const char* expected_class_name);
|
22
|
+
void raise_compatible_typeerror(VALUE object, VALUE expected_class);
|
23
|
+
void raise_compatible_typeerror(VALUE object, const char* expected_class_name);
|
24
|
+
void* rb_cvAlloc(size_t size);
|
25
|
+
CvMat* rb_cvCreateMat(int height, int width, int type);
|
26
|
+
CvMatND* rb_cvCreateMatND(int dims, const int* sizes, int type);
|
27
|
+
IplImage* rb_cvCreateImage(CvSize size, int depth, int channels);
|
28
|
+
IplConvKernel* rb_cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, int shape, int *values);
|
29
|
+
CvMemStorage* rb_cvCreateMemStorage(int block_size);
|
30
|
+
VALUE rb_get_option_table(VALUE klass, const char* table_name, VALUE option);
|
31
|
+
|
@@ -0,0 +1,142 @@
|
|
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
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* CvVideoWriter.new(filname, fourcc, fps, size[, is_color]) -> cvvideowriter
|
32
|
+
* CvVideoWriter.new(filname, fourcc, fps, size[, is_color]){|vw| ... } -> nil
|
33
|
+
*
|
34
|
+
* Open new video writer. If block given, writer is closed automatically when end of block.
|
35
|
+
*
|
36
|
+
* note: if <i>fourcc</i> is nil, popup codec select dialog (Windows only).
|
37
|
+
*/
|
38
|
+
VALUE
|
39
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
40
|
+
{
|
41
|
+
VALUE filename, fourcc, fps, size, is_color_val;
|
42
|
+
rb_scan_args(argc, argv, "41", &filename, &fourcc, &fps, &size, &is_color_val);
|
43
|
+
char codec[4] = {' ', ' ', ' ', ' '};
|
44
|
+
int codec_number;
|
45
|
+
Check_Type(filename, T_STRING);
|
46
|
+
if (RSTRING_LEN(filename) == 0)
|
47
|
+
rb_raise(rb_eArgError, "argument 1 (file name) dose not given");
|
48
|
+
if (NIL_P(fourcc))
|
49
|
+
codec_number = -1;
|
50
|
+
else {
|
51
|
+
Check_Type(fourcc, T_STRING);
|
52
|
+
if (RSTRING_LEN(fourcc) > 4)
|
53
|
+
rb_raise(rb_eStandardError, "argument 2 (fourcc) should be specific 4-character. (i.e \"PIM1\",\"MJPG\")");
|
54
|
+
else {
|
55
|
+
int len = RSTRING_LEN(fourcc);
|
56
|
+
for (int i = 0; i < len; ++i)
|
57
|
+
codec[i] = RSTRING_PTR(fourcc)[i];
|
58
|
+
codec_number = CV_FOURCC(codec[0], codec[1], codec[2], codec[3]);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
int is_color;
|
62
|
+
if (NIL_P(is_color_val))
|
63
|
+
is_color = 1;
|
64
|
+
else
|
65
|
+
is_color = (is_color_val == Qtrue) ? 1 : 0;
|
66
|
+
try {
|
67
|
+
DATA_PTR(self) = cvCreateVideoWriter(StringValueCStr(filename), codec_number,
|
68
|
+
NUM2DBL(fps), VALUE_TO_CVSIZE(size), is_color);
|
69
|
+
}
|
70
|
+
catch (cv::Exception& e) {
|
71
|
+
raise_cverror(e);
|
72
|
+
}
|
73
|
+
if (rb_block_given_p()) {
|
74
|
+
rb_yield(self);
|
75
|
+
rb_close(self);
|
76
|
+
return Qnil;
|
77
|
+
}
|
78
|
+
else
|
79
|
+
return self;
|
80
|
+
}
|
81
|
+
|
82
|
+
/*
|
83
|
+
* call-seq:
|
84
|
+
* write(frame)
|
85
|
+
*
|
86
|
+
* Write image as frame of video stream.
|
87
|
+
* <i>frame</i> should be IplImage
|
88
|
+
*/
|
89
|
+
VALUE
|
90
|
+
rb_write(VALUE self, VALUE frame)
|
91
|
+
{
|
92
|
+
try {
|
93
|
+
cvWriteFrame(CVVIDEOWRITER(self), IPLIMAGE_WITH_CHECK(frame));
|
94
|
+
}
|
95
|
+
catch (cv::Exception& e) {
|
96
|
+
raise_cverror(e);
|
97
|
+
}
|
98
|
+
return self;
|
99
|
+
}
|
100
|
+
|
101
|
+
/*
|
102
|
+
* Close vidoe writer.
|
103
|
+
*/
|
104
|
+
VALUE
|
105
|
+
rb_close(VALUE self)
|
106
|
+
{
|
107
|
+
CvVideoWriter *writer = CVVIDEOWRITER(self);
|
108
|
+
try {
|
109
|
+
if (writer)
|
110
|
+
cvReleaseVideoWriter(&writer);
|
111
|
+
}
|
112
|
+
catch (cv::Exception& e) {
|
113
|
+
raise_cverror(e);
|
114
|
+
}
|
115
|
+
return Qnil;
|
116
|
+
}
|
117
|
+
|
118
|
+
void
|
119
|
+
init_ruby_class()
|
120
|
+
{
|
121
|
+
#if 0
|
122
|
+
// For documentation using YARD
|
123
|
+
VALUE opencv = rb_define_module("OpenCV");
|
124
|
+
#endif
|
125
|
+
|
126
|
+
if (rb_klass)
|
127
|
+
return;
|
128
|
+
/*
|
129
|
+
* opencv = rb_define_module("OpenCV");
|
130
|
+
*
|
131
|
+
* note: this comment is used by rdoc.
|
132
|
+
*/
|
133
|
+
VALUE opencv = rb_module_opencv();
|
134
|
+
rb_klass = rb_define_class_under(opencv, "CvVideoWriter", rb_cObject);
|
135
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
136
|
+
rb_define_method(rb_klass, "write", RUBY_METHOD_FUNC(rb_write), 1);
|
137
|
+
rb_define_method(rb_klass, "close", RUBY_METHOD_FUNC(rb_close), 0);
|
138
|
+
}
|
139
|
+
|
140
|
+
__NAMESPACE_END_CVVIDEOWRITER
|
141
|
+
__NAMESPACE_END_OPENCV
|
142
|
+
|
@@ -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 init_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
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
eigenfaces.cpp -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include <stdio.h>
|
11
|
+
#include "eigenfaces.h"
|
12
|
+
/*
|
13
|
+
* Document-class: OpenCV::EigenFaces
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_EIGENFACES
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* call-seq:
|
29
|
+
* EigenFaces.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::createEigenFaceRecognizer(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, "EigenFaces", 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_EIGENFACES
|
74
|
+
__NAMESPACE_END_OPENCV
|
75
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
eigenfaces.h
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_EIGENFACES_H
|
11
|
+
#define RUBY_OPENCV_EIGENFACES_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_EIGENFACES namespace cEigenFaces {
|
16
|
+
#define __NAMESPACE_END_EIGENFACES }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_EIGENFACES
|
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_EIGENFACES
|
27
|
+
__NAMESPACE_END_OPENCV
|
28
|
+
|
29
|
+
#endif // RUBY_OPENCV_EIGENFACES_H
|
30
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
CC = RbConfig::CONFIG['CC']
|
4
|
+
if CC =~ /clang/
|
5
|
+
RbConfig::MAKEFILE_CONFIG['try_header'] = :try_cpp
|
6
|
+
RbConfig::CONFIG['CPP'] = "#{CC} -E"
|
7
|
+
elsif RbConfig::CONFIG['arch'] =~ /mswin32/
|
8
|
+
RbConfig::MAKEFILE_CONFIG['try_header'] = :try_cpp
|
9
|
+
RbConfig::CONFIG['CPP'] = "#{CC} /P"
|
10
|
+
end
|
11
|
+
|
12
|
+
require "mkmf"
|
13
|
+
|
14
|
+
if enable_config('debug')
|
15
|
+
$CPPFLAGS << ' -ggdb3 -O0'
|
16
|
+
$CFLAGS << ' -ggdb3 -O0'
|
17
|
+
end
|
18
|
+
|
19
|
+
def cv_version_suffix(incdir)
|
20
|
+
major, minor, subminor = nil, nil, nil
|
21
|
+
open("#{incdir}/opencv2/core/version.hpp", 'r') { |f|
|
22
|
+
f.read.lines.each { |line|
|
23
|
+
major = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_EPOCH|CV_MAJOR_VERSION)\s+(\d+)\s*\Z/
|
24
|
+
minor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MAJOR|CV_MINOR_VERSION)\s+(\d+)\s*\Z/
|
25
|
+
subminor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MINOR|CV_SUBMINOR_VERSION)\s+(\d+)\s*\Z/
|
26
|
+
}
|
27
|
+
}
|
28
|
+
major + minor + subminor
|
29
|
+
end
|
30
|
+
|
31
|
+
# Quick fix for 2.0.0
|
32
|
+
# @libdir_basename is set to nil and dir_config() sets invalid libdir '${opencv-dir}/' when --with-opencv-dir option passed.
|
33
|
+
@libdir_basename ||= 'lib'
|
34
|
+
incdir, libdir = dir_config("opencv", "/usr/local/include", "/usr/local/lib")
|
35
|
+
dir_config("libxml2", "/usr/include", "/usr/lib")
|
36
|
+
|
37
|
+
opencv_headers = ["opencv2/core/core_c.h", "opencv2/core/core.hpp", "opencv2/imgproc/imgproc_c.h",
|
38
|
+
"opencv2/imgproc/imgproc.hpp", "opencv2/video/tracking.hpp", "opencv2/features2d/features2d.hpp",
|
39
|
+
"opencv2/flann/flann.hpp", "opencv2/calib3d/calib3d.hpp", "opencv2/objdetect/objdetect.hpp",
|
40
|
+
"opencv2/legacy/compat.hpp", "opencv2/legacy/legacy.hpp", "opencv2/highgui/highgui_c.h",
|
41
|
+
"opencv2/highgui/highgui.hpp", "opencv2/photo/photo.hpp"]
|
42
|
+
opencv_headers_opt = ["opencv2/nonfree/nonfree.hpp"]
|
43
|
+
|
44
|
+
opencv_libraries = ["opencv_calib3d", "opencv_contrib", "opencv_core", "opencv_features2d",
|
45
|
+
"opencv_flann", "opencv_highgui", "opencv_imgproc", "opencv_legacy",
|
46
|
+
"opencv_ml", "opencv_objdetect", "opencv_video", "opencv_photo"]
|
47
|
+
opencv_libraries_opt = ["opencv_gpu", "opencv_nonfree"]
|
48
|
+
|
49
|
+
puts ">> Check the required libraries..."
|
50
|
+
if $mswin or $mingw
|
51
|
+
suffix = cv_version_suffix(incdir)
|
52
|
+
opencv_libraries.map! { |lib| lib + suffix }
|
53
|
+
opencv_libraries_opt.map! { |lib| lib + suffix }
|
54
|
+
have_library("msvcrt")
|
55
|
+
if $mswin
|
56
|
+
$CFLAGS << ' /EHsc'
|
57
|
+
CONFIG['CXXFLAGS'] << ' /EHsc'
|
58
|
+
end
|
59
|
+
else
|
60
|
+
have_library("stdc++")
|
61
|
+
end
|
62
|
+
|
63
|
+
opencv_libraries.each { |lib| raise "#{lib} not found." unless have_library(lib) }
|
64
|
+
opencv_libraries_opt.each { |lib| warn "#{lib} not found." unless have_library(lib) }
|
65
|
+
|
66
|
+
# Check the required headers
|
67
|
+
puts ">> Check the required headers..."
|
68
|
+
opencv_headers.each { |header| raise "#{header} not found." unless have_header(header) }
|
69
|
+
opencv_headers_opt.each { |header| warn "#{header} not found." unless have_header(header) }
|
70
|
+
have_header("stdarg.h")
|
71
|
+
|
72
|
+
if $warnflags
|
73
|
+
$warnflags.slice!('-Wdeclaration-after-statement')
|
74
|
+
$warnflags.slice!('-Wimplicit-function-declaration')
|
75
|
+
end
|
76
|
+
|
77
|
+
# Quick fix for 1.8.7
|
78
|
+
$CFLAGS << " -I#{File.dirname(__FILE__)}/ext/opencv"
|
79
|
+
|
80
|
+
# Create Makefile
|
81
|
+
create_makefile('opencv')
|
82
|
+
|
@@ -0,0 +1,181 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
facerecognizer.cpp -
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include <stdio.h>
|
11
|
+
#include "facerecognizer.h"
|
12
|
+
/*
|
13
|
+
* Document-class: OpenCV::FaceRecognizer
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_FACERECOGNIZER
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
std::map<void*, cv::Ptr<cv::FaceRecognizer> > ptr_guard_map;
|
22
|
+
|
23
|
+
void
|
24
|
+
guard_facerecognizer(void* data_ptr, cv::Ptr<cv::FaceRecognizer> ptr)
|
25
|
+
{
|
26
|
+
ptr_guard_map[data_ptr] = ptr;
|
27
|
+
}
|
28
|
+
|
29
|
+
void
|
30
|
+
release_facerecognizer(void *data_ptr)
|
31
|
+
{
|
32
|
+
ptr_guard_map[data_ptr].release();
|
33
|
+
ptr_guard_map.erase(data_ptr);
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE
|
37
|
+
allocate_facerecognizer(VALUE klass)
|
38
|
+
{
|
39
|
+
return Data_Wrap_Struct(klass, 0, release_facerecognizer, NULL);
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
rb_class()
|
45
|
+
{
|
46
|
+
return rb_klass;
|
47
|
+
}
|
48
|
+
|
49
|
+
/*
|
50
|
+
* call-seq:
|
51
|
+
* train(src, labels)
|
52
|
+
*
|
53
|
+
* Trains a FaceRecognizer with given data and associated labels.
|
54
|
+
*/
|
55
|
+
VALUE
|
56
|
+
rb_train(VALUE self, VALUE src, VALUE labels)
|
57
|
+
{
|
58
|
+
Check_Type(src, T_ARRAY);
|
59
|
+
Check_Type(labels, T_ARRAY);
|
60
|
+
|
61
|
+
VALUE *src_ptr = RARRAY_PTR(src);
|
62
|
+
int src_size = RARRAY_LEN(src);
|
63
|
+
std::vector<cv::Mat> images;
|
64
|
+
for (int i = 0; i < src_size; i++) {
|
65
|
+
images.push_back(cv::Mat(CVMAT_WITH_CHECK(src_ptr[i])));
|
66
|
+
}
|
67
|
+
|
68
|
+
VALUE *labels_ptr = RARRAY_PTR(labels);
|
69
|
+
int labels_size = RARRAY_LEN(labels);
|
70
|
+
std::vector<int> local_labels;
|
71
|
+
for (int i = 0; i < labels_size; i++) {
|
72
|
+
local_labels.push_back(NUM2INT(labels_ptr[i]));
|
73
|
+
}
|
74
|
+
|
75
|
+
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
76
|
+
try {
|
77
|
+
self_ptr->train(images, local_labels);
|
78
|
+
}
|
79
|
+
catch (cv::Exception& e) {
|
80
|
+
raise_cverror(e);
|
81
|
+
}
|
82
|
+
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* call-seq:
|
88
|
+
* predict(src)
|
89
|
+
*
|
90
|
+
* Predicts a label and associated confidence (e.g. distance) for a given input image.
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
rb_predict(VALUE self, VALUE src)
|
94
|
+
{
|
95
|
+
cv::Mat mat = cv::Mat(CVMAT_WITH_CHECK(src));
|
96
|
+
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
97
|
+
int label;
|
98
|
+
double confidence;
|
99
|
+
try {
|
100
|
+
self_ptr->predict(mat, label, confidence);
|
101
|
+
}
|
102
|
+
catch (cv::Exception& e) {
|
103
|
+
raise_cverror(e);
|
104
|
+
}
|
105
|
+
|
106
|
+
return rb_ary_new3(2, INT2NUM(label), DBL2NUM(confidence));
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
/*
|
111
|
+
* call-seq:
|
112
|
+
* save(filename)
|
113
|
+
*
|
114
|
+
* Saves this model to a given filename, either as XML or YAML.
|
115
|
+
*/
|
116
|
+
VALUE
|
117
|
+
rb_save(VALUE self, VALUE filename)
|
118
|
+
{
|
119
|
+
Check_Type(filename, T_STRING);
|
120
|
+
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
121
|
+
try {
|
122
|
+
char* s = StringValueCStr(filename);
|
123
|
+
self_ptr->save(std::string(s));
|
124
|
+
}
|
125
|
+
catch (cv::Exception& e) {
|
126
|
+
raise_cverror(e);
|
127
|
+
}
|
128
|
+
|
129
|
+
return Qnil;
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* load(filename)
|
135
|
+
*
|
136
|
+
* Loads a FaceRecognizer and its model state.
|
137
|
+
*/
|
138
|
+
VALUE
|
139
|
+
rb_load(VALUE self, VALUE filename)
|
140
|
+
{
|
141
|
+
Check_Type(filename, T_STRING);
|
142
|
+
cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
|
143
|
+
try {
|
144
|
+
char* s = StringValueCStr(filename);
|
145
|
+
self_ptr->load(std::string(s));
|
146
|
+
}
|
147
|
+
catch (cv::Exception& e) {
|
148
|
+
raise_cverror(e);
|
149
|
+
}
|
150
|
+
|
151
|
+
return Qnil;
|
152
|
+
}
|
153
|
+
|
154
|
+
void
|
155
|
+
init_ruby_class()
|
156
|
+
{
|
157
|
+
#if 0
|
158
|
+
// For documentation using YARD
|
159
|
+
VALUE opencv = rb_define_module("OpenCV");
|
160
|
+
VALUE alghorithm = rb_define_class_under(opencv, "Algorithm", rb_cObject);
|
161
|
+
#endif
|
162
|
+
|
163
|
+
if (rb_klass)
|
164
|
+
return;
|
165
|
+
/*
|
166
|
+
* opencv = rb_define_module("OpenCV");
|
167
|
+
*
|
168
|
+
* note: this comment is used by rdoc.
|
169
|
+
*/
|
170
|
+
VALUE opencv = rb_module_opencv();
|
171
|
+
VALUE alghorithm = cAlgorithm::rb_class();
|
172
|
+
rb_klass = rb_define_class_under(opencv, "FaceRecognizer", alghorithm);
|
173
|
+
rb_define_method(rb_klass, "train", RUBY_METHOD_FUNC(rb_train), 2);
|
174
|
+
rb_define_method(rb_klass, "predict", RUBY_METHOD_FUNC(rb_predict), 1);
|
175
|
+
rb_define_method(rb_klass, "save", RUBY_METHOD_FUNC(rb_save), 1);
|
176
|
+
rb_define_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
|
177
|
+
}
|
178
|
+
|
179
|
+
__NAMESPACE_END_FACERECOGNIZER
|
180
|
+
__NAMESPACE_END_OPENCV
|
181
|
+
|