1
我使用支持SVM的BOG训练了数据,我训练了它,现在我只想通过xml
打开它,我不想在每次运行中一次又一次地训练它, 训练SVM和正在利用其加载函数加载它如何在训练后使用聚类文件
CvSVM svm;
svm.load("trainsvm.xml");
但如何做词汇文件一样,我用BOG算法用于集群,下面是我的代码,这是训练数据,但我想打开它现在好像svm
for (i = all_names.begin(); i != all_names.end(); ++i)
{
Dir=((count < files.size()) ? YourImagesDirectory : YourImagesDirectory_2);
Mat row_img = cv::imread(Dir +*i, 0);
detector.detect(row_img, keypoints);
RetainBestKeypoints(keypoints, 20);
extractor->compute(row_img, keypoints, descriptors_1);
descriptors_1.reshape(1,1);
bow.add(descriptors_1);
++count;
}
vector<string>::const_iterator k;
cout<<"CLUSTERING"<<endl;
Mat vocabulary = bow.cluster();
dextract.setVocabulary(vocabulary);
cv::Mat training_mat(num_img , dictionarySize,CV_32FC1);
cv::Mat labels(num_img,1,CV_32FC1);
这是集群数据,现在我不想一次又一次地运行它,因为它需要太多的时间,当它训练一次,我只是想使用它,这样我就可以加快我的程序
我知道FileStorage,但这是技术是不是有用的我的问题,词汇没有存储在它与svm使用它,我需要一个完整的解释答案 – Rocket
Mat词汇表= bow.cluster();从这行代码看来,您的词汇表是Mat对象的一个实例,因此可以使用FileStorage将其写入磁盘。也许你应该更详细地解释你的问题,并说明为什么这种技术对你的问题没有用。 – guneykayim
你想提供这样的'FileStorage fs; fs.open(“Vocalbury.xml”,FileStorage :: WRITE); Mat词汇表= bow.cluster(); fs [“Vocalbury”] >>词汇; dextract.setVocabulary(词汇); Mat training_mat(num_img,dictionarySize,CV_32FC1); Mat标签(num_img,1,CV_32FC1);' – Rocket