Commit f7dddb1fc7f2da3c3f51b5e8d5334007cd520caa
1 parent
71885f41
Sample bug fixes/tweaks
Showing
1 changed file
with
5 additions
and
3 deletions
openbr/plugins/random.cpp
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | #include <numeric> | 17 | #include <numeric> |
| 18 | 18 | ||
| 19 | #include <opencv2/imgproc/imgproc.hpp> | 19 | #include <opencv2/imgproc/imgproc.hpp> |
| 20 | + | ||
| 20 | #include "openbr_internal.h" | 21 | #include "openbr_internal.h" |
| 21 | 22 | ||
| 22 | #include "openbr/core/common.h" | 23 | #include "openbr/core/common.h" |
| @@ -164,7 +165,7 @@ class RndSampleTransform : public UntrainableMetaTransform | @@ -164,7 +165,7 @@ class RndSampleTransform : public UntrainableMetaTransform | ||
| 164 | void project(const TemplateList &src, TemplateList &dst) const | 165 | void project(const TemplateList &src, TemplateList &dst) const |
| 165 | { | 166 | { |
| 166 | foreach(const Template &t, src) { | 167 | foreach(const Template &t, src) { |
| 167 | - QPointF point = t.file.points()[0]; | 168 | + QPointF point = t.file.points()[pointIndex]; |
| 168 | QRectF region(point.x()-sampleRadius, point.y()-sampleRadius, sampleRadius*2, sampleRadius*2); | 169 | QRectF region(point.x()-sampleRadius, point.y()-sampleRadius, sampleRadius*2, sampleRadius*2); |
| 169 | 170 | ||
| 170 | if (region.x() < 0 || | 171 | if (region.x() < 0 || |
| @@ -184,6 +185,7 @@ class RndSampleTransform : public UntrainableMetaTransform | @@ -184,6 +185,7 @@ class RndSampleTransform : public UntrainableMetaTransform | ||
| 184 | labelCount << 0; | 185 | labelCount << 0; |
| 185 | 186 | ||
| 186 | while (std::accumulate(labelCount.begin(),labelCount.end(),0.0) < (sampleOverlapBands.size()-1)*samplesPerOverlapBand) { | 187 | while (std::accumulate(labelCount.begin(),labelCount.end(),0.0) < (sampleOverlapBands.size()-1)*samplesPerOverlapBand) { |
| 188 | + | ||
| 187 | float x = rand() % (sampleFactor*sampleRadius) + region.x() - sampleFactor/2*sampleRadius; | 189 | float x = rand() % (sampleFactor*sampleRadius) + region.x() - sampleFactor/2*sampleRadius; |
| 188 | float y = rand() % (sampleFactor*sampleRadius) + region.y() - sampleFactor/2*sampleRadius; | 190 | float y = rand() % (sampleFactor*sampleRadius) + region.y() - sampleFactor/2*sampleRadius; |
| 189 | 191 | ||
| @@ -192,13 +194,13 @@ class RndSampleTransform : public UntrainableMetaTransform | @@ -192,13 +194,13 @@ class RndSampleTransform : public UntrainableMetaTransform | ||
| 192 | 194 | ||
| 193 | QRectF negativeLocation = QRectF(x, y, sampleRadius*2, sampleRadius*2); | 195 | QRectF negativeLocation = QRectF(x, y, sampleRadius*2, sampleRadius*2); |
| 194 | 196 | ||
| 195 | - float overlap = QtUtils::overlap(region, negativeLocation); | 197 | + float overlap = pow(QtUtils::overlap(region, negativeLocation),overlapPower); |
| 196 | 198 | ||
| 197 | for (int k = 0; k<sampleOverlapBands.size()-1; k++) { | 199 | for (int k = 0; k<sampleOverlapBands.size()-1; k++) { |
| 198 | if (overlap >= sampleOverlapBands.at(k) && overlap < sampleOverlapBands.at(k+1) && labelCount[k] < samplesPerOverlapBand) { | 200 | if (overlap >= sampleOverlapBands.at(k) && overlap < sampleOverlapBands.at(k+1) && labelCount[k] < samplesPerOverlapBand) { |
| 199 | Mat m(t.m(),OpenCVUtils::toRect(negativeLocation)); | 201 | Mat m(t.m(),OpenCVUtils::toRect(negativeLocation)); |
| 200 | dst.append(Template(t.file, m)); | 202 | dst.append(Template(t.file, m)); |
| 201 | - float label = classification ? 0 : pow(overlap,overlapPower); | 203 | + float label = classification ? 0 : overlap; |
| 202 | dst.last().file.set(inputVariable, label); | 204 | dst.last().file.set(inputVariable, label); |
| 203 | labelCount[k]++; | 205 | labelCount[k]++; |
| 204 | } | 206 | } |