2016-06-07 53 views
0

我试图按照this代码来实现BoF。尤其是这样的代码:OpenCV,由BOWKMeansTrainer获得的词汇矩阵

//featuresUnclustered contains all the feature descriptors of all images 
//Construct BOWKMeansTrainer 
//the number of bags 
int dictionarySize=200; 
//define Term Criteria 
TermCriteria tc(CV_TERMCRIT_ITER,100,0.001); 
//retries number 
int retries=1; 
//necessary flags 
int flags=KMEANS_PP_CENTERS; 
//Create the BoW (or BoF) trainer 
BOWKMeansTrainer bowTrainer(dictionarySize,tc,retries,flags); 
//cluster the feature vectors 
cout<<"starting k-means..."<<endl; 
Mat dictionary=bowTrainer.cluster(featuresUnclustered);  
//store the vocabulary 
FileStorage fs("dictionary.yml", FileStorage::WRITE); 
fs << "vocabulary" << dictionary; 
fs.release(); 

我获得dictionary.yaml文件的格式为:

%YAML:1.0 
vocabulary: !!opencv-matrix 
    rows: 200 
    cols: 128 
    dt: f 
    data: [ 8.19999981e+00, 1.20000005e+00, 1., 24., 5.82000008e+01, 
    ... 
    ] 

现在,我的问题是:每一行代表一个质​​心(我们有200个重心,由dictionarySize给出)并且由于SIFT的描述符大小是128位,所以每个质心具有相同的维度。那是对的吗?

回答

1

的每一行代表一个质​​心(和我们有200点的质心,由dictionarySize给出),并且由于SIFT的描述符大小是128位,每个质心具有相同的尺寸。那是对的吗?

是的,正确的。

那么,SIFT有128个值(不是)。在OpenCV中,每个值是float,即32位。但是,每个质心都有128个值。


的k均值的KdictionarySize)是质心的数量。每个质心具有相同的维度N您使用的功能,所以128 SIFT。

该字典将是一个矩阵K x N,在这种情况下,200 X 128


记住弓直方图(这是使用字典计算的全局描述符)将有K值。

+0

哎呀,我的错!如果我们讨论的是二进制描述符,就像ORB一样;) – justHelloWorld

+0

我的意思是,假设二进制描述符有128个维度(以及128位)。只是在说'。 – justHelloWorld

+0

是的,没问题; D很高兴帮助! – Miki