00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVBRIEFDetector>
00026 #include <QVIndexPair>
00027 QVector <QVIndexPair> getImageFeaturedSortedPairs( const QVBRIEFDetector &briefDetector,
00028 const QVector<unsigned int> &sourceFrameBRIEFDescriptors,
00029 const QVector<unsigned int> &destFrameBRIEFDescriptors,
00030 const int maxBinaryDistance = 256,
00031 const int maxFeatures = std::numeric_limits<int>::max())
00032 {
00033 const int sourceCount = sourceFrameBRIEFDescriptors.count() / briefDetector.getDescriptorInts(),
00034 destCount = destFrameBRIEFDescriptors.count() / briefDetector.getDescriptorInts();
00035
00036
00037 const int maxTests = MIN(maxBinaryDistance, briefDetector.getNumTests());
00038
00039
00040 int sortedMatchingsCount = 0;
00041 QVector< QList< QVIndexPair > > matchingsHistogramVector(maxTests);
00042 for(int i = 0; i < MIN(sourceCount, maxFeatures); i++)
00043 for(int j = 0; j < MIN(destCount, maxFeatures); j++)
00044 {
00045 const int distanceBis = briefDetector.distance(sourceFrameBRIEFDescriptors, destFrameBRIEFDescriptors, i, j);
00046
00047 if (distanceBis < maxTests)
00048 {
00049 matchingsHistogramVector [ distanceBis ] << QVIndexPair(i, j);
00050 sortedMatchingsCount++;
00051 }
00052 }
00053
00054
00055 QVector<QVIndexPair> sortedMatchings;
00056 sortedMatchings.reserve(sortedMatchingsCount);
00057 for(int i = 0; i < maxTests; i++)
00058 foreach(QVIndexPair pair, matchingsHistogramVector [ i ])
00059 sortedMatchings << pair;
00060
00061 return sortedMatchings;
00062 }
00063
00064 #include <QFile>
00065 #include <QTextStream>
00066 bool saveBRIEFDescriptorsInLoweSIFTFileFormat(const QString fileName, const QVector<QPointF> features, const QVector<unsigned int> descriptors)
00067 {
00068 const int descriptorInts = descriptors.count() / features.count();
00069
00070 QFile keyFile(fileName);
00071 if (not keyFile.open(QIODevice::WriteOnly | QIODevice::Text))
00072 return false;
00073
00074 QTextStream outFile(&keyFile);
00075
00076 bool cond = false;
00077
00078 outFile << features.count() << " " << (descriptorInts*32) << "\n";
00079 for(int i = 0; i < features.count(); i++)
00080 {
00081
00082 if (cond)
00083 outFile << "\n";
00084
00085 outFile << features[i].y() << " " << features[i].x() << " 1.0 0.0\n";
00086
00087
00088
00089
00090
00091
00092 for (int j = 0, n = 0; j < descriptorInts; j++)
00093 {
00094 const int intIndex = i * descriptorInts + j;
00095 Q_ASSERT(intIndex < descriptors.count());
00096 int tests = descriptors[intIndex];
00097
00098 for(int k = 0; k < 32; k++, n++)
00099 {
00100 outFile << " " << ((tests & 1)?"255":"0");
00101 tests >>= 1;
00102 if (( (n+1) % 20) == 0)
00103 outFile << "\n";
00104 }
00105 }
00106
00107 cond = true;
00108 }
00109 keyFile.close();
00110
00111 return true;
00112 }
00113