使用opencv通过Filestorage保存时出错

AHF*_*AHF 4 c++ opencv image-processing svm computer-vision

我试图保存BOW算法中的词汇表.以下是我的代码.

FileStorage fs; 
fs.open("Vocabulary.xml", FileStorage::WRITE); 
Mat vocabulary = bow.cluster(); 
fs << vocabulary ;
fs.release();
FileStorage fs2; 
fs2.open("Vocabulary.xml", FileStorage::READ); 
fs2 ["Vocabulary"] >> vocabulary ;
dextract.setVocabulary(vocabulary);

cv::Mat training_mat(num_img , dictionarySize,CV_32FC1);
cv::Mat labels(num_img,1,CV_32FC1);

CvSVM svm;
svm.load( "trainsvm.xml" );
Run Code Online (Sandbox Code Playgroud)

这是我的错误:

OpenCV Error: Unspecified error (No element name has been given) in unknown function , file c:\opencv\2.4.4\build\include\opencv2\core\operations.hpp , line 2908
Run Code Online (Sandbox Code Playgroud)

Mic*_*ica 6

您没有在文件中设置词汇表的名称,请尝试以下操作:

fs << "Vocabulary" << vocabulary ;
Run Code Online (Sandbox Code Playgroud)