随机树CvRTrees持久性问题opencv [英] Random tree CvRTrees persistence issue opencv

查看:130
本文介绍了随机树CvRTrees持久性问题opencv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Opencv实现随机树分类器。我成功地用opencv实现了它,并且可以正常工作。

I'm trying to implement a random tree classifier using Opencv. I succeed implementing it with opencv and it is working.

然后,我决定将训练部分与分类部分分开。
的想法是保存经过训练的森林,并在您想要对它们进行分类时将其加载回去。

Then I decided to separate the training part from the classification part. The idea is to save the trained forest and load it back when you want to classify something.

我尝试了两种不同的方法:

I tried in two different way:


  1. 使用超类 CvStatModel
  2. 写入和读取方法

  3. 使用超类 CvStatModel 存储和加载方法

  1. using write and read methods of the super class CvStatModel
  2. using store and load methods of the super class CvStatModel

但是较旧的实现没有将树保存到文件的结果是不同的,甚至更糟。

But results form the older implementation that did not save trees to file are different and worst.

下面的代码是第二点的实现:

Following code is the implementation of 2nd point:

要存储它:

for (unsigned i=0; i<scenes.size(); ++i) {
      char class_fname[50];
      char output[100];
      sprintf(class_fname,"class_%d.xml",i);
      sprintf(output,"class_%d",i);
      //classifiers[i]->save(class_fname,output);
      classifiers[i]->save(class_fname);
    }

要重新加载它们:

 for (unsigned int i = 0; i<CLUSTERING_N_CENTERS;i++){
    char class_fname[50];
    char output[100];
    sprintf(class_fname,"class_%d.xml",i);
    sprintf(output,"class_%d",i);
    classifiers[i] = new CvRTrees();
    //classifiers[i]->load(class_fname,output);
    classifiers[i]->load(class_fname);
  }

我正在使用opencv 2.4.6
是否有人建议

I'm using opencv 2.4.6 Does anyone have suggestions on this code?

推荐答案

由于文件错误而导致错误!

It was an error due to file mistake!

因此持久性正在发挥作用!

So the persistency is working!

但是如果有人需要实现,我将其保留为示例!

But I leave the post as sample if someone needs to implement it!

这篇关于随机树CvRTrees持久性问题opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆