Commit a7fbfd50b1b964c88a5aa8b1c277ba680dafe1af

Authored by Austin Blanton
2 parents b573c3bb 7a0a9f3e

Merge SlidingWindowTransform conflicts

Conflicts:
	openbr/plugins/slidingwindow.cpp
openbr/openbr_plugin.cpp
@@ -476,13 +476,18 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) @@ -476,13 +476,18 @@ TemplateList TemplateList::fromGallery(const br::File &gallery)
476 476
477 // indexes some property, assigns an integer id to each unique value of propName 477 // indexes some property, assigns an integer id to each unique value of propName
478 // stores the index values in "Label" of the output template list 478 // stores the index values in "Label" of the output template list
479 -TemplateList TemplateList::relabel(const TemplateList &tl, const QString & propName) 479 +TemplateList TemplateList::relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers)
480 { 480 {
481 const QList<QString> originalLabels = File::get<QString>(tl, propName); 481 const QList<QString> originalLabels = File::get<QString>(tl, propName);
482 QHash<QString,int> labelTable; 482 QHash<QString,int> labelTable;
483 - foreach (const QString & label, originalLabels)  
484 - if (!labelTable.contains(label))  
485 - labelTable.insert(label, labelTable.size()); 483 + foreach (const QString &label, originalLabels)
  484 + if (!labelTable.contains(label)) {
  485 + int value; bool ok;
  486 + value = label.toInt(&ok);
  487 + // If the label is already an integer value we don't want to change it.
  488 + if (ok && preserveIntegers) labelTable.insert(label, value);
  489 + else labelTable.insert(label, labelTable.size());
  490 + }
486 491
487 TemplateList result = tl; 492 TemplateList result = tl;
488 for (int i=0; i<result.size(); i++) 493 for (int i=0; i<result.size(); i++)
openbr/openbr_plugin.h
@@ -438,7 +438,7 @@ struct TemplateList : public QList&lt;Template&gt; @@ -438,7 +438,7 @@ struct TemplateList : public QList&lt;Template&gt;
438 BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */ 438 BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */
439 439
440 /*!< \brief Ensure labels are in the range [0,numClasses-1]. */ 440 /*!< \brief Ensure labels are in the range [0,numClasses-1]. */
441 - BR_EXPORT static TemplateList relabel(const TemplateList & tl, const QString & propName); 441 + BR_EXPORT static TemplateList relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers);
442 442
443 QList<int> indexProperty(const QString & propName, QHash<QString, int> * valueMap=NULL,QHash<int, QVariant> * reverseLookup = NULL) const; 443 QList<int> indexProperty(const QString & propName, QHash<QString, int> * valueMap=NULL,QHash<int, QVariant> * reverseLookup = NULL) const;
444 QList<int> indexProperty(const QString & propName, QHash<QString, int> & valueMap, QHash<int, QVariant> & reverseLookup) const; 444 QList<int> indexProperty(const QString & propName, QHash<QString, int> & valueMap, QHash<int, QVariant> & reverseLookup) const;
openbr/plugins/eigen3.cpp
@@ -317,7 +317,7 @@ class LDATransform : public Transform @@ -317,7 +317,7 @@ class LDATransform : public Transform
317 void train(const TemplateList &_trainingSet) 317 void train(const TemplateList &_trainingSet)
318 { 318 {
319 // creates "Label" 319 // creates "Label"
320 - TemplateList trainingSet = TemplateList::relabel(_trainingSet, inputVariable); 320 + TemplateList trainingSet = TemplateList::relabel(_trainingSet, inputVariable, isBinary);
321 int instances = trainingSet.size(); 321 int instances = trainingSet.size();
322 322
323 // Perform PCA dimensionality reduction 323 // Perform PCA dimensionality reduction
openbr/plugins/slidingwindow.cpp
@@ -42,15 +42,15 @@ class SlidingWindowTransform : public MetaTransform @@ -42,15 +42,15 @@ class SlidingWindowTransform : public MetaTransform
42 { 42 {
43 Q_OBJECT 43 Q_OBJECT
44 Q_PROPERTY(br::Transform *transform READ get_transform WRITE set_transform RESET reset_transform STORED false) 44 Q_PROPERTY(br::Transform *transform READ get_transform WRITE set_transform RESET reset_transform STORED false)
45 - Q_PROPERTY(int stepSize READ get_stepSize WRITE set_stepSize RESET reset_stepSize STORED false)  
46 - Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false)  
47 Q_PROPERTY(int windowWidth READ get_windowWidth WRITE set_windowWidth RESET reset_windowWidth STORED false) 45 Q_PROPERTY(int windowWidth READ get_windowWidth WRITE set_windowWidth RESET reset_windowWidth STORED false)
  46 + Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false)
48 Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) 47 Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false)
  48 + Q_PROPERTY(float stepFraction READ get_stepFraction WRITE set_stepFraction RESET reset_stepFraction STORED false)
49 BR_PROPERTY(br::Transform *, transform, NULL) 49 BR_PROPERTY(br::Transform *, transform, NULL)
50 - BR_PROPERTY(int, stepSize, 1)  
51 - BR_PROPERTY(bool, takeFirst, false)  
52 BR_PROPERTY(int, windowWidth, 24) 50 BR_PROPERTY(int, windowWidth, 24)
  51 + BR_PROPERTY(bool, takeFirst, false)
53 BR_PROPERTY(float, threshold, 0) 52 BR_PROPERTY(float, threshold, 0)
  53 + BR_PROPERTY(float, stepFraction, 0.25)
54 54
55 private: 55 private:
56 int windowHeight; 56 int windowHeight;
@@ -66,6 +66,19 @@ private: @@ -66,6 +66,19 @@ private:
66 } 66 }
67 } 67 }
68 68
  69 + void store(QDataStream &stream) const
  70 + {
  71 + transform->store(stream);
  72 + stream << windowHeight;
  73 + }
  74 +
  75 + void load(QDataStream &stream)
  76 + {
  77 + transform->load(stream);
  78 + stream >> windowHeight;
  79 + }
  80 +
  81 +protected: // Let IntegralSlidingWindowTransform access this
69 void project(const Template &src, Template &dst) const 82 void project(const Template &src, Template &dst) const
70 { 83 {
71 (void)src;(void)dst;qFatal("don't do that"); 84 (void)src;(void)dst;qFatal("don't do that");
@@ -100,21 +113,28 @@ private: @@ -100,21 +113,28 @@ private:
100 } 113 }
101 } 114 }
102 } 115 }
  116 +};
103 117
104 - void store(QDataStream &stream) const  
105 - {  
106 - transform->store(stream);  
107 - stream << windowHeight;  
108 - } 118 +BR_REGISTER(Transform, SlidingWindowTransform)
109 119
110 - void load(QDataStream &stream) 120 +/*!
  121 + * \ingroup transforms
  122 + * \brief Overloads SlidingWindowTransform for integral images that should be
  123 + * sampled at multiple scales.
  124 + * \author Josh Klontz \cite jklontz
  125 + */
  126 +class IntegralSlidingWindowTransform : public SlidingWindowTransform
  127 +{
  128 + Q_OBJECT
  129 +
  130 + void project(const Template &src, Template &dst) const
111 { 131 {
112 - transform->load(stream);  
113 - stream >> windowHeight; 132 + // TODO: call SlidingWindowTransform::project on multiple scales
  133 + SlidingWindowTransform::project(src, dst);
114 } 134 }
115 }; 135 };
116 136
117 -BR_REGISTER(Transform, SlidingWindowTransform) 137 +BR_REGISTER(Transform, IntegralSlidingWindowTransform)
118 138
119 static TemplateList cropTrainingSamples(const TemplateList &data, const float aspectRatio, const int minSize = 32, const float maxOverlap = 0.5, const int negToPosRatio = 1) 139 static TemplateList cropTrainingSamples(const TemplateList &data, const float aspectRatio, const int minSize = 32, const float maxOverlap = 0.5, const int negToPosRatio = 1)
120 { 140 {
scripts/pedestrianBaselineLBP.sh
@@ -13,7 +13,7 @@ fi @@ -13,7 +13,7 @@ fi
13 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" 13 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"
14 14
15 # Josh's new algorithm (in progress) 15 # Josh's new algorithm (in progress)
16 -# ALG2="Open+Cvt(Gray)+Detector(Gradient+Bin(0,360,9,true)+Merge+Integral+SlidingWindow(Identity))" 16 +# 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)))"
17 17
18 br -useGui 0 \ 18 br -useGui 0 \
19 -algorithm "${ALG}" \ 19 -algorithm "${ALG}" \