使用 Ferns 描述符训练后保存 opencv 描述符匹配器
我正在研究图像识别应用程序,并尝试使用 Ferns 描述符匹配器实现一种方法。
我训练 Ferns 结构并使用下面的代码保存它们:
int main(int argc, char** argv) {
vector<string> trainFilenames;
readTrainFilenames(modelImagesList, imagesDir, trainFilenames);
Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create("FERN", params_filename);
SurfFeatureDetector detector(500);
SurfDescriptorExtractor extractor;
vector<vector<KeyPoint> > allKeypoints;
vector<Mat> allTrainImages;
//TRAIN AND SAVE
for(unsigned int i = 0; i < trainFilenames.size(); i++){
Mat sceneImage;
std::vector<KeyPoint> sceneKeypoints;
sceneImage = imread(trainFilenames.at(i), CV_LOAD_IMAGE_GRAYSCALE );
detector.detect( sceneImage, sceneKeypoints );
allKeypoints.push_back(sceneKeypoints);
allTrainImages.push_back(sceneImage);
}
std::string sceneImageData = "sceneImagedatamodel.xml";
FileStorage fs(sceneImageData, FileStorage::WRITE);
descriptorMatcher->add(allTrainImages, allKeypoints);
descriptorMatcher->train();
descriptorMatcher->write(fs);
fs.release();
}
但是,我在输出文件中获得的唯一内容是:
<?xml version="1.0"?>
<opencv_storage>
<nclasses>0</nclasses>
<patchSize>31</patchSize>
<signatureSize>2147483647</signatureSize>
<nstructs>50</nstructs>
<structSize>9</structSize>
<nviews>1000</nviews>
<compressionMethod>0</compressionMethod>
</opencv_storage>
我不是应该将整个结构保存在 xml 文件中吗?
我似乎找不到任何人使用新的 C++ 界面执行此操作。这些方法真的有效吗?如果是这样,你们知道如何让它发挥作用吗?
谢谢。
I am working in a image recognition application and trying to implement a method using the Ferns descriptor matcher.
I training the Ferns structures and saving them using the code below:
int main(int argc, char** argv) {
vector<string> trainFilenames;
readTrainFilenames(modelImagesList, imagesDir, trainFilenames);
Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create("FERN", params_filename);
SurfFeatureDetector detector(500);
SurfDescriptorExtractor extractor;
vector<vector<KeyPoint> > allKeypoints;
vector<Mat> allTrainImages;
//TRAIN AND SAVE
for(unsigned int i = 0; i < trainFilenames.size(); i++){
Mat sceneImage;
std::vector<KeyPoint> sceneKeypoints;
sceneImage = imread(trainFilenames.at(i), CV_LOAD_IMAGE_GRAYSCALE );
detector.detect( sceneImage, sceneKeypoints );
allKeypoints.push_back(sceneKeypoints);
allTrainImages.push_back(sceneImage);
}
std::string sceneImageData = "sceneImagedatamodel.xml";
FileStorage fs(sceneImageData, FileStorage::WRITE);
descriptorMatcher->add(allTrainImages, allKeypoints);
descriptorMatcher->train();
descriptorMatcher->write(fs);
fs.release();
}
However, the only thing I obtain in the output file is this:
<?xml version="1.0"?>
<opencv_storage>
<nclasses>0</nclasses>
<patchSize>31</patchSize>
<signatureSize>2147483647</signatureSize>
<nstructs>50</nstructs>
<structSize>9</structSize>
<nviews>1000</nviews>
<compressionMethod>0</compressionMethod>
</opencv_storage>
Wasn't I supposed to save the entire structure in the xml file?
I can't seem to find any where someone doing this with the new C++ interface. Are these methods really working? If so, do you guys have any idea how to put it to work?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我发现了问题。我查看了源文件,实际保存分类器的行被注释掉了。
以下是源文件的 URL: https: //code.ros.org/svn/opencv/trunk/opencv/modules/features2d/src/matchers.cpp
FernClassifier类实现了一个write()方法
planardetect.cpp
文件。我不知道为什么它被注释掉了。我想你可以取消注释该行并重新编译。I think I found the problem. I had a look at the source file and the line that actually saves the classifier is commented out.
Here is the URL to the source file: https://code.ros.org/svn/opencv/trunk/opencv/modules/features2d/src/matchers.cpp
The FernClassifier class implements a write() method in the
planardetect.cpp
file. I do not know why it is commented out. I guess you could uncomment the line and recompile.