使用 opencv 通过文件存储保存时出错

Getting error while saving through Filestorage using opencv

本文关键字:保存 出错 存储 文件 opencv 使用      更新时间:2023-10-16

我正在尝试从 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" );

这是我的错误:

OpenCV Error: Unspecified error (No element name has been given) in unknown function , file c:opencv2.4.4buildincludeopencv2coreoperations.hpp , line 2908

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

fs << "Vocabulary" << vocabulary ;