00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVVector>
00026 #include <QVKeypoint>
00027 #include <QFile>
00028 #include <QTextStream>
00029 #include <QVSiftFeature>
00030
00031 bool saveSIFTDescriptorsInLoweSIFTFileFormat(const QString &fileName, const QList<QVSiftFeature> &features)
00032 {
00033 QFile file(fileName);
00034 if (not file.open(QIODevice::WriteOnly | QIODevice::Text))
00035 return false;
00036
00037 QTextStream stream(&file);
00038
00039 stream.setRealNumberPrecision(16);
00040
00041 stream << features.count() << " 128\n";
00042 foreach(QVSiftFeature feature, features)
00043 {
00044 stream << feature.keypoint.y() << " "
00045 << feature.keypoint.x() << " "
00046 << feature.keypoint.scale() << " "
00047 << feature.keypoint.orientation();
00048
00049 const QVVector descriptor = 512 * feature.descriptor / feature.descriptor.norm2();
00050
00051 for(int i = 0; i < 128; i++)
00052 {
00053 if ( (i % 20) == 0 )
00054 stream << "\n";
00055 stream << " " << int(descriptor[i]);
00056 }
00057 stream << "\n";
00058 }
00059
00060 file.close();
00061 return true;
00062 }
00063