Commit 590bb5d8505ee94314b1f04159d524e0f37a077b
1 parent
f05c88a7
more new transforms
Showing
5 changed files
with
95 additions
and
7 deletions
sdk/plugins/algorithms.cpp
| ... | ... | @@ -50,7 +50,7 @@ class AlgorithmsInitializer : public Initializer |
| 50 | 50 | Globals->abbreviations.insert("SmallSIFT", "Open+LimitSize(512)+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); |
| 51 | 51 | Globals->abbreviations.insert("SmallSURF", "Open+LimitSize(512)+KeyPointDetector(SURF)+KeyPointDescriptor(SURF):KeyPointMatcher(BruteForce)"); |
| 52 | 52 | Globals->abbreviations.insert("ColorHist", "Open+LimitSize(512)!EnsureChannels(3)+SplitChannels+Hist(256,0,8)+Cat+Normalize(L1):L2"); |
| 53 | - Globals->abbreviations.insert("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat:L2"); | |
| 53 | + Globals->abbreviations.insert("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat+RowWisePCA(8)+RowWiseMeanCenter+Binarize:L2"); | |
| 54 | 54 | |
| 55 | 55 | // Hash |
| 56 | 56 | Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); | ... | ... |
sdk/plugins/eigen3.cpp
| ... | ... | @@ -32,6 +32,10 @@ namespace br |
| 32 | 32 | class PCATransform : public Transform |
| 33 | 33 | { |
| 34 | 34 | Q_OBJECT |
| 35 | + friend class DFFSTransform; | |
| 36 | + friend class LDATransform; | |
| 37 | + | |
| 38 | +protected: | |
| 35 | 39 | Q_PROPERTY(float keep READ get_keep WRITE set_keep RESET reset_keep STORED false) |
| 36 | 40 | Q_PROPERTY(int drop READ get_drop WRITE set_drop RESET reset_drop STORED false) |
| 37 | 41 | Q_PROPERTY(bool whiten READ get_whiten WRITE set_whiten RESET reset_whiten STORED false) |
| ... | ... | @@ -42,12 +46,10 @@ class PCATransform : public Transform |
| 42 | 46 | BR_PROPERTY(int, drop, 0) |
| 43 | 47 | BR_PROPERTY(bool, whiten, false) |
| 44 | 48 | |
| 45 | - int originalRows; | |
| 46 | 49 | Eigen::VectorXf mean, eVals; |
| 47 | 50 | Eigen::MatrixXf eVecs; |
| 48 | 51 | |
| 49 | - friend class DFFSTransform; | |
| 50 | - friend class LDATransform; | |
| 52 | + int originalRows; | |
| 51 | 53 | |
| 52 | 54 | public: |
| 53 | 55 | PCATransform() : keep(0.95), drop(0), whiten(false) {} |
| ... | ... | @@ -118,6 +120,7 @@ private: |
| 118 | 120 | stream >> keep >> drop >> whiten >> originalRows >> mean >> eVals >> eVecs; |
| 119 | 121 | } |
| 120 | 122 | |
| 123 | +protected: | |
| 121 | 124 | void train(Eigen::MatrixXd data) |
| 122 | 125 | { |
| 123 | 126 | int dimsIn = data.rows(); |
| ... | ... | @@ -200,6 +203,50 @@ BR_REGISTER(Transform, PCATransform) |
| 200 | 203 | |
| 201 | 204 | /*! |
| 202 | 205 | * \ingroup transforms |
| 206 | + * \brief PCA on each row. | |
| 207 | + * \author Josh Klontz \cite jklontz | |
| 208 | + */ | |
| 209 | +class RowWisePCATransform : public PCATransform | |
| 210 | +{ | |
| 211 | + Q_OBJECT | |
| 212 | + | |
| 213 | + void train(const TemplateList &trainingSet) | |
| 214 | + { | |
| 215 | + if (trainingSet.first().m().type() != CV_32FC1) | |
| 216 | + qFatal("Requires single channel 32-bit floating point matrices."); | |
| 217 | + | |
| 218 | + originalRows = trainingSet.first().m().rows; | |
| 219 | + const int dimsIn = trainingSet.first().m().cols; | |
| 220 | + int instances = 0; | |
| 221 | + foreach (const Template &t, trainingSet) | |
| 222 | + instances += t.m().rows; | |
| 223 | + | |
| 224 | + // Map into 64-bit Eigen matrix | |
| 225 | + Eigen::MatrixXd data(dimsIn, instances); | |
| 226 | + int index = 0; | |
| 227 | + foreach (const Template &t, trainingSet) | |
| 228 | + for (int i=0; i<t.m().rows; i++) | |
| 229 | + data.col(index++) = Eigen::Map<const Eigen::MatrixXf>(t.m().ptr<float>(i), dimsIn, 1).cast<double>(); | |
| 230 | + | |
| 231 | + PCATransform::train(data); | |
| 232 | + } | |
| 233 | + | |
| 234 | + void project(const Template &src, Template &dst) const | |
| 235 | + { | |
| 236 | + dst = cv::Mat(src.m().rows, keep, CV_32FC1); | |
| 237 | + | |
| 238 | + for (int i=0; i<src.m().rows; i++) { | |
| 239 | + Eigen::Map<const Eigen::MatrixXf> inMap(src.m().ptr<float>(i), src.m().cols, 1); | |
| 240 | + Eigen::Map<Eigen::MatrixXf> outMap(dst.m().ptr<float>(i), keep, 1); | |
| 241 | + outMap = eVecs.transpose() * (inMap - mean); | |
| 242 | + } | |
| 243 | + } | |
| 244 | +}; | |
| 245 | + | |
| 246 | +BR_REGISTER(Transform, RowWisePCATransform) | |
| 247 | + | |
| 248 | +/*! | |
| 249 | + * \ingroup transforms | |
| 203 | 250 | * \brief Computes Distance From Feature Space (DFFS) \cite moghaddam97. |
| 204 | 251 | * \author Josh Klontz \cite jklontz |
| 205 | 252 | */ | ... | ... |
sdk/plugins/integral.cpp
| ... | ... | @@ -38,8 +38,8 @@ class IntegralSamplerTransform : public UntrainableTransform |
| 38 | 38 | Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false) |
| 39 | 39 | Q_PROPERTY(float stepFactor READ get_stepFactor WRITE set_stepFactor RESET reset_stepFactor STORED false) |
| 40 | 40 | Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false) |
| 41 | - BR_PROPERTY(int, scales, 3) | |
| 42 | - BR_PROPERTY(float, scaleFactor, 2) | |
| 41 | + BR_PROPERTY(int, scales, 4) | |
| 42 | + BR_PROPERTY(float, scaleFactor, 1.5) | |
| 43 | 43 | BR_PROPERTY(float, stepFactor, 0.25) |
| 44 | 44 | BR_PROPERTY(int, minSize, 8) |
| 45 | 45 | ... | ... |
sdk/plugins/normalize.cpp
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 | #include <QtConcurrentRun> |
| 18 | 18 | #include <opencv2/imgproc/imgproc.hpp> |
| 19 | 19 | #include <opencv2/highgui/highgui.hpp> |
| 20 | +#include <Eigen/Core> | |
| 20 | 21 | #include <openbr_plugin.h> |
| 21 | 22 | |
| 22 | 23 | #include "core/common.h" |
| ... | ... | @@ -184,6 +185,45 @@ private: |
| 184 | 185 | |
| 185 | 186 | BR_REGISTER(Transform, CenterTransform) |
| 186 | 187 | |
| 188 | +/*! | |
| 189 | + * \ingroup transforms | |
| 190 | + * \brief Remove the row-wise training set average. | |
| 191 | + * \author Josh Klontz \cite jklontz | |
| 192 | + */ | |
| 193 | +class RowWiseMeanCenterTransform : public Transform | |
| 194 | +{ | |
| 195 | + Q_OBJECT | |
| 196 | + Mat mean; | |
| 197 | + | |
| 198 | + void train(const TemplateList &data) | |
| 199 | + { | |
| 200 | + Mat m = OpenCVUtils::toMatByRow(data.data()); | |
| 201 | + mean = Mat(1, m.cols, m.type()); | |
| 202 | + for (int i=0; i<m.cols; i++) | |
| 203 | + mean.col(i) = cv::mean(m.col(i)); | |
| 204 | + } | |
| 205 | + | |
| 206 | + void project(const Template &src, Template &dst) const | |
| 207 | + { | |
| 208 | + Mat m = src.m().clone(); | |
| 209 | + for (int i=0; i<m.rows; i++) | |
| 210 | + m.row(i) -= mean; | |
| 211 | + dst = m; | |
| 212 | + } | |
| 213 | + | |
| 214 | + void store(QDataStream &stream) const | |
| 215 | + { | |
| 216 | + stream << mean; | |
| 217 | + } | |
| 218 | + | |
| 219 | + void load(QDataStream &stream) | |
| 220 | + { | |
| 221 | + stream >> mean; | |
| 222 | + } | |
| 223 | +}; | |
| 224 | + | |
| 225 | +BR_REGISTER(Transform, RowWiseMeanCenterTransform) | |
| 226 | + | |
| 187 | 227 | } // namespace br |
| 188 | 228 | |
| 189 | 229 | #include "normalize.moc" | ... | ... |
sdk/plugins/quantize.cpp
| ... | ... | @@ -64,7 +64,8 @@ class BinarizeTransform : public UntrainableTransform |
| 64 | 64 | void project(const Template &src, Template &dst) const |
| 65 | 65 | { |
| 66 | 66 | const Mat &m = src; |
| 67 | - assert((m.cols % 8 == 0) && (m.type() == CV_32FC1)); | |
| 67 | + if ((m.cols % 8 != 0) || (m.type() != CV_32FC1)) | |
| 68 | + qFatal("Expected CV_32FC1 matrix with a multiple of 8 columns."); | |
| 68 | 69 | Mat n(m.rows, m.cols/8, CV_8UC1); |
| 69 | 70 | for (int i=0; i<m.rows; i++) |
| 70 | 71 | for (int j=0; j<m.cols-7; j+=8) | ... | ... |