Commit c5f168d6af6b3ee55baf78d5db75b994f8dbfc02

Authored by Josh Klontz
1 parent 1952d826

added more plugins

sdk/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("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat+WordWise(RowWisePCA(8)+RowWiseMeanCenter+Binarize,RowWisePCA):L2"); 53 + Globals->abbreviations.insert("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat+WordWise(RowWisePCA(8)+RowWiseMeanCenter+Binarize,RowWisePCA)+Sentence:SentenceSimilarity");
54 54
55 // Hash 55 // Hash
56 Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); 56 Globals->abbreviations.insert("FileName", "Name+Identity:Identical");
sdk/plugins/sentence.cpp 0 → 100644
  1 +#include <openbr_plugin.h>
  2 +
  3 +using namespace cv;
  4 +
  5 +namespace br
  6 +{
  7 +
  8 +/*!
  9 + * \ingroup transforms
  10 + * \brief Ordered words
  11 + * \author Josh Klontz \cite jklontz
  12 + */
  13 +class SentenceTransform : public UntrainableMetaTransform
  14 +{
  15 + Q_OBJECT
  16 +
  17 + void project(const Template &src, Template &dst) const
  18 + {
  19 + QByteArray sentence;
  20 + QDataStream stream(&sentence, QIODevice::WriteOnly);
  21 + for (int i=0; i<src.size(); i++) {
  22 + const Mat &m = src[i];
  23 + if (!m.data) continue;
  24 + stream << i << m.rows << m.cols;
  25 + stream.writeRawData((const char*)m.data, 4*m.rows*m.cols);
  26 + }
  27 + dst.file = src.file;
  28 + dst.m() = Mat(1, sentence.size(), CV_8UC1, sentence.data()).clone();
  29 + }
  30 +};
  31 +
  32 +BR_REGISTER(Transform, SentenceTransform)
  33 +
  34 +/*!
  35 + * \ingroup distances
  36 + * \brief Distance between sentences
  37 + * \author Josh Klontz \cite jklontz
  38 + */
  39 +class SentenceSimilarityDistance : public Distance
  40 +{
  41 + Q_OBJECT
  42 +
  43 + float compare(const Template &a, const Template &b) const
  44 + {
  45 + const int aSize = a.m().cols;
  46 + const int bSize = b.m().cols;
  47 + uchar *aData = a.m().data;
  48 + uchar *bData = b.m().data;
  49 + const uchar *aEnd = aData + aSize;
  50 + const uchar *bEnd = bData + bSize;
  51 +
  52 + int32_t aWord, bWord, aRows, bRows, aColumns, bColumns;
  53 + aWord = aRows = aColumns = -2;
  54 + bWord = bRows = bColumns = -1;
  55 + float distance = 0;
  56 + int comparisons = 0;
  57 + while ((aData != aEnd) && (bData != bEnd)) {
  58 + if (aWord < bWord) {
  59 + aWord = *reinterpret_cast<int32_t*>(aData);
  60 + aRows = *reinterpret_cast<int32_t*>(aData+4);
  61 + aColumns = *reinterpret_cast<int32_t*>(aData+8);
  62 + aData += 12;
  63 + } else if (bWord < aWord) {
  64 + bWord = *reinterpret_cast<int32_t*>(bData);
  65 + bRows = *reinterpret_cast<int32_t*>(bData+4);
  66 + bColumns = *reinterpret_cast<int32_t*>(bData+8);
  67 + bData += 12;
  68 + } else {
  69 + for (int i=0; i<aRows; i++)
  70 + for (int j=0; j<bRows; j++)
  71 + for (int k=0; k<aColumns; k++)
  72 + distance += *reinterpret_cast<float*>(aData+4*k) * *reinterpret_cast<float*>(bData+4*k);
  73 + comparisons += aRows * bRows;
  74 + }
  75 + }
  76 +
  77 + return comparisons / distance;
  78 + }
  79 +};
  80 +
  81 +BR_REGISTER(Distance, SentenceSimilarityDistance)
  82 +
  83 +} // namespace br
  84 +
  85 +#include "sentence.moc"