使用 Ferns 描述符训练后保存 opencv 描述符匹配器

发布于 2024-12-11 09:16:25 字数 1672 浏览 0 评论 0原文

我正在研究图像识别应用程序,并尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春夜浅 2024-12-18 09:16:25

我想我发现了问题。我查看了源文件,实际保存分类器的行被注释掉了。

void FernDescriptorMatcher::write( FileStorage& fs ) const
{
    fs << "nclasses" << params.nclasses;
    fs << "patchSize" << params.patchSize;
    fs << "signatureSize" << params.signatureSize;
    fs << "nstructs" << params.nstructs;
    fs << "structSize" << params.structSize;
    fs << "nviews" << params.nviews;
    fs << "compressionMethod" << params.compressionMethod;

//    classifier->write(fs);
}

以下是源文件的 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.

void FernDescriptorMatcher::write( FileStorage& fs ) const
{
    fs << "nclasses" << params.nclasses;
    fs << "patchSize" << params.patchSize;
    fs << "signatureSize" << params.signatureSize;
    fs << "nstructs" << params.nstructs;
    fs << "structSize" << params.structSize;
    fs << "nviews" << params.nviews;
    fs << "compressionMethod" << params.compressionMethod;

//    classifier->write(fs);
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文