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,148 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvhaarclassifercascade.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2007 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvhaarclassifiercascade.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvHaarClassifierCascade
|
13
|
+
*
|
14
|
+
* Haar Feature-based Cascade Classifier for Object Detection
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_allocate(VALUE klass)
|
29
|
+
{
|
30
|
+
return OPENCV_OBJECT(klass, 0);
|
31
|
+
}
|
32
|
+
|
33
|
+
void
|
34
|
+
cvhaarclassifiercascade_free(void* ptr)
|
35
|
+
{
|
36
|
+
if (ptr) {
|
37
|
+
CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)ptr;
|
38
|
+
cvReleaseHaarClassifierCascade(&cascade);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Load trained cascade of haar classifers from file.
|
44
|
+
*
|
45
|
+
* @overload load(filename)
|
46
|
+
* @param filename [String] Haar classifer file name
|
47
|
+
* @return [CvHaarClassifierCascade] Object detector
|
48
|
+
* @scope class
|
49
|
+
* @opencv_func cvLoad
|
50
|
+
*/
|
51
|
+
VALUE
|
52
|
+
rb_load(VALUE klass, VALUE path)
|
53
|
+
{
|
54
|
+
CvHaarClassifierCascade *cascade = NULL;
|
55
|
+
try {
|
56
|
+
cascade = (CvHaarClassifierCascade*)cvLoad(StringValueCStr(path), 0, 0, 0);
|
57
|
+
}
|
58
|
+
catch (cv::Exception& e) {
|
59
|
+
raise_cverror(e);
|
60
|
+
}
|
61
|
+
if (!CV_IS_HAAR_CLASSIFIER(cascade))
|
62
|
+
rb_raise(rb_eArgError, "invalid format haar classifier cascade file.");
|
63
|
+
return Data_Wrap_Struct(klass, 0, cvhaarclassifiercascade_free, cascade);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Detects objects of different sizes in the input image.
|
68
|
+
*
|
69
|
+
* @overload detect_objects(image, options = nil)
|
70
|
+
* @param image [CvMat,IplImage] Matrix of the type CV_8U containing an image where objects are detected.
|
71
|
+
* @param options [Hash] Options
|
72
|
+
* @option options [Number] :scale_factor
|
73
|
+
* Parameter specifying how much the image size is reduced at each image scale.
|
74
|
+
* @option options [Number] :storage
|
75
|
+
* Memory storage to store the resultant sequence of the object candidate rectangles
|
76
|
+
* @option options [Number] :min_neighbors
|
77
|
+
* Parameter specifying how many neighbors each candidate rectangle should have to retain it.
|
78
|
+
* @option options [CvSize] :min_size
|
79
|
+
* Minimum possible object size. Objects smaller than that are ignored.
|
80
|
+
* @option options [CvSize] :max_size
|
81
|
+
* Maximum possible object size. Objects larger than that are ignored.
|
82
|
+
* @return [CvSeq<CvAvgComp>] Detected objects as a list of rectangles
|
83
|
+
* @opencv_func cvHaarDetectObjects
|
84
|
+
*/
|
85
|
+
VALUE
|
86
|
+
rb_detect_objects(int argc, VALUE *argv, VALUE self)
|
87
|
+
{
|
88
|
+
VALUE image, options;
|
89
|
+
rb_scan_args(argc, argv, "11", &image, &options);
|
90
|
+
|
91
|
+
double scale_factor;
|
92
|
+
int flags, min_neighbors;
|
93
|
+
CvSize min_size, max_size;
|
94
|
+
VALUE storage_val;
|
95
|
+
if (NIL_P(options)) {
|
96
|
+
scale_factor = 1.1;
|
97
|
+
flags = 0;
|
98
|
+
min_neighbors = 3;
|
99
|
+
min_size = max_size = cvSize(0, 0);
|
100
|
+
storage_val = cCvMemStorage::new_object();
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
scale_factor = IF_DBL(LOOKUP_HASH(options, "scale_factor"), 1.1);
|
104
|
+
flags = IF_INT(LOOKUP_HASH(options, "flags"), 0);
|
105
|
+
min_neighbors = IF_INT(LOOKUP_HASH(options, "min_neighbors"), 3);
|
106
|
+
VALUE min_size_val = LOOKUP_HASH(options, "min_size");
|
107
|
+
min_size = NIL_P(min_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(min_size_val);
|
108
|
+
VALUE max_size_val = LOOKUP_HASH(options, "max_size");
|
109
|
+
max_size = NIL_P(max_size_val) ? cvSize(0, 0) : VALUE_TO_CVSIZE(max_size_val);
|
110
|
+
storage_val = CHECK_CVMEMSTORAGE(LOOKUP_HASH(options, "storage"));
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE result = Qnil;
|
114
|
+
try {
|
115
|
+
CvSeq *seq = cvHaarDetectObjects(CVARR_WITH_CHECK(image), CVHAARCLASSIFIERCASCADE(self), CVMEMSTORAGE(storage_val),
|
116
|
+
scale_factor, min_neighbors, flags, min_size, max_size);
|
117
|
+
result = cCvSeq::new_sequence(cCvSeq::rb_class(), seq, cCvAvgComp::rb_class(), storage_val);
|
118
|
+
if (rb_block_given_p()) {
|
119
|
+
for(int i = 0; i < seq->total; ++i)
|
120
|
+
rb_yield(REFER_OBJECT(cCvAvgComp::rb_class(), cvGetSeqElem(seq, i), storage_val));
|
121
|
+
}
|
122
|
+
}
|
123
|
+
catch (cv::Exception& e) {
|
124
|
+
raise_cverror(e);
|
125
|
+
}
|
126
|
+
return result;
|
127
|
+
}
|
128
|
+
|
129
|
+
void
|
130
|
+
init_ruby_class()
|
131
|
+
{
|
132
|
+
#if 0
|
133
|
+
// For documentation using YARD
|
134
|
+
VALUE opencv = rb_define_module("OpenCV");
|
135
|
+
#endif
|
136
|
+
|
137
|
+
if (rb_klass)
|
138
|
+
return;
|
139
|
+
|
140
|
+
VALUE opencv = rb_module_opencv();
|
141
|
+
rb_klass = rb_define_class_under(opencv, "CvHaarClassifierCascade", rb_cObject);
|
142
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
143
|
+
rb_define_singleton_method(rb_klass, "load", RUBY_METHOD_FUNC(rb_load), 1);
|
144
|
+
rb_define_method(rb_klass, "detect_objects", RUBY_METHOD_FUNC(rb_detect_objects), -1);
|
145
|
+
}
|
146
|
+
|
147
|
+
__NAMESPACE_END_CVHAARCLASSIFERCASCADE
|
148
|
+
__NAMESPACE_END_OPENCV
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvhaarclassifiercascade.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
11
|
+
#define RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
12
|
+
|
13
|
+
#define __NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE namespace cCvHaarClassifierCascade {
|
14
|
+
#define __NAMESPACE_END_CVHAARCLASSIFERCASCADE }
|
15
|
+
|
16
|
+
#include "opencv.h"
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CVHAARCLASSIFERCASCADE
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void init_ruby_class();
|
24
|
+
|
25
|
+
VALUE rb_allocate(VALUE klass);
|
26
|
+
|
27
|
+
VALUE rb_load(VALUE klass, VALUE path);
|
28
|
+
VALUE rb_detect_objects(int argc, VALUE *argv, VALUE self);
|
29
|
+
|
30
|
+
__NAMESPACE_END_CVHAARCLASSIFERCASCADE
|
31
|
+
inline CvHaarClassifierCascade*
|
32
|
+
CVHAARCLASSIFIERCASCADE(VALUE object) {
|
33
|
+
CvHaarClassifierCascade *ptr;
|
34
|
+
Data_Get_Struct(object, CvHaarClassifierCascade, ptr);
|
35
|
+
return ptr;
|
36
|
+
}
|
37
|
+
__NAMESPACE_END_OPENCV
|
38
|
+
|
39
|
+
#endif // RUBY_OPENCV_CVHAARCLASSIFIERCASCADE_H
|
@@ -0,0 +1,715 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvhistogram.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2008 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvhistogram.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvHistogram
|
13
|
+
*
|
14
|
+
* Multi-dimensional histogram.
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CVHISTOGRAM
|
18
|
+
|
19
|
+
VALUE rb_klass;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_class()
|
23
|
+
{
|
24
|
+
return rb_klass;
|
25
|
+
}
|
26
|
+
|
27
|
+
void
|
28
|
+
release_hist(void* ptr)
|
29
|
+
{
|
30
|
+
if (ptr) {
|
31
|
+
try {
|
32
|
+
cvReleaseHist((CvHistogram**)&ptr);
|
33
|
+
}
|
34
|
+
catch (cv::Exception& e) {
|
35
|
+
raise_cverror(e);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE
|
41
|
+
rb_allocate(VALUE klass)
|
42
|
+
{
|
43
|
+
CvHistogram* ptr = NULL;
|
44
|
+
return Data_Wrap_Struct(klass, 0, release_hist, ptr);
|
45
|
+
}
|
46
|
+
|
47
|
+
float*
|
48
|
+
ary2fltptr(VALUE ary, float* buff)
|
49
|
+
{
|
50
|
+
Check_Type(ary, T_ARRAY);
|
51
|
+
int size = RARRAY_LEN(ary);
|
52
|
+
VALUE* ary_ptr = RARRAY_PTR(ary);
|
53
|
+
for (int i = 0; i < size; ++i) {
|
54
|
+
buff[i] = NUM2DBL(ary_ptr[i]);
|
55
|
+
}
|
56
|
+
return buff;
|
57
|
+
}
|
58
|
+
|
59
|
+
int*
|
60
|
+
ary2intptr(VALUE ary, int* buff)
|
61
|
+
{
|
62
|
+
Check_Type(ary, T_ARRAY);
|
63
|
+
int size = RARRAY_LEN(ary);
|
64
|
+
VALUE* ary_ptr = RARRAY_PTR(ary);
|
65
|
+
for (int i = 0; i < size; ++i) {
|
66
|
+
buff[i] = NUM2INT(ary_ptr[i]);
|
67
|
+
}
|
68
|
+
return buff;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* Creates a histogram
|
73
|
+
* @overload new(dims, sizes, type, ranges=nil, uniform=true)
|
74
|
+
* @param dims [Integer] Number of histogram dimensions
|
75
|
+
* @param sizes [Array<Integer>] Array of the histogram dimension sizes
|
76
|
+
* @param type [Integer]
|
77
|
+
* Histogram representation format. CV_HIST_ARRAY means that the histogram data is represented
|
78
|
+
* as a multi-dimensional dense array CvMatND. CV_HIST_SPARSE means that histogram data is
|
79
|
+
* represented as a multi-dimensional sparse array CvSparseMat.
|
80
|
+
* @param ranges [Array<Integer>]
|
81
|
+
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
82
|
+
* The ranges are used when the histogram is calculated or backprojected to determine which
|
83
|
+
* histogram bin corresponds to which value/tuple of values from the input image(s).
|
84
|
+
* @param uniform [Boolean] Uniformity flag.
|
85
|
+
* @return [CvHistogram] Histogram
|
86
|
+
* @opencv_func cvCreateHist
|
87
|
+
*/
|
88
|
+
VALUE
|
89
|
+
rb_initialize(int argc, VALUE *argv, VALUE self)
|
90
|
+
{
|
91
|
+
VALUE _dims, _sizes, _type, _ranges, _uniform;
|
92
|
+
int uniform;
|
93
|
+
int* sizes;
|
94
|
+
float** ranges = NULL;
|
95
|
+
|
96
|
+
rb_scan_args(argc, argv, "32", &_dims, &_sizes, &_type, &_ranges, &_uniform);
|
97
|
+
int sizes_len = RARRAY_LEN(_sizes);
|
98
|
+
sizes = ALLOCA_N(int, sizes_len);
|
99
|
+
|
100
|
+
if (NIL_P(_ranges)) {
|
101
|
+
sizes = ary2intptr(_sizes, sizes);
|
102
|
+
ranges = NULL;
|
103
|
+
}
|
104
|
+
else {
|
105
|
+
ranges = ALLOCA_N(float*, sizes_len);
|
106
|
+
VALUE* range_ptr = RARRAY_PTR(_ranges);
|
107
|
+
int i;
|
108
|
+
for (i = 0; i < sizes_len; i++) {
|
109
|
+
sizes[i] = NUM2INT(RARRAY_PTR(_sizes)[i]);
|
110
|
+
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
|
111
|
+
}
|
112
|
+
}
|
113
|
+
uniform = TRUE_OR_FALSE(_uniform, 1);
|
114
|
+
|
115
|
+
try {
|
116
|
+
DATA_PTR(self) = cvCreateHist(NUM2INT(_dims), sizes, NUM2INT(_type), ranges, uniform);
|
117
|
+
}
|
118
|
+
catch (cv::Exception& e) {
|
119
|
+
raise_cverror(e);
|
120
|
+
}
|
121
|
+
|
122
|
+
return self;
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* Returns <tt>self</tt> is uniform histogram or not
|
127
|
+
* @overload is_uniform?
|
128
|
+
* @return [Boolean] Uniform or not
|
129
|
+
* @opencv_func CV_IS_UNIFORM_HIST
|
130
|
+
*/
|
131
|
+
VALUE
|
132
|
+
rb_is_uniform(VALUE self)
|
133
|
+
{
|
134
|
+
return CV_IS_UNIFORM_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* Returns <tt>self</tt> is sparse histogram or not
|
139
|
+
* @overload is_sparse?
|
140
|
+
* @return [Boolean] Sparse or not
|
141
|
+
* @opencv_func CV_IS_SPARSE_HIST
|
142
|
+
*/
|
143
|
+
VALUE
|
144
|
+
rb_is_sparse(VALUE self)
|
145
|
+
{
|
146
|
+
return CV_IS_SPARSE_HIST(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
147
|
+
}
|
148
|
+
|
149
|
+
/*
|
150
|
+
* Returns <tt>self</tt> has range or not
|
151
|
+
* @overload has_range?
|
152
|
+
* @return [Boolean] Has range or not
|
153
|
+
* @opencv_func CV_HIST_HAS_RANGES
|
154
|
+
*/
|
155
|
+
VALUE
|
156
|
+
rb_has_range(VALUE self)
|
157
|
+
{
|
158
|
+
return CV_HIST_HAS_RANGES(CVHISTOGRAM(self)) ? Qtrue : Qfalse;
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* Calculates a histogram of a set of arrays.
|
163
|
+
* @overload calc_hist(images, accumulate=nil, mask=nil)
|
164
|
+
* @param images [Array<IplImage>]
|
165
|
+
* Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
|
166
|
+
* Each of them can have an arbitrary number of channels.
|
167
|
+
* @param accumulate [Boolean]
|
168
|
+
* Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated.
|
169
|
+
* This feature enables you to compute a single histogram from several sets of arrays,
|
170
|
+
* or to update the histogram in time.
|
171
|
+
* @param mask [CvMat]
|
172
|
+
* Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i].
|
173
|
+
* The non-zero mask elements mark the array elements counted in the histogram.
|
174
|
+
* @return [CvHistogram] Histogram of a set of arrays
|
175
|
+
* @opencv_func cvCalcHist
|
176
|
+
*/
|
177
|
+
VALUE
|
178
|
+
rb_calc_hist(int argc, VALUE* argv, VALUE self)
|
179
|
+
{
|
180
|
+
return rb_calc_hist_bang(argc, argv, rb_copy_hist(self));
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Calculates a histogram of a set of arrays.
|
185
|
+
* @overload calc_hist!(images, accumulate=nil, mask=nil)
|
186
|
+
* @see #calc_hist
|
187
|
+
* @opencv_func cvCalcHist
|
188
|
+
*/
|
189
|
+
VALUE
|
190
|
+
rb_calc_hist_bang(int argc, VALUE* argv, VALUE self)
|
191
|
+
{
|
192
|
+
VALUE images, accumulate, mask;
|
193
|
+
rb_scan_args(argc, argv, "12", &images, &accumulate, &mask);
|
194
|
+
Check_Type(images, T_ARRAY);
|
195
|
+
int num_images = RARRAY_LEN(images);
|
196
|
+
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
197
|
+
VALUE* images_ptr = RARRAY_PTR(images);
|
198
|
+
for (int i = 0; i < num_images; i++) {
|
199
|
+
img[i] = IPLIMAGE_WITH_CHECK(images_ptr[i]);
|
200
|
+
}
|
201
|
+
CvMat* m = NIL_P(mask) ? NULL : CVMAT_WITH_CHECK(mask);
|
202
|
+
try {
|
203
|
+
cvCalcHist(img, CVHISTOGRAM(self), TRUE_OR_FALSE(accumulate, 0), m);
|
204
|
+
}
|
205
|
+
catch (cv::Exception& e) {
|
206
|
+
raise_cverror(e);
|
207
|
+
}
|
208
|
+
|
209
|
+
return self;
|
210
|
+
}
|
211
|
+
|
212
|
+
/*
|
213
|
+
* Queries the value of the histogram bin.
|
214
|
+
* @overload [](idx0)
|
215
|
+
* @overload [](idx0, idx1)
|
216
|
+
* @overload [](idx0, idx1, idx2)
|
217
|
+
* @overload [](idx0, idx1, idx2, idx3, ...)
|
218
|
+
* @param idx* [Integer] *-th index
|
219
|
+
* @return [Number] The value of the specified bin of the 1D, 2D, 3D, or N-D histogram.
|
220
|
+
* @opencv_func cvQueryHistValue_1D
|
221
|
+
* @opencv_func cvQueryHistValue_2D
|
222
|
+
* @opencv_func cvQueryHistValue_3D
|
223
|
+
* @opencv_func cvQueryHistValue_nD
|
224
|
+
*/
|
225
|
+
VALUE
|
226
|
+
rb_aref(VALUE self, VALUE args)
|
227
|
+
{
|
228
|
+
int num_idx = RARRAY_LEN(args);
|
229
|
+
int* idx = ALLOCA_N(int, num_idx);
|
230
|
+
VALUE* args_ptr = RARRAY_PTR(args);
|
231
|
+
for (int i = 0; i < num_idx; i++) {
|
232
|
+
idx[i] = NUM2INT(args_ptr[i]);
|
233
|
+
}
|
234
|
+
|
235
|
+
float value = 0.0;
|
236
|
+
CvHistogram* self_ptr = CVHISTOGRAM(self);
|
237
|
+
try {
|
238
|
+
switch (num_idx) {
|
239
|
+
case 1:
|
240
|
+
value = cvQueryHistValue_1D(self_ptr, idx[0]);
|
241
|
+
break;
|
242
|
+
case 2:
|
243
|
+
value = cvQueryHistValue_2D(self_ptr, idx[0], idx[1]);
|
244
|
+
break;
|
245
|
+
case 3:
|
246
|
+
value = cvQueryHistValue_3D(self_ptr, idx[0], idx[1], idx[2]);
|
247
|
+
break;
|
248
|
+
default:
|
249
|
+
value = cvQueryHistValue_nD(self_ptr, idx);
|
250
|
+
break;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
catch (cv::Exception& e) {
|
254
|
+
raise_cverror(e);
|
255
|
+
}
|
256
|
+
|
257
|
+
return rb_float_new((double)value);
|
258
|
+
}
|
259
|
+
|
260
|
+
/*
|
261
|
+
* Finds the minimum and maximum histogram bins.
|
262
|
+
* @overload min_max_value
|
263
|
+
* @return [Array]
|
264
|
+
* [min_value, max_value, min_idx, max_idx]: Array of the minimum / maximum value of the histogram
|
265
|
+
* and their coordinates.
|
266
|
+
* - min_value: The minimum value of the histogram.
|
267
|
+
* - max_value: The maximum value of the histogram.
|
268
|
+
* - min_idx: The array of coordinates for the minimum.
|
269
|
+
* - max_idx: The array of coordinates for the maximum.
|
270
|
+
* @opencv_func cvGetMinMaxHistValue
|
271
|
+
*/
|
272
|
+
VALUE
|
273
|
+
rb_min_max_value(VALUE self)
|
274
|
+
{
|
275
|
+
CvHistogram* self_ptr = CVHISTOGRAM(self);
|
276
|
+
int dims = 0;
|
277
|
+
float min_value = 0.0, max_value = 0.0;
|
278
|
+
int *min_idx = NULL;
|
279
|
+
int *max_idx = NULL;
|
280
|
+
try {
|
281
|
+
dims = cvGetDims(self_ptr->bins, NULL);
|
282
|
+
min_idx = ALLOCA_N(int, dims);
|
283
|
+
max_idx = ALLOCA_N(int, dims);
|
284
|
+
cvGetMinMaxHistValue(CVHISTOGRAM(self), &min_value, &max_value, min_idx, max_idx);
|
285
|
+
}
|
286
|
+
catch (cv::Exception& e) {
|
287
|
+
raise_cverror(e);
|
288
|
+
}
|
289
|
+
|
290
|
+
VALUE _min_idx = rb_ary_new2(dims);
|
291
|
+
VALUE _max_idx = rb_ary_new2(dims);
|
292
|
+
for (int i = 0; i < dims; i++) {
|
293
|
+
rb_ary_store(_min_idx, i, INT2NUM(min_idx[i]));
|
294
|
+
rb_ary_store(_max_idx, i, INT2NUM(max_idx[i]));
|
295
|
+
}
|
296
|
+
|
297
|
+
return rb_ary_new3(4, rb_float_new((double)min_value), rb_float_new((double)max_value),
|
298
|
+
_min_idx, _max_idx);
|
299
|
+
}
|
300
|
+
|
301
|
+
/*
|
302
|
+
* Returns number of array dimensions
|
303
|
+
* @overload [](idx0, idx1, ...)
|
304
|
+
* @param idx* [Integer] *-th index
|
305
|
+
* @return [Array<Integer, Array<Integer>>]
|
306
|
+
* [dims, sizes]: Number of array dimensions and its sizes.
|
307
|
+
* - dims (Integer): Number of array dimensions
|
308
|
+
* - sizes (Array<Integer>): Vector of the array dimension sizes.
|
309
|
+
* For 2D arrays the number of rows (height) goes first,
|
310
|
+
* number of columns (width) next.
|
311
|
+
* @opencv_func cvGetDims
|
312
|
+
*/
|
313
|
+
VALUE
|
314
|
+
rb_dims(VALUE self)
|
315
|
+
{
|
316
|
+
VALUE _sizes = Qnil;
|
317
|
+
int size[CV_MAX_DIM];
|
318
|
+
int dims = 0;
|
319
|
+
try {
|
320
|
+
dims = cvGetDims(CVHISTOGRAM(self)->bins, size);
|
321
|
+
_sizes = rb_ary_new2(dims);
|
322
|
+
for (int i = 0; i < dims; ++i) {
|
323
|
+
rb_ary_store(_sizes, i, INT2NUM(size[i]));
|
324
|
+
}
|
325
|
+
}
|
326
|
+
catch (cv::Exception& e) {
|
327
|
+
raise_cverror(e);
|
328
|
+
}
|
329
|
+
return rb_assoc_new(INT2NUM(dims), _sizes);
|
330
|
+
}
|
331
|
+
|
332
|
+
/*
|
333
|
+
* Clones histogram
|
334
|
+
* @overload copy_hist
|
335
|
+
* @return [CvHistogram] Copy of the histogram
|
336
|
+
* @opencv_func cvCopyHist
|
337
|
+
*/
|
338
|
+
VALUE
|
339
|
+
rb_copy_hist(VALUE self)
|
340
|
+
{
|
341
|
+
CvHistogram* hist = NULL;
|
342
|
+
try {
|
343
|
+
cvCopyHist(CVHISTOGRAM(self), &hist);
|
344
|
+
}
|
345
|
+
catch (cv::Exception& e) {
|
346
|
+
raise_cverror(e);
|
347
|
+
}
|
348
|
+
return Data_Wrap_Struct(rb_klass, 0, release_hist, hist);
|
349
|
+
}
|
350
|
+
|
351
|
+
/*
|
352
|
+
* Sets all histogram bins to 0 in case of dense histogram
|
353
|
+
* and removes all histogram bins in case of sparse array.
|
354
|
+
* @overload clear_hist
|
355
|
+
* @return [CvHistogram] Cleared histogram
|
356
|
+
* @opencv_func cvClearHist
|
357
|
+
*/
|
358
|
+
VALUE
|
359
|
+
rb_clear_hist(VALUE self)
|
360
|
+
{
|
361
|
+
return rb_clear_hist_bang(rb_copy_hist(self));
|
362
|
+
}
|
363
|
+
|
364
|
+
/*
|
365
|
+
* Sets all histogram bins to 0 in case of dense histogram
|
366
|
+
* and removes all histogram bins in case of sparse array.
|
367
|
+
* This method changes <tt>self</tt>.
|
368
|
+
* @overload clear_hist!
|
369
|
+
* @see #clear_hist
|
370
|
+
* @return [CvHistogram] Cleared histogram
|
371
|
+
* @opencv_func cvClearHist
|
372
|
+
*/
|
373
|
+
VALUE
|
374
|
+
rb_clear_hist_bang(VALUE self)
|
375
|
+
{
|
376
|
+
try {
|
377
|
+
cvClearHist(CVHISTOGRAM(self));
|
378
|
+
}
|
379
|
+
catch (cv::Exception& e) {
|
380
|
+
raise_cverror(e);
|
381
|
+
}
|
382
|
+
return self;
|
383
|
+
}
|
384
|
+
|
385
|
+
/*
|
386
|
+
* Returns normalized the histogram bins by scaling them,
|
387
|
+
* such that the sum of the bins becomes equal to <tt>factor</tt>.
|
388
|
+
* @overload normalize(factor)
|
389
|
+
* @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
|
390
|
+
* @return [CvHistogram] Normalized histogram
|
391
|
+
* @opencv_func cvNormalizeHist
|
392
|
+
*/
|
393
|
+
VALUE
|
394
|
+
rb_normalize_hist(VALUE self, VALUE factor)
|
395
|
+
{
|
396
|
+
return rb_normalize_hist_bang(rb_copy_hist(self), factor);
|
397
|
+
}
|
398
|
+
|
399
|
+
/*
|
400
|
+
* Returns normalized the histogram bins by scaling them,
|
401
|
+
* such that the sum of the bins becomes equal to <tt>factor</tt>.
|
402
|
+
* This method changes <tt>self</tt>.
|
403
|
+
* @overload normalize!(factor)
|
404
|
+
* @param factor [Number] Normalization factor. The sum of the bins becomes equal to this value.
|
405
|
+
* @return [CvHistogram] Normalized histogram
|
406
|
+
* @see #normalize
|
407
|
+
* @opencv_func cvNormalizeHist
|
408
|
+
*/
|
409
|
+
VALUE
|
410
|
+
rb_normalize_hist_bang(VALUE self, VALUE factor)
|
411
|
+
{
|
412
|
+
try {
|
413
|
+
cvNormalizeHist(CVHISTOGRAM(self), NUM2DBL(factor));
|
414
|
+
}
|
415
|
+
catch (cv::Exception& e) {
|
416
|
+
raise_cverror(e);
|
417
|
+
}
|
418
|
+
return self;
|
419
|
+
}
|
420
|
+
|
421
|
+
/*
|
422
|
+
* Returns cleared histogram bins that are below the specified threshold.
|
423
|
+
* @overload thresh_hist(threshold)
|
424
|
+
* @param threshold [Number] Threshold value
|
425
|
+
* @return [CvHistogram] Cleared histogram
|
426
|
+
* @opencv_func cvThreshHist
|
427
|
+
*/
|
428
|
+
VALUE
|
429
|
+
rb_thresh_hist(VALUE self, VALUE threshold)
|
430
|
+
{
|
431
|
+
return rb_thresh_hist_bang(rb_copy_hist(self), threshold);
|
432
|
+
}
|
433
|
+
|
434
|
+
/*
|
435
|
+
* Cleares histogram bins that are below the specified threshold.
|
436
|
+
* This method changes <tt>self</tt>.
|
437
|
+
* @overload thresh_hist!(threshold)
|
438
|
+
* @param threshold [Number] Threshold value
|
439
|
+
* @return [CvHistogram] Cleared histogram
|
440
|
+
* @see #thresh_hist
|
441
|
+
* @opencv_func cvThreshHist
|
442
|
+
*/
|
443
|
+
VALUE
|
444
|
+
rb_thresh_hist_bang(VALUE self, VALUE threshold)
|
445
|
+
{
|
446
|
+
try {
|
447
|
+
cvThreshHist(CVHISTOGRAM(self), NUM2DBL(threshold));
|
448
|
+
}
|
449
|
+
catch (cv::Exception& e) {
|
450
|
+
raise_cverror(e);
|
451
|
+
}
|
452
|
+
return self;
|
453
|
+
}
|
454
|
+
|
455
|
+
/*
|
456
|
+
* Sets the bounds of the histogram bins.
|
457
|
+
* @overload set_hist_bin_ranges(ranges, uniform=true)
|
458
|
+
* @param ranges [Array<Number>]
|
459
|
+
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
460
|
+
* The ranges are used when the histogram is calculated or backprojected to determine
|
461
|
+
* which histogram bin corresponds to which value/tuple of values from the input image(s).
|
462
|
+
* @param uniform [Boolean]
|
463
|
+
* Uniformity flag.
|
464
|
+
* @return [CvHistogram]
|
465
|
+
* Histogram
|
466
|
+
* @opencv_func cvSetHistBinRanges
|
467
|
+
*/
|
468
|
+
VALUE
|
469
|
+
rb_set_hist_bin_ranges(int argc, VALUE* argv, VALUE self)
|
470
|
+
{
|
471
|
+
return rb_set_hist_bin_ranges_bang(argc, argv, rb_copy_hist(self));
|
472
|
+
}
|
473
|
+
|
474
|
+
/*
|
475
|
+
* Sets the bounds of the histogram bins. This method changes <tt>self</tt>.
|
476
|
+
* @overload set_hist_bin_ranges!(ranges, uniform=true)
|
477
|
+
* @param ranges [Array<Number>]
|
478
|
+
* Array of ranges for the histogram bins. Its meaning depends on the uniform parameter value.
|
479
|
+
* The ranges are used when the histogram is calculated or backprojected to determine
|
480
|
+
* which histogram bin corresponds to which value/tuple of values from the input image(s).
|
481
|
+
* @param uniform [Boolean]
|
482
|
+
* Uniformity flag.
|
483
|
+
* @return [CvHistogram]
|
484
|
+
* Histogram
|
485
|
+
* @see #set_hist_bin_ranges
|
486
|
+
* @opencv_func cvSetHistBinRanges
|
487
|
+
*/
|
488
|
+
VALUE
|
489
|
+
rb_set_hist_bin_ranges_bang(int argc, VALUE* argv, VALUE self)
|
490
|
+
{
|
491
|
+
VALUE _ranges, _uniform;
|
492
|
+
rb_scan_args(argc, argv, "11", &_ranges, &_uniform);
|
493
|
+
Check_Type(_ranges, T_ARRAY);
|
494
|
+
|
495
|
+
int ranges_size = RARRAY_LEN(_ranges);
|
496
|
+
float** ranges = ALLOCA_N(float*, ranges_size);
|
497
|
+
VALUE* range_ptr = RARRAY_PTR(_ranges);
|
498
|
+
for (int i = 0; i < ranges_size; ++i) {
|
499
|
+
ranges[i] = ary2fltptr(range_ptr[i], ALLOCA_N(float, 2));
|
500
|
+
}
|
501
|
+
int uniform = TRUE_OR_FALSE(_uniform, 1);
|
502
|
+
|
503
|
+
try {
|
504
|
+
cvSetHistBinRanges(CVHISTOGRAM(self), ranges, uniform);
|
505
|
+
}
|
506
|
+
catch (cv::Exception& e) {
|
507
|
+
raise_cverror(e);
|
508
|
+
}
|
509
|
+
|
510
|
+
return self;
|
511
|
+
}
|
512
|
+
|
513
|
+
/*
|
514
|
+
* Calculates the back projection of a histogram.
|
515
|
+
* @overload calc_back_project(images)
|
516
|
+
* @param images [Array<IplImage>]
|
517
|
+
* Source arrays. They all should have the same depth, CV_8U or CV_32F, and the same size.
|
518
|
+
* Each of them can have an arbitrary number of channels.
|
519
|
+
* @return [CvMat,IplImage]
|
520
|
+
* Destination back projection array that is a single-channel array of the same size and depth
|
521
|
+
* as the first element of <tt>images</tt>
|
522
|
+
* @opencv_func cvCalcBackProject
|
523
|
+
*/
|
524
|
+
VALUE
|
525
|
+
rb_calc_back_project(VALUE self, VALUE image)
|
526
|
+
{
|
527
|
+
Check_Type(image, T_ARRAY);
|
528
|
+
int num_images = RARRAY_LEN(image);
|
529
|
+
if (num_images == 0) {
|
530
|
+
return Qnil;
|
531
|
+
}
|
532
|
+
|
533
|
+
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
534
|
+
VALUE* image_ptr = RARRAY_PTR(image);
|
535
|
+
for (int i = 0; i < num_images; ++i) {
|
536
|
+
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
|
537
|
+
}
|
538
|
+
|
539
|
+
CvSize size;
|
540
|
+
size.width = img[0]->width;
|
541
|
+
size.height = img[0]->height;
|
542
|
+
VALUE back_project = cCvMat::new_mat_kind_object(size, image_ptr[0]);
|
543
|
+
try {
|
544
|
+
cvCalcBackProject(img, CVARR(back_project), CVHISTOGRAM(self));
|
545
|
+
}
|
546
|
+
catch (cv::Exception& e) {
|
547
|
+
raise_cverror(e);
|
548
|
+
}
|
549
|
+
|
550
|
+
return back_project;
|
551
|
+
}
|
552
|
+
|
553
|
+
/*
|
554
|
+
* Locates a template within an image by using a histogram comparison.
|
555
|
+
* @overload calc_back_project_patch(images, patch_size, method, factor)
|
556
|
+
* @param images [Array<IplImage>] Source arrays.
|
557
|
+
* @param pach_size [CvSize] Size of the patch slid though the source image.
|
558
|
+
* @param method [Integer]
|
559
|
+
* Comparison method that could be one of the following:
|
560
|
+
* - <tt>CV_COMP_CORREL</tt>: Correlation
|
561
|
+
* - <tt>CV_COMP_CHISQR</tt>: Chi-Square
|
562
|
+
* - <tt>CV_COMP_INTERSECT</tt>: Intersection
|
563
|
+
* - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
|
564
|
+
* - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
|
565
|
+
* @param factor [Number]
|
566
|
+
* Normalization factor for histograms that affects the normalization scale
|
567
|
+
* of the destination image. Pass 1 if not sure.
|
568
|
+
* @return [CvMat,IplImage] Destination image.
|
569
|
+
* @opencv_func cvCalcBackProject
|
570
|
+
*/
|
571
|
+
VALUE
|
572
|
+
rb_calc_back_project_patch(VALUE self, VALUE image, VALUE patch_size, VALUE method, VALUE factor)
|
573
|
+
{
|
574
|
+
Check_Type(image, T_ARRAY);
|
575
|
+
int num_images = RARRAY_LEN(image);
|
576
|
+
if (num_images == 0) {
|
577
|
+
return Qnil;
|
578
|
+
}
|
579
|
+
|
580
|
+
IplImage** img = ALLOCA_N(IplImage*, num_images);
|
581
|
+
VALUE* image_ptr = RARRAY_PTR(image);
|
582
|
+
for (int i = 0; i < num_images; ++i) {
|
583
|
+
img[i] = IPLIMAGE_WITH_CHECK(image_ptr[i]);
|
584
|
+
}
|
585
|
+
|
586
|
+
CvSize patchsize = VALUE_TO_CVSIZE(patch_size);
|
587
|
+
CvSize dst_size;
|
588
|
+
dst_size.width = img[0]->width - patchsize.width + 1;
|
589
|
+
dst_size.height = img[0]->height - patchsize.height + 1;
|
590
|
+
|
591
|
+
VALUE dst = cCvMat::new_mat_kind_object(dst_size, image_ptr[0], CV_32F, 1);
|
592
|
+
try {
|
593
|
+
cvCalcBackProjectPatch(img, CVARR(dst), patchsize, CVHISTOGRAM(self),
|
594
|
+
NUM2INT(method), NUM2DBL(factor));
|
595
|
+
}
|
596
|
+
catch (cv::Exception& e) {
|
597
|
+
raise_cverror(e);
|
598
|
+
}
|
599
|
+
|
600
|
+
return dst;
|
601
|
+
}
|
602
|
+
|
603
|
+
/*
|
604
|
+
* Compares two histograms.
|
605
|
+
* @overload compare_hist(hist1, hist2, method)
|
606
|
+
* @param hist1 [CvHistogram] First compared histogram.
|
607
|
+
* @param hist2 [CvHistogram] Second compared histogram of the same size as <tt>hist1</tt>.
|
608
|
+
* @param method [Integer]
|
609
|
+
* Comparison method that could be one of the following:
|
610
|
+
* - <tt>CV_COMP_CORREL</tt>: Correlation
|
611
|
+
* - <tt>CV_COMP_CHISQR</tt>: Chi-Square
|
612
|
+
* - <tt>CV_COMP_INTERSECT</tt>: Intersection
|
613
|
+
* - <tt>CV_COMP_BHATTACHARYYA</tt>: Bhattacharyya distance
|
614
|
+
* - <tt>CV_COMP_HELLINGER</tt>: Synonym for <tt>CV_COMP_BHATTACHARYYA</tt>
|
615
|
+
* @return [Number] Distance of the two histograms.
|
616
|
+
* @scope class
|
617
|
+
* @opencv_func cvCompareHist
|
618
|
+
*/
|
619
|
+
VALUE
|
620
|
+
rb_compare_hist(VALUE self, VALUE hist1, VALUE hist2, VALUE method)
|
621
|
+
{
|
622
|
+
double result = 0;
|
623
|
+
try {
|
624
|
+
result = cvCompareHist(CVHISTOGRAM_WITH_CHECK(hist1), CVHISTOGRAM_WITH_CHECK(hist2),
|
625
|
+
NUM2INT(method));
|
626
|
+
}
|
627
|
+
catch (cv::Exception& e) {
|
628
|
+
raise_cverror(e);
|
629
|
+
}
|
630
|
+
|
631
|
+
return rb_float_new(result);
|
632
|
+
}
|
633
|
+
|
634
|
+
/*
|
635
|
+
* Divides one histogram by another.
|
636
|
+
* @overload calc_prob_density(hist1, hist2, scale=255)
|
637
|
+
* @param hist1 [CvHistogram] First histogram (the divisor).
|
638
|
+
* @param hist2 [CvHistogram] Second histogram.
|
639
|
+
* @param scale [Number] Scale factor for the destination histogram.
|
640
|
+
* @return [CvHistogram] Destination histogram.
|
641
|
+
* @opencv_func cvCalcProbDensity
|
642
|
+
*/
|
643
|
+
VALUE
|
644
|
+
rb_calc_prob_density(int argc, VALUE* argv, VALUE self)
|
645
|
+
{
|
646
|
+
VALUE hist1, hist2, scale;
|
647
|
+
rb_scan_args(argc, argv, "21", &hist1, &hist2, &scale);
|
648
|
+
double s = NIL_P(scale) ? 255 : NUM2DBL(scale);
|
649
|
+
|
650
|
+
CvHistogram* hist1_ptr = CVHISTOGRAM_WITH_CHECK(hist1);
|
651
|
+
VALUE dst_hist = rb_allocate(rb_klass);
|
652
|
+
try {
|
653
|
+
cvCopyHist(hist1_ptr, (CvHistogram**)&(DATA_PTR(dst_hist)));
|
654
|
+
cvCalcProbDensity(hist1_ptr, CVHISTOGRAM_WITH_CHECK(hist2), CVHISTOGRAM(dst_hist), s);
|
655
|
+
}
|
656
|
+
catch (cv::Exception& e) {
|
657
|
+
raise_cverror(e);
|
658
|
+
}
|
659
|
+
|
660
|
+
return dst_hist;
|
661
|
+
}
|
662
|
+
|
663
|
+
void
|
664
|
+
init_ruby_class()
|
665
|
+
{
|
666
|
+
#if 0
|
667
|
+
// For documentation using YARD
|
668
|
+
VALUE opencv = rb_define_module("OpenCV");
|
669
|
+
#endif
|
670
|
+
|
671
|
+
if (rb_klass)
|
672
|
+
return;
|
673
|
+
|
674
|
+
VALUE opencv = rb_module_opencv();
|
675
|
+
rb_klass = rb_define_class_under(opencv, "CvHistogram", rb_cObject);
|
676
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
677
|
+
rb_define_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
678
|
+
rb_define_method(rb_klass, "is_uniform?", RUBY_METHOD_FUNC(rb_is_uniform), 0);
|
679
|
+
rb_define_method(rb_klass, "is_sparse?", RUBY_METHOD_FUNC(rb_is_sparse), 0);
|
680
|
+
rb_define_method(rb_klass, "has_range?", RUBY_METHOD_FUNC(rb_has_range), 0);
|
681
|
+
rb_define_method(rb_klass, "dims", RUBY_METHOD_FUNC(rb_dims), 0);
|
682
|
+
rb_define_method(rb_klass, "calc_hist", RUBY_METHOD_FUNC(rb_calc_hist), -1);
|
683
|
+
rb_define_method(rb_klass, "calc_hist!", RUBY_METHOD_FUNC(rb_calc_hist_bang), -1);
|
684
|
+
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), -2);
|
685
|
+
rb_define_alias(rb_klass, "query_hist_value", "[]");
|
686
|
+
rb_define_method(rb_klass, "min_max_value", RUBY_METHOD_FUNC(rb_min_max_value), 0);
|
687
|
+
rb_define_method(rb_klass, "copy_hist", RUBY_METHOD_FUNC(rb_copy_hist), 0);
|
688
|
+
|
689
|
+
rb_define_method(rb_klass, "clear_hist", RUBY_METHOD_FUNC(rb_clear_hist), 0);
|
690
|
+
rb_define_alias(rb_klass, "clear", "clear_hist");
|
691
|
+
rb_define_method(rb_klass, "clear_hist!", RUBY_METHOD_FUNC(rb_clear_hist_bang), 0);
|
692
|
+
rb_define_alias(rb_klass, "clear!", "clear_hist!");
|
693
|
+
|
694
|
+
rb_define_method(rb_klass, "normalize_hist", RUBY_METHOD_FUNC(rb_normalize_hist), 1);
|
695
|
+
rb_define_alias(rb_klass, "normalize", "normalize_hist");
|
696
|
+
rb_define_method(rb_klass, "normalize_hist!", RUBY_METHOD_FUNC(rb_normalize_hist_bang), 1);
|
697
|
+
rb_define_alias(rb_klass, "normalize!", "normalize_hist!");
|
698
|
+
|
699
|
+
rb_define_method(rb_klass, "thresh_hist", RUBY_METHOD_FUNC(rb_thresh_hist), 1);
|
700
|
+
rb_define_alias(rb_klass, "thresh", "thresh_hist");
|
701
|
+
rb_define_method(rb_klass, "thresh_hist!", RUBY_METHOD_FUNC(rb_thresh_hist_bang), 1);
|
702
|
+
rb_define_alias(rb_klass, "thresh!", "thresh_hist!");
|
703
|
+
|
704
|
+
rb_define_method(rb_klass, "set_hist_bin_ranges", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges), -1);
|
705
|
+
rb_define_method(rb_klass, "set_hist_bin_ranges!", RUBY_METHOD_FUNC(rb_set_hist_bin_ranges_bang), -1);
|
706
|
+
|
707
|
+
rb_define_method(rb_klass, "calc_back_project", RUBY_METHOD_FUNC(rb_calc_back_project), 1);
|
708
|
+
rb_define_method(rb_klass, "calc_back_project_patch", RUBY_METHOD_FUNC(rb_calc_back_project_patch), 4);
|
709
|
+
|
710
|
+
rb_define_singleton_method(rb_klass, "calc_prob_density", RUBY_METHOD_FUNC(rb_calc_prob_density), -1);
|
711
|
+
rb_define_singleton_method(rb_klass, "compare_hist", RUBY_METHOD_FUNC(rb_compare_hist), 3);
|
712
|
+
}
|
713
|
+
|
714
|
+
__NAMESPACE_END_CVHISTOGRAM
|
715
|
+
__NAMESPACE_END_OPENCV
|