using namespace cv;
using namespace std;
int main()
{
{
auto rtrees = cv::ml::RTrees::create();
rtrees->setMaxDepth(10);
rtrees->setMinSampleCount(2);
rtrees->setRegressionAccuracy(0);
rtrees->setUseSurrogates(false);
rtrees->setMaxCategories(16);
rtrees->setPriors(cv::Mat());
rtrees->setCalculateVarImportance(false);
rtrees->setActiveVarCount(0);
rtrees->setTermCriteria({ cv::TermCriteria::MAX_ITER, 100, 0 });
// Some dummy stuff here...
Mat1f feat(1, 5, 0.f);
Mat1f labels = (Mat1f(1, 5) << 1, 0, 1, 0, 1);
rtrees->train(feat, cv::ml::ROW_SAMPLE, labels);
rtrees->write(cv::FileStorage("smoke_classifier.xml",
cv::FileStorage::WRITE));
}
{
auto rtrees2 = cv::ml::RTrees::create();
cv::FileStorage read("smoke_classifier.xml", cv::FileStorage::READ);
rtrees2->read(read.root());
int a = rtrees2->getMinSampleCount();
}
return 0;
}
Write and read opencv3.0 ml files(random forest)
最新推荐文章于 2021-06-06 15:57:59 发布