How to use BOW file for testing
I trained the data using BOG with SVM , i trained it , now i just want to open it through xml
, i don't want to train it again and again on every run ,
I trained the svm and now loading it using its loading function
CvSVM svm;
svm.load( "trainsvm.xml" );
But how to do the same with vocabulary file which i use for clustering using BOG algorithm , below is my code , which is training the data , but i want to open it now like svm
for (i = files.begin(); i != files.end(); ++i)
{
Mat row_img = imread( Dir +*i, 0 );
detector.detect( row_img, keypoints);
extractor->compute( row_img, keypoints, descriptors_1);
descriptors_1.reshape(1,1);
bow.add(descriptors_1);
++count;
}
cout<<"CLUSTERING";
Mat vocabulary = bow.cluster();
dextract.setVocabulary(vocabulary);
Mat training_mat(num_img , dictionarySize,CV_32FC1);
Mat labels(num_img,1,CV_32FC1);
This is clustering the data , now i don't want to run it again and again because it takes too much time , when it trained once , i just want to use it , so that i can speed up my program
Edit :
I used this approach in the above code and got error :
FileStorage fs;
fs.open("Vocabulary.xml", FileStorage::WRITE);
Mat vocabulary = bow.cluster();
fs["Vocabulary"]>>vocabulary ;
dextract.setVocabulary(vocabulary);
fs.release();
cv::Mat training_mat(num_img , dictionarySize,CV_32FC1);
cv::Mat labels(num_img,1,CV_32FC1);
CvSVM svm;
svm.load( "trainsvm.xml" );
Error :