这个模块提供特征和特征描述子的通用容器
特征
提供基本的结构和IO来存储`特征点。存储特征点的类:
PointFeature
:存储特征的位置(x,y)
SIOPointFeature
:存储特征的位置、方向和尺度(x,y,s,o)
描述子
提供基本的结构和IO来存储`特征描述子。
template <typename T, std::size_t N> class Descriptor
:存储N个类型是T的值,连续内存
// SIFT like descriptor
using siftDescriptorData Descriptor<float, 128>;
// SURF like descriptor
using surfDescriptorData = Descriptor<float, 64>;
// Binary descriptor (128 bits)
using binaryDescriptor_bitset = Descriptor<std::bitset<128>,1> binaryDescriptor_bitset;
// or using unsigned chars
using binaryDescriptor_uchar = Descriptor<unsigned char, 128/sizeof(unsigned char)>;
特征点集
存储一系列特征及其描述子:
template<typename FeaturesT, typename DescriptorsT> class KeypointSet
// Define SIFT Keypoints:
// Define the SIFT descriptor [128 floating point value]
using Descriptor<float, 128> DescriptorT;
// Use SIFT compatible features (scale, orientation and position)
using FeatureT = SIOPointFeature;
// Describe what a collection of local feature is for a given image:
using FeatsT = std::vector<FeatureT>;
using DescsT = std::vector<DescriptorT>;
// Link features and their descriptors as a collection:
using KeypointSetT = KeypointSet<FeatsT, DescsT>;
//示例
Feats_T vec_feats;
for (int i = 0; i < CARD; ++i)
vec_feats.push_back(Feature_T(i, i*2, i*3, i*4));
//Save them to a file
saveFeatsToFile("tempFeats.feat", vec_feats);
Feats_T vec_feats_read;
loadFeatsFromFile("tempFeats.feat", vec_feats_read);
//vec_feats_read.size();
//vec_feats[i].coords(), .scale(), .orientation()
// Create an input series of descriptor
Descs_T vec_descs;
for (int i = 0; i < CARD; ++i)
{
Desc_T desc;
for (int j = 0; j < DESC_LENGTH; ++j)
desc[j] = i*DESC_LENGTH+j;
vec_descs.emplace_back(desc);
}
saveDescsToFile("tempDescs.desc", vec_descs);
Descs_T vec_descs_read;
loadDescsFromFile("tempDescs.desc", vec_descs_read);
//vec_descs_read.size();
//vec_descs[i][j]
//保存为二进制文件
saveDescsToBinFile("tempDescsBin.desc", vec_descs);
loadDescsFromBinFile("tempDescsBin.desc", vec_descs_read)
还可以通过cereal
把特征描述子保存为json
格式