Commit 19a3de11ddb8d8cade6b92e30f7090c803c99711
1 parent
acb45104
implemented KNSTransform
Showing
2 changed files
with
48 additions
and
2 deletions
openbr/plugins/algorithms.cpp
| @@ -50,7 +50,7 @@ class AlgorithmsInitializer : public Initializer | @@ -50,7 +50,7 @@ class AlgorithmsInitializer : public Initializer | ||
| 50 | Globals->abbreviations.insert("SmallSIFT", "Open+LimitSize(512)+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); | 50 | Globals->abbreviations.insert("SmallSIFT", "Open+LimitSize(512)+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); |
| 51 | Globals->abbreviations.insert("SmallSURF", "Open+LimitSize(512)+KeyPointDetector(SURF)+KeyPointDescriptor(SURF):KeyPointMatcher(BruteForce)"); | 51 | Globals->abbreviations.insert("SmallSURF", "Open+LimitSize(512)+KeyPointDetector(SURF)+KeyPointDescriptor(SURF):KeyPointMatcher(BruteForce)"); |
| 52 | Globals->abbreviations.insert("ColorHist", "Open+LimitSize(512)!EnsureChannels(3)+SplitChannels+Hist(256,0,8)+Cat+Normalize(L1):L2"); | 52 | Globals->abbreviations.insert("ColorHist", "Open+LimitSize(512)!EnsureChannels(3)+SplitChannels+Hist(256,0,8)+Cat+Normalize(L1):L2"); |
| 53 | - Globals->abbreviations.insert("ImageClassification", "Open+CropSquare+LimitSize(256)+Cvt(Gray)+Gradient+Bin(0,360,9,true)+Merge+Integral+RecursiveIntegralSampler(4,2,8,Singleton(KMeans(1024)[fraction=0.5]))+Cat+CvtFloat+Hist(1024):Dist(L1)"); | 53 | + Globals->abbreviations.insert("ImageClassification", "Open+CropSquare+LimitSize(256)+Cvt(Gray)+Gradient+Bin(0,360,9,true)+Merge+Integral+RecursiveIntegralSampler(4,2,8,Singleton(KMeans(1024)[fraction=0.5]))+Cat+CvtFloat+Hist(1024)+KNS(5,Dist(L1))"); |
| 54 | 54 | ||
| 55 | // Hash | 55 | // Hash |
| 56 | Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); | 56 | Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); |
openbr/plugins/cluster.cpp
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | #include <opencv2/flann/flann.hpp> | 17 | #include <opencv2/flann/flann.hpp> |
| 18 | 18 | ||
| 19 | #include "openbr_internal.h" | 19 | #include "openbr_internal.h" |
| 20 | +#include "openbr/core/common.h" | ||
| 20 | #include "openbr/core/opencvutils.h" | 21 | #include "openbr/core/opencvutils.h" |
| 21 | 22 | ||
| 22 | using namespace cv; | 23 | using namespace cv; |
| @@ -76,6 +77,51 @@ class KMeansTransform : public Transform | @@ -76,6 +77,51 @@ class KMeansTransform : public Transform | ||
| 76 | 77 | ||
| 77 | BR_REGISTER(Transform, KMeansTransform) | 78 | BR_REGISTER(Transform, KMeansTransform) |
| 78 | 79 | ||
| 79 | -} | 80 | +/*! |
| 81 | + * \ingroup transforms | ||
| 82 | + * \brief K nearest subjects. | ||
| 83 | + * \author Josh Klontz \cite jklontz | ||
| 84 | + */ | ||
| 85 | +class KNSTransform : public Transform | ||
| 86 | +{ | ||
| 87 | + Q_OBJECT | ||
| 88 | + Q_PROPERTY(int k READ get_k WRITE set_k RESET reset_k STORED false) | ||
| 89 | + Q_PROPERTY(br::Distance *distance READ get_distance WRITE set_distance RESET reset_distance STORED false) | ||
| 90 | + BR_PROPERTY(int, k, 1) | ||
| 91 | + BR_PROPERTY(br::Distance*, distance, NULL) | ||
| 92 | + | ||
| 93 | + TemplateList gallery; | ||
| 94 | + | ||
| 95 | + void train(const TemplateList &data) | ||
| 96 | + { | ||
| 97 | + gallery = data; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + void project(const Template &src, Template &dst) const | ||
| 101 | + { | ||
| 102 | + const QList< QPair<float, int> > sortedScores = Common::Sort(distance->compare(gallery, src), true); | ||
| 103 | + QSet<QString> subjects; | ||
| 104 | + int i = 0; | ||
| 105 | + while ((subjects.size() < k) && (i < sortedScores.size())) { | ||
| 106 | + subjects.insert(gallery[sortedScores[i].second].file.subject()); | ||
| 107 | + i++; | ||
| 108 | + } | ||
| 109 | + dst.file.set("KNS", QStringList(subjects.toList()).join(", ")); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + void store(QDataStream &stream) const | ||
| 113 | + { | ||
| 114 | + stream << gallery; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + void load(QDataStream &stream) | ||
| 118 | + { | ||
| 119 | + stream >> gallery; | ||
| 120 | + } | ||
| 121 | +}; | ||
| 122 | + | ||
| 123 | +BR_REGISTER(Transform, KNSTransform) | ||
| 124 | + | ||
| 125 | +} // namespace br | ||
| 80 | 126 | ||
| 81 | #include "cluster.moc" | 127 | #include "cluster.moc" |