Commit 6ad751d2ca57ade28d675f361dedc782dea259b2

Authored by Josh Klontz
1 parent 46e22263

remove recursiveintegralsampler

openbr/plugins/imgproc/recursiveintegralsampler.cpp deleted
1 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
2 - * Copyright 2012 The MITRE Corporation *  
3 - * *  
4 - * Licensed under the Apache License, Version 2.0 (the "License"); *  
5 - * you may not use this file except in compliance with the License. *  
6 - * You may obtain a copy of the License at *  
7 - * *  
8 - * http://www.apache.org/licenses/LICENSE-2.0 *  
9 - * *  
10 - * Unless required by applicable law or agreed to in writing, software *  
11 - * distributed under the License is distributed on an "AS IS" BASIS, *  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  
13 - * See the License for the specific language governing permissions and *  
14 - * limitations under the License. *  
15 - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */  
16 -  
17 -#include <Eigen/Dense>  
18 -  
19 -#include <openbr/plugins/openbr_internal.h>  
20 -  
21 -using namespace cv;  
22 -  
23 -namespace br  
24 -{  
25 -  
26 -/*!  
27 - * \ingroup transforms  
28 - * \brief Construct Template in a recursive decent manner.  
29 - * \author Josh Klontz \cite jklontz  
30 - */  
31 -class RecursiveIntegralSamplerTransform : public Transform  
32 -{  
33 - Q_OBJECT  
34 - Q_PROPERTY(int scales READ get_scales WRITE set_scales RESET reset_scales STORED false)  
35 - Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false)  
36 - Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false)  
37 - Q_PROPERTY(br::Transform *transform READ get_transform WRITE set_transform RESET reset_transform)  
38 - BR_PROPERTY(int, scales, 6)  
39 - BR_PROPERTY(float, scaleFactor, 2)  
40 - BR_PROPERTY(int, minSize, 8)  
41 - BR_PROPERTY(br::Transform*, transform, NULL)  
42 -  
43 - Transform *subTransform;  
44 -  
45 - typedef Eigen::Map< const Eigen::Matrix<qint32,Eigen::Dynamic,1> > InputDescriptor;  
46 - typedef Eigen::Map< Eigen::Matrix<float,Eigen::Dynamic,1> > OutputDescriptor;  
47 - typedef Eigen::Map< const Eigen::Matrix<float,Eigen::Dynamic,1> > SecondOrderInputDescriptor;  
48 -  
49 - void init()  
50 - {  
51 - if (scales >= 2) {  
52 - File subFile = file;  
53 - subFile.set("scales", scales-1);  
54 - subTransform = make(subFile.flat());  
55 - } else {  
56 - subTransform = NULL;  
57 - }  
58 - }  
59 -  
60 - static void integralHistogram(const Mat &src, const int x, const int y, const int width, const int height, Mat &dst, int index)  
61 - {  
62 - const int channels = src.channels();  
63 - OutputDescriptor(dst.ptr<float>(index), channels, 1) =  
64 - ( InputDescriptor(src.ptr<qint32>(y+height, x+width), channels, 1)  
65 - - InputDescriptor(src.ptr<qint32>(y, x+width), channels, 1)  
66 - - InputDescriptor(src.ptr<qint32>(y+height, x), channels, 1)  
67 - + InputDescriptor(src.ptr<qint32>(y, x), channels, 1)).cast<float>()/(height*width);  
68 - }  
69 -  
70 - void computeDescriptor(const Mat &src, Mat &dst) const  
71 - {  
72 - const int channels = src.channels();  
73 - const int rows = src.rows-1; // Integral images have an extra row and column  
74 - const int columns = src.cols-1;  
75 -  
76 - Mat tmp(5, channels, CV_32FC1);  
77 - integralHistogram(src, 0, 0, columns/2, rows/2, tmp, 0);  
78 - integralHistogram(src, columns/2, 0, columns/2, rows/2, tmp, 1);  
79 - integralHistogram(src, 0, rows/2, columns/2, rows/2, tmp, 2);  
80 - integralHistogram(src, columns/2, rows/2, columns/2, rows/2, tmp, 3);  
81 - integralHistogram(src, columns/4, rows/4, columns/2, rows/2, tmp, 4);  
82 - const SecondOrderInputDescriptor a(tmp.ptr<float>(0), channels, 1);  
83 - const SecondOrderInputDescriptor b(tmp.ptr<float>(1), channels, 1);  
84 - const SecondOrderInputDescriptor c(tmp.ptr<float>(2), channels, 1);  
85 - const SecondOrderInputDescriptor d(tmp.ptr<float>(3), channels, 1);  
86 - const SecondOrderInputDescriptor e(tmp.ptr<float>(4), channels, 1);  
87 -  
88 - dst = Mat(5, channels, CV_32FC1);  
89 - OutputDescriptor(dst.ptr<float>(0), channels, 1) = (a+b+c+d)/4.f;  
90 - OutputDescriptor(dst.ptr<float>(1), channels, 1) = ((a+b+c+d)/4.f-e);  
91 - OutputDescriptor(dst.ptr<float>(2), channels, 1) = ((a+b)-(c+d))/2.f;  
92 - OutputDescriptor(dst.ptr<float>(3), channels, 1) = ((a+c)-(b+d))/2.f;  
93 - OutputDescriptor(dst.ptr<float>(4), channels, 1) = ((a+d)-(b+c))/2.f;  
94 - dst = dst.reshape(1, 1);  
95 - }  
96 -  
97 - Template subdivide(const Template &src) const  
98 - {  
99 - // Integral images have an extra row and column  
100 - int subWidth = (src.m().cols-1) / scaleFactor + 1;  
101 - int subHeight = (src.m().rows-1) / scaleFactor + 1;  
102 - return Template(src.file, QList<Mat>() << Mat(src, Rect(0, 0, subWidth, subHeight))  
103 - << Mat(src, Rect(src.m().cols-subWidth, 0, subWidth, subHeight))  
104 - << Mat(src, Rect(0, src.m().rows-subHeight, subWidth, subHeight))  
105 - << Mat(src, Rect(src.m().cols-subWidth, src.m().rows-subHeight, subWidth, subHeight)));  
106 - }  
107 -  
108 - bool canSubdivide(const Template &t) const  
109 - {  
110 - // Integral images have an extra row and column  
111 - const int subWidth = (t.m().cols-1) / scaleFactor;  
112 - const int subHeight = (t.m().rows-1) / scaleFactor;  
113 - return ((subWidth >= minSize) && (subHeight >= minSize));  
114 - }  
115 -  
116 - void train(const TemplateList &src)  
117 - {  
118 - if (src.first().m().depth() != CV_32S)  
119 - qFatal("Expected CV_32S depth!");  
120 -  
121 - if (subTransform != NULL) {  
122 - TemplateList subSrc; subSrc.reserve(src.size());  
123 - foreach (const Template &t, src)  
124 - if (canSubdivide(t))  
125 - subSrc.append(subdivide(t));  
126 -  
127 - if (subSrc.isEmpty()) {  
128 - delete subTransform;  
129 - subTransform = NULL;  
130 - } else {  
131 - subTransform->train(subSrc);  
132 - }  
133 - }  
134 -  
135 - TemplateList dst; dst.reserve(src.size());  
136 - foreach (const Template &t, src) {  
137 - Template u(t.file);  
138 - computeDescriptor(t, u);  
139 - dst.append(u);  
140 - }  
141 - transform->train(dst);  
142 - }  
143 -  
144 - void project(const Template &src, Template &dst) const  
145 - {  
146 - computeDescriptor(src, dst);  
147 - transform->project(dst, dst);  
148 -  
149 - if ((subTransform != NULL) && canSubdivide(src)) {  
150 - Template subDst;  
151 - subTransform->project(subdivide(src), subDst);  
152 - dst.append(subDst);  
153 - }  
154 - }  
155 -  
156 - void store(QDataStream &stream) const  
157 - {  
158 - transform->store(stream);  
159 - stream << (subTransform != NULL);  
160 - if (subTransform != NULL)  
161 - subTransform->store(stream);  
162 - }  
163 -  
164 - void load(QDataStream &stream)  
165 - {  
166 - transform->load(stream);  
167 - bool hasSubTransform;  
168 - stream >> hasSubTransform;  
169 - if (hasSubTransform) subTransform->load(stream);  
170 - else { delete subTransform; subTransform = NULL; }  
171 - }  
172 -};  
173 -  
174 -BR_REGISTER(Transform, RecursiveIntegralSamplerTransform)  
175 -  
176 -} // namespace br  
177 -  
178 -#include "imgproc/recursiveintegralsampler.moc"