diff --git a/openbr/plugins/imgproc/rndsubspace.cpp b/openbr/plugins/imgproc/rndsubspace.cpp index e6f6972..423dbc9 100644 --- a/openbr/plugins/imgproc/rndsubspace.cpp +++ b/openbr/plugins/imgproc/rndsubspace.cpp @@ -30,7 +30,7 @@ namespace br * \brief Generates a random subspace. * \author Josh Klontz \cite jklontz */ -class RndSubspaceTransform : public Transform +class RndSubspaceTransform : public MetaTransform { Q_OBJECT Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false) @@ -38,54 +38,66 @@ class RndSubspaceTransform : public Transform BR_PROPERTY(float, fraction, 0.5) BR_PROPERTY(bool, weighted, false) - Mat map; + QList maps; void train(const TemplateList &data) { - int cols = data.first().m().cols; - int size = data.first().m().rows * cols; - QList weights; weights.reserve(size); - if (weighted) { - Mat flatData = OpenCVUtils::toMat(data.data()); - for (int i=0; i weights; weights.reserve(size); + if (weighted) { + Mat flatData = OpenCVUtils::toMat(data.data()); + for (int i=0; i sample = Common::RandSample(dimsOut, weights); - Mat xMap(1, dimsOut, CV_16SC1); - Mat yMap(1, dimsOut, CV_16SC1); - for (int j=0; j(0,j) = index % cols; - yMap.at(0,j) = index / cols; - } - std::vector mv; - mv.push_back(xMap); - mv.push_back(yMap); + QList sample = Common::RandSample(dimsOut, weights); + Mat xMap(1, dimsOut, CV_16SC1); + Mat yMap(1, dimsOut, CV_16SC1); + for (int j=0; j(0,j) = index % cols; + yMap.at(0,j) = index / cols; + } + std::vector mv; + mv.push_back(xMap); + mv.push_back(yMap); - merge(mv, map); + Mat map; + merge(mv, map); + maps.append(map); + } } void project(const Template &src, Template &dst) const { - remap(src, dst, map, Mat(), INTER_NEAREST); + dst.file = src.file; + for (int i=0; i> fraction >> weighted >> map; + stream >> maps; } };