ruby-opencv 0.0.10 → 0.0.11.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +6 -14
  2. data/Manifest.txt +32 -8
  3. data/README.md +1 -1
  4. data/examples/alpha_blend.rb +2 -2
  5. data/examples/contours/bounding-box-detect-canny.rb +0 -0
  6. data/examples/contours/contour_retrieval_modes.rb +0 -0
  7. data/examples/convexhull.rb +0 -0
  8. data/examples/face_detect.rb +0 -0
  9. data/examples/facerec/create_csv.rb +43 -0
  10. data/examples/facerec/facerec_eigenfaces.rb +132 -0
  11. data/examples/facerec/facerec_fisherfaces.rb +131 -0
  12. data/examples/facerec/facerec_lbph.rb +116 -0
  13. data/examples/facerec/readme.md +111 -0
  14. data/examples/find_obj.rb +2 -2
  15. data/examples/houghcircle.rb +1 -1
  16. data/examples/{box.png → images/box.png} +0 -0
  17. data/examples/{box_in_scene.png → images/box_in_scene.png} +0 -0
  18. data/examples/{inpaint.png → images/inpaint.png} +0 -0
  19. data/examples/images/lena-256x256.jpg +0 -0
  20. data/examples/images/lena-eyes.jpg +0 -0
  21. data/examples/{lenna-rotated.jpg → images/lenna-rotated.jpg} +0 -0
  22. data/examples/{lenna.jpg → images/lenna.jpg} +0 -0
  23. data/examples/{stuff.jpg → images/stuff.jpg} +0 -0
  24. data/examples/{tiffany.jpg → images/tiffany.jpg} +0 -0
  25. data/examples/inpaint.rb +1 -1
  26. data/examples/match_kdtree.rb +2 -2
  27. data/examples/match_template.rb +26 -0
  28. data/examples/{matching_to_many_images.rb → matching_to_many_images/matching_to_many_images.rb} +3 -3
  29. data/examples/matching_to_many_images/query.png +0 -0
  30. data/examples/matching_to_many_images/train/1.png +0 -0
  31. data/examples/matching_to_many_images/train/2.png +0 -0
  32. data/examples/matching_to_many_images/train/3.png +0 -0
  33. data/examples/matching_to_many_images/train/trainImages.txt +0 -0
  34. data/examples/paint.rb +0 -0
  35. data/examples/snake.rb +0 -0
  36. data/ext/opencv/algorithm.cpp +286 -0
  37. data/ext/opencv/algorithm.h +38 -0
  38. data/ext/opencv/cvmat.cpp +205 -76
  39. data/ext/opencv/cvmat.h +8 -1
  40. data/ext/opencv/eigenfaces.cpp +67 -0
  41. data/ext/opencv/eigenfaces.h +30 -0
  42. data/ext/opencv/extconf.rb +0 -0
  43. data/ext/opencv/facerecognizer.cpp +174 -0
  44. data/ext/opencv/facerecognizer.h +46 -0
  45. data/ext/opencv/fisherfaces.cpp +67 -0
  46. data/ext/opencv/fisherfaces.h +30 -0
  47. data/ext/opencv/lbph.cpp +70 -0
  48. data/ext/opencv/lbph.h +30 -0
  49. data/ext/opencv/opencv.cpp +51 -1
  50. data/ext/opencv/opencv.h +6 -0
  51. data/lib/opencv.rb +0 -0
  52. data/lib/opencv/version.rb +1 -1
  53. data/ruby-opencv.gemspec +8 -7
  54. data/test/eigenfaces_save.xml +7524 -0
  55. data/test/fisherfaces_save.xml +7530 -0
  56. data/test/helper.rb +0 -0
  57. data/test/lbph_save.xml +4304 -0
  58. data/test/runner.rb +0 -0
  59. data/test/test_curve.rb +0 -0
  60. data/test/test_cvavgcomp.rb +0 -0
  61. data/test/test_cvbox2d.rb +0 -0
  62. data/test/test_cvcapture.rb +0 -0
  63. data/test/test_cvchain.rb +0 -0
  64. data/test/test_cvcircle32f.rb +0 -0
  65. data/test/test_cvconnectedcomp.rb +0 -0
  66. data/test/test_cvcontour.rb +0 -0
  67. data/test/test_cvcontourtree.rb +0 -0
  68. data/test/test_cverror.rb +0 -0
  69. data/test/test_cvfeaturetree.rb +0 -0
  70. data/test/test_cvfont.rb +0 -0
  71. data/test/test_cvhaarclassifiercascade.rb +0 -0
  72. data/test/test_cvhistogram.rb +0 -0
  73. data/test/test_cvhumoments.rb +0 -0
  74. data/test/test_cvline.rb +0 -0
  75. data/test/test_cvmat.rb +72 -16
  76. data/test/test_cvmat_drawing.rb +0 -0
  77. data/test/test_cvmat_dxt.rb +0 -0
  78. data/test/test_cvmat_imageprocessing.rb +72 -2
  79. data/test/test_cvmat_matching.rb +1 -1
  80. data/test/test_cvmoments.rb +0 -0
  81. data/test/test_cvpoint.rb +0 -0
  82. data/test/test_cvpoint2d32f.rb +0 -0
  83. data/test/test_cvpoint3d32f.rb +0 -0
  84. data/test/test_cvrect.rb +0 -0
  85. data/test/test_cvscalar.rb +0 -0
  86. data/test/test_cvseq.rb +0 -0
  87. data/test/test_cvsize.rb +0 -0
  88. data/test/test_cvsize2d32f.rb +0 -0
  89. data/test/test_cvslice.rb +0 -0
  90. data/test/test_cvsurfparams.rb +0 -0
  91. data/test/test_cvsurfpoint.rb +0 -0
  92. data/test/test_cvtermcriteria.rb +0 -0
  93. data/test/test_cvtwopoints.rb +0 -0
  94. data/test/test_cvvideowriter.rb +0 -0
  95. data/test/test_eigenfaces.rb +93 -0
  96. data/test/test_fisherfaces.rb +93 -0
  97. data/test/test_iplconvkernel.rb +0 -0
  98. data/test/test_iplimage.rb +0 -4
  99. data/test/test_lbph.rb +152 -0
  100. data/test/test_mouseevent.rb +0 -0
  101. data/test/test_opencv.rb +33 -4
  102. data/test/test_pointset.rb +7 -5
  103. data/test/test_preliminary.rb +0 -0
  104. data/test/test_trackbar.rb +0 -0
  105. data/test/test_window.rb +0 -0
  106. metadata +84 -56
@@ -0,0 +1,67 @@
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
+ define_ruby_class()
51
+ {
52
+ if (rb_klass)
53
+ return;
54
+ /*
55
+ * opencv = rb_define_module("OpenCV");
56
+ *
57
+ * note: this comment is used by rdoc.
58
+ */
59
+ VALUE opencv = rb_module_opencv();
60
+ rb_klass = rb_define_class_under(opencv, "EigenFaces", cFaceRecognizer::rb_class());
61
+ rb_define_alloc_func(rb_klass, cFaceRecognizer::allocate_facerecognizer);
62
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
63
+ }
64
+
65
+ __NAMESPACE_END_EIGENFACES
66
+ __NAMESPACE_END_OPENCV
67
+
@@ -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 define_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
+
File without changes
@@ -0,0 +1,174 @@
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< long, 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[(long)data_ptr] = ptr;
27
+ }
28
+
29
+ void
30
+ release_facerecognizer(void *ptr)
31
+ {
32
+ long key = (long)ptr;
33
+ ptr_guard_map[key].release();
34
+ ptr_guard_map.erase(key);
35
+ }
36
+
37
+ VALUE
38
+ allocate_facerecognizer(VALUE klass)
39
+ {
40
+ return Data_Wrap_Struct(klass, 0, release_facerecognizer, NULL);
41
+ }
42
+
43
+
44
+ VALUE
45
+ rb_class()
46
+ {
47
+ return rb_klass;
48
+ }
49
+
50
+ /*
51
+ * call-seq:
52
+ * train(src, labels)
53
+ *
54
+ * Trains a FaceRecognizer with given data and associated labels.
55
+ */
56
+ VALUE
57
+ rb_train(VALUE self, VALUE src, VALUE labels)
58
+ {
59
+ Check_Type(src, T_ARRAY);
60
+ Check_Type(labels, T_ARRAY);
61
+
62
+ VALUE *src_ptr = RARRAY_PTR(src);
63
+ int src_size = RARRAY_LEN(src);
64
+ std::vector<cv::Mat> images;
65
+ for (int i = 0; i < src_size; i++) {
66
+ images.push_back(cv::Mat(CVMAT_WITH_CHECK(src_ptr[i])));
67
+ }
68
+
69
+ VALUE *labels_ptr = RARRAY_PTR(labels);
70
+ int labels_size = RARRAY_LEN(labels);
71
+ std::vector<int> local_labels;
72
+ for (int i = 0; i < labels_size; i++) {
73
+ local_labels.push_back(NUM2INT(labels_ptr[i]));
74
+ }
75
+
76
+ cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
77
+ try {
78
+ self_ptr->train(images, local_labels);
79
+ }
80
+ catch (cv::Exception& e) {
81
+ raise_cverror(e);
82
+ }
83
+
84
+ return Qnil;
85
+ }
86
+
87
+ /*
88
+ * call-seq:
89
+ * predict(src)
90
+ *
91
+ * Predicts a label and associated confidence (e.g. distance) for a given input image.
92
+ */
93
+ VALUE
94
+ rb_predict(VALUE self, VALUE src)
95
+ {
96
+ cv::Mat mat = cv::Mat(CVMAT_WITH_CHECK(src));
97
+ cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
98
+ int label;
99
+ double confidence;
100
+ try {
101
+ self_ptr->predict(mat, label, confidence);
102
+ }
103
+ catch (cv::Exception& e) {
104
+ raise_cverror(e);
105
+ }
106
+
107
+ return rb_ary_new3(2, INT2NUM(label), DBL2NUM(confidence));
108
+ }
109
+
110
+
111
+ /*
112
+ * call-seq:
113
+ * save(filename)
114
+ *
115
+ * Saves this model to a given filename, either as XML or YAML.
116
+ */
117
+ VALUE
118
+ rb_save(VALUE self, VALUE filename)
119
+ {
120
+ Check_Type(filename, T_STRING);
121
+ cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
122
+ try {
123
+ char* s = StringValueCStr(filename);
124
+ self_ptr->save(std::string(s));
125
+ }
126
+ catch (cv::Exception& e) {
127
+ raise_cverror(e);
128
+ }
129
+
130
+ return Qnil;
131
+ }
132
+
133
+ /*
134
+ * call-seq:
135
+ * load(filename)
136
+ *
137
+ * Loads a FaceRecognizer and its model state.
138
+ */
139
+ VALUE
140
+ rb_load(VALUE self, VALUE filename)
141
+ {
142
+ Check_Type(filename, T_STRING);
143
+ cv::FaceRecognizer *self_ptr = FACERECOGNIZER(self);
144
+ try {
145
+ char* s = StringValueCStr(filename);
146
+ self_ptr->load(std::string(s));
147
+ }
148
+ catch (cv::Exception& e) {
149
+ raise_cverror(e);
150
+ }
151
+
152
+ return Qnil;
153
+ }
154
+
155
+ void
156
+ define_ruby_class()
157
+ {
158
+ if (rb_klass)
159
+ return;
160
+ /*
161
+ * opencv = rb_define_module("OpenCV");
162
+ *
163
+ * note: this comment is used by rdoc.
164
+ */
165
+ VALUE opencv = rb_module_opencv();
166
+ rb_klass = rb_define_class_under(opencv, "FaceRecognizer", cAlgorithm::rb_class());
167
+ rb_define_method(rb_klass, "train", RUBY_METHOD_FUNC(rb_train), 2);
168
+ rb_define_method(rb_klass, "predict", RUBY_METHOD_FUNC(rb_predict), 1);
169
+ rb_define_method(rb_klass, "save", RUBY_METHOD_FUNC(rb_save), 1);
170
+ rb_define_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
171
+ }
172
+
173
+ __NAMESPACE_END_FACERECOGNIZER
174
+ __NAMESPACE_END_OPENCV
@@ -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 define_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 *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,67 @@
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
+ define_ruby_class()
51
+ {
52
+ if (rb_klass)
53
+ return;
54
+ /*
55
+ * opencv = rb_define_module("OpenCV");
56
+ *
57
+ * note: this comment is used by rdoc.
58
+ */
59
+ VALUE opencv = rb_module_opencv();
60
+ rb_klass = rb_define_class_under(opencv, "FisherFaces", cFaceRecognizer::rb_class());
61
+ rb_define_alloc_func(rb_klass, cFaceRecognizer::allocate_facerecognizer);
62
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
63
+ }
64
+
65
+ __NAMESPACE_END_FISHERFACES
66
+ __NAMESPACE_END_OPENCV
67
+
@@ -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 define_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
+
@@ -0,0 +1,70 @@
1
+ /************************************************************
2
+
3
+ lbph.cpp -
4
+
5
+ $Author: ser1zw $
6
+
7
+ Copyright (C) 2013 ser1zw
8
+
9
+ ************************************************************/
10
+ #include <stdio.h>
11
+ #include "lbph.h"
12
+ /*
13
+ * Document-class: OpenCV::LBPH
14
+ *
15
+ */
16
+ __NAMESPACE_BEGIN_OPENCV
17
+ __NAMESPACE_BEGIN_LBPH
18
+
19
+ VALUE rb_klass;
20
+
21
+ VALUE
22
+ rb_class()
23
+ {
24
+ return rb_klass;
25
+ }
26
+
27
+ /*
28
+ * call-seq:
29
+ * LBPH.new(radius=1, neighbors=8, grid_x=8, grid_y=8, threshold=DBL_MAX) -> cvmat
30
+ */
31
+ VALUE
32
+ rb_initialize(int argc, VALUE argv[], VALUE self)
33
+ {
34
+ VALUE radius_val, neighbors_val, grid_x_val, grid_y_val, threshold_val;
35
+ rb_scan_args(argc, argv, "05", &radius_val, &neighbors_val, &grid_x_val, &grid_y_val, &threshold_val);
36
+
37
+ int radius = NIL_P(radius_val) ? 1 : NUM2INT(radius_val);
38
+ int neighbors = NIL_P(neighbors_val) ? 8 : NUM2INT(neighbors_val);
39
+ int grid_x = NIL_P(grid_x_val) ? 8 : NUM2INT(grid_x_val);
40
+ int grid_y = NIL_P(grid_y_val) ? 8 : NUM2INT(grid_y_val);
41
+ double threshold = NIL_P(threshold_val) ? DBL_MAX : NUM2INT(threshold_val);
42
+
43
+ free(DATA_PTR(self));
44
+ cv::Ptr<cv::FaceRecognizer> ptr = cv::createLBPHFaceRecognizer(radius, neighbors, grid_x, grid_y, threshold);
45
+ DATA_PTR(self) = ptr;
46
+
47
+ cFaceRecognizer::guard_facerecognizer(DATA_PTR(self), ptr);
48
+
49
+ return self;
50
+ }
51
+
52
+ void
53
+ define_ruby_class()
54
+ {
55
+ if (rb_klass)
56
+ return;
57
+ /*
58
+ * opencv = rb_define_module("OpenCV");
59
+ *
60
+ * note: this comment is used by rdoc.
61
+ */
62
+ VALUE opencv = rb_module_opencv();
63
+ rb_klass = rb_define_class_under(opencv, "LBPH", cFaceRecognizer::rb_class());
64
+ rb_define_alloc_func(rb_klass, cFaceRecognizer::allocate_facerecognizer);
65
+ rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
66
+ }
67
+
68
+ __NAMESPACE_END_LBPH
69
+ __NAMESPACE_END_OPENCV
70
+