diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 9322f5d..97eaa3d 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -476,13 +476,18 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) // indexes some property, assigns an integer id to each unique value of propName // stores the index values in "Label" of the output template list -TemplateList TemplateList::relabel(const TemplateList &tl, const QString & propName) +TemplateList TemplateList::relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers) { const QList originalLabels = File::get(tl, propName); QHash labelTable; - foreach (const QString & label, originalLabels) - if (!labelTable.contains(label)) - labelTable.insert(label, labelTable.size()); + foreach (const QString &label, originalLabels) + if (!labelTable.contains(label)) { + int value; bool ok; + value = label.toInt(&ok); + // If the label is already an integer value we don't want to change it. + if (ok && preserveIntegers) labelTable.insert(label, value); + else labelTable.insert(label, labelTable.size()); + } TemplateList result = tl; for (int i=0; i BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */ /*!< \brief Ensure labels are in the range [0,numClasses-1]. */ - BR_EXPORT static TemplateList relabel(const TemplateList & tl, const QString & propName); + BR_EXPORT static TemplateList relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers); QList indexProperty(const QString & propName, QHash * valueMap=NULL,QHash * reverseLookup = NULL) const; QList indexProperty(const QString & propName, QHash & valueMap, QHash & reverseLookup) const; diff --git a/openbr/plugins/eigen3.cpp b/openbr/plugins/eigen3.cpp index 8341b22..28a805f 100644 --- a/openbr/plugins/eigen3.cpp +++ b/openbr/plugins/eigen3.cpp @@ -317,7 +317,7 @@ class LDATransform : public Transform void train(const TemplateList &_trainingSet) { // creates "Label" - TemplateList trainingSet = TemplateList::relabel(_trainingSet, inputVariable); + TemplateList trainingSet = TemplateList::relabel(_trainingSet, inputVariable, isBinary); int instances = trainingSet.size(); // Perform PCA dimensionality reduction diff --git a/openbr/plugins/slidingwindow.cpp b/openbr/plugins/slidingwindow.cpp index 2fbe4c2..17f39c4 100644 --- a/openbr/plugins/slidingwindow.cpp +++ b/openbr/plugins/slidingwindow.cpp @@ -42,15 +42,15 @@ class SlidingWindowTransform : public MetaTransform { Q_OBJECT Q_PROPERTY(br::Transform *transform READ get_transform WRITE set_transform RESET reset_transform STORED false) - Q_PROPERTY(int stepSize READ get_stepSize WRITE set_stepSize RESET reset_stepSize STORED false) - Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false) Q_PROPERTY(int windowWidth READ get_windowWidth WRITE set_windowWidth RESET reset_windowWidth STORED false) + Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false) Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) + Q_PROPERTY(float stepFraction READ get_stepFraction WRITE set_stepFraction RESET reset_stepFraction STORED false) BR_PROPERTY(br::Transform *, transform, NULL) - BR_PROPERTY(int, stepSize, 1) - BR_PROPERTY(bool, takeFirst, false) BR_PROPERTY(int, windowWidth, 24) + BR_PROPERTY(bool, takeFirst, false) BR_PROPERTY(float, threshold, 0) + BR_PROPERTY(float, stepFraction, 0.25) private: int windowHeight; @@ -66,6 +66,19 @@ private: } } + void store(QDataStream &stream) const + { + transform->store(stream); + stream << windowHeight; + } + + void load(QDataStream &stream) + { + transform->load(stream); + stream >> windowHeight; + } + +protected: // Let IntegralSlidingWindowTransform access this void project(const Template &src, Template &dst) const { (void)src;(void)dst;qFatal("don't do that"); @@ -100,21 +113,28 @@ private: } } } +}; - void store(QDataStream &stream) const - { - transform->store(stream); - stream << windowHeight; - } +BR_REGISTER(Transform, SlidingWindowTransform) - void load(QDataStream &stream) +/*! + * \ingroup transforms + * \brief Overloads SlidingWindowTransform for integral images that should be + * sampled at multiple scales. + * \author Josh Klontz \cite jklontz + */ +class IntegralSlidingWindowTransform : public SlidingWindowTransform +{ + Q_OBJECT + + void project(const Template &src, Template &dst) const { - transform->load(stream); - stream >> windowHeight; + // TODO: call SlidingWindowTransform::project on multiple scales + SlidingWindowTransform::project(src, dst); } }; -BR_REGISTER(Transform, SlidingWindowTransform) +BR_REGISTER(Transform, IntegralSlidingWindowTransform) static TemplateList cropTrainingSamples(const TemplateList &data, const float aspectRatio, const int minSize = 32, const float maxOverlap = 0.5, const int negToPosRatio = 1) { diff --git a/scripts/pedestrianBaselineLBP.sh b/scripts/pedestrianBaselineLBP.sh index e5e70e6..ea6af8f 100755 --- a/scripts/pedestrianBaselineLBP.sh +++ b/scripts/pedestrianBaselineLBP.sh @@ -13,7 +13,7 @@ fi ALG="Open+Cvt(Gray)+Rename(neg,0)+BuildScales(Blur(2)+LBP(1,2)+SlidingWindow(Hist(59)+Cat+LDA(isBinary=true),windowWidth=10,takeLargestScale=false,threshold=2),windowWidth=10,takeLargestScale=false,minScale=4)+ConsolidateDetections+Discard" # Josh's new algorithm (in progress) -# ALG2="Open+Cvt(Gray)+Detector(Gradient+Bin(0,360,9,true)+Merge+Integral+SlidingWindow(Identity))" +# ALG="Open+Cvt(Gray)+Detector(Gradient+Bin(0,360,9,true)+Merge+Integral+IntegralSlidingWindow(RecursiveIntegralSampler(2,2,0,PCA(0.95))+Cat+LDA(0.95,isBinary=true)))" br -useGui 0 \ -algorithm "${ALG}" \