Commit 9f4327d3b48b388ef0074b7a6fff15bbcd895366

Authored by Josh Klontz
1 parent ac8caa74

remove rndsample

openbr/plugins/imgproc/rndsample.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 <numeric>  
18 -  
19 -#include <openbr/plugins/openbr_internal.h>  
20 -#include <openbr/core/opencvutils.h>  
21 -#include <openbr/core/qtutils.h>  
22 -  
23 -using namespace cv;  
24 -  
25 -namespace br  
26 -{  
27 -  
28 -/*!  
29 - * \ingroup transforms  
30 - * \brief Selects a random region about a point to use for training.  
31 - * \author Scott Klum \cite sklum  
32 - */  
33 -  
34 -class RndSampleTransform : public UntrainableMetaTransform  
35 -{  
36 - Q_OBJECT  
37 - Q_PROPERTY(int pointIndex READ get_pointIndex WRITE set_pointIndex RESET reset_pointIndex)  
38 - Q_PROPERTY(int sampleRadius READ get_sampleRadius WRITE set_sampleRadius RESET reset_sampleRadius)  
39 - Q_PROPERTY(int sampleFactor READ get_sampleFactor WRITE set_sampleFactor RESET reset_sampleFactor)  
40 - Q_PROPERTY(bool duplicatePositiveSamples READ get_duplicatePositiveSamples WRITE set_duplicatePositiveSamples RESET reset_duplicatePositiveSamples STORED true)  
41 - Q_PROPERTY(QList<float> sampleOverlapBands READ get_sampleOverlapBands WRITE set_sampleOverlapBands RESET reset_sampleOverlapBands STORED true)  
42 - Q_PROPERTY(int samplesPerOverlapBand READ get_samplesPerOverlapBand WRITE set_samplesPerOverlapBand RESET reset_samplesPerOverlapBand STORED true)  
43 - Q_PROPERTY(bool classification READ get_classification WRITE set_classification RESET reset_classification STORED true)  
44 - Q_PROPERTY(float overlapPower READ get_overlapPower WRITE set_overlapPower RESET reset_overlapPower STORED true)  
45 - Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED true)  
46 - BR_PROPERTY(int, pointIndex, 0)  
47 - BR_PROPERTY(int, sampleRadius, 6)  
48 - BR_PROPERTY(int, sampleFactor, 4)  
49 - BR_PROPERTY(bool, duplicatePositiveSamples, true)  
50 - BR_PROPERTY(QList<float>, sampleOverlapBands, QList<float>() << .1 << .5 << .7 << .9 << 1.0)  
51 - BR_PROPERTY(int, samplesPerOverlapBand, 2)  
52 - BR_PROPERTY(bool, classification, true)  
53 - BR_PROPERTY(float, overlapPower, 1)  
54 - BR_PROPERTY(QString, inputVariable, "Label")  
55 -  
56 - void project(const TemplateList &src, TemplateList &dst) const  
57 - {  
58 - foreach(const Template &t, src) {  
59 - QPointF point = t.file.points()[pointIndex];  
60 - QRectF region(point.x()-sampleRadius, point.y()-sampleRadius, sampleRadius*2, sampleRadius*2);  
61 -  
62 - if (region.x() < 0 ||  
63 - region.y() < 0 ||  
64 - region.x() + region.width() >= t.m().cols ||  
65 - region.y() + region.height() >= t.m().rows)  
66 - continue;  
67 -  
68 - int positiveSamples = duplicatePositiveSamples ? (sampleOverlapBands.size()-1)*samplesPerOverlapBand : 1;  
69 - for (int k=0; k<positiveSamples; k++) {  
70 - dst.append(Template(t.file, Mat(t.m(), OpenCVUtils::toRect(region))));  
71 - dst.last().file.set(inputVariable, 1);  
72 - }  
73 -  
74 - QList<int> labelCount;  
75 - for (int k=0; k<sampleOverlapBands.size()-1; k++)  
76 - labelCount << 0;  
77 -  
78 - while (std::accumulate(labelCount.begin(),labelCount.end(),0.0) < (sampleOverlapBands.size()-1)*samplesPerOverlapBand) {  
79 -  
80 - float x = rand() % (sampleFactor*sampleRadius) + region.x() - sampleFactor/2*sampleRadius;  
81 - float y = rand() % (sampleFactor*sampleRadius) + region.y() - sampleFactor/2*sampleRadius;  
82 -  
83 - if (x < 0 || y < 0 || x+2*sampleRadius > t.m().cols || y+2*sampleRadius > t.m().rows)  
84 - continue;  
85 -  
86 - QRectF negativeLocation = QRectF(x, y, sampleRadius*2, sampleRadius*2);  
87 -  
88 - float overlap = pow(QtUtils::overlap(region, negativeLocation),overlapPower);  
89 -  
90 - for (int k = 0; k<sampleOverlapBands.size()-1; k++) {  
91 - if (overlap >= sampleOverlapBands.at(k) && overlap < sampleOverlapBands.at(k+1) && labelCount[k] < samplesPerOverlapBand) {  
92 - Mat m(t.m(),OpenCVUtils::toRect(negativeLocation));  
93 - dst.append(Template(t.file, m));  
94 - float label = classification ? 0 : overlap;  
95 - dst.last().file.set(inputVariable, label);  
96 - labelCount[k]++;  
97 - }  
98 - }  
99 - }  
100 - }  
101 - }  
102 -  
103 - void project(const Template &src, Template &dst) const {  
104 - TemplateList temp;  
105 - project(TemplateList() << src, temp);  
106 - if (!temp.isEmpty()) dst = temp.first();  
107 - }  
108 -  
109 -};  
110 -  
111 -BR_REGISTER(Transform, RndSampleTransform)  
112 -  
113 -} // namespace br  
114 -  
115 -#include "imgproc/rndsample.moc"