In OpenCV 3.1, it's either broken or I'm using it wrong. Can anyone either tell me what I'm doing wrong or confirm that it's broken?
My code:
cv::FileStorage fsWrite("my_tree", cv::FileStorage::WRITE + cv::FileStorage::MEMORY + FileStorage::FORMAT_XML);
Ptr<cv::ml::Rtrees> model;
[code to train model]
model->write(fsWrite);
std::string modelString = fsWrite.releaseAndGetString(); // produces proper-looking string with xml in it
Ptr<cv::ml::RTrees> resultModel = Algorithm::read<ml::RTrees>(fsWrite.getFirstTopLevelNode());
resultModel ends up having a null contained Rtrees.
This is what modelString looks like:
<?xml version="1.0"?>
<opencv_storage>
<is_classifier>0</is_classifier>
<var_all>13</var_all>
<var_count>12</var_count>
<ord_var_count>13</ord_var_count>
<cat_var_count>0</cat_var_count>
<training_params>
<use_surrogates>0</use_surrogates>
<max_categories>10</max_categories>
<regression_accuracy>9.9999997764825821e-03</regression_accuracy>
<max_depth>25</max_depth>
<min_sample_count>10</min_sample_count>
<cross_validation_folds>0</cross_validation_folds>
<nactive_vars>4</nactive_vars></training_params>
<global_var_idx>1</global_var_idx>
<var_idx>
0 1 2 3 4 5 6 7 8 9 10 11</var_idx>
<var_type>
0 0 0 0 0 0 0 0 0 0 0 0 0</var_type>
<cat_ofs>
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</cat_ofs>
<missing_subst>
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.</missing_subst>
<oob_error>0.</oob_error>
<ntrees>1</ntrees>
<trees>
<_>
<nodes>
<_>
<depth>0</depth>
<value>2.7725000000000000e+00</value>
<splits>
<_><var>7</var>
<quality>1.2565179687500000e+04</quality>
<le>5.8210000991821289e+00</le></_></splits></_>
<_>
<depth>1</depth>
<value>2.9880095923261392e+00</value>
<splits>
<_><var>7</var>
<quality>1.1172947265625000e+04</quality>
<le>1.2557047605514526e+00</le></_></splits></_>
<_>
<depth>2</depth>
<value>3.</value></_>
<_>
<depth>2</depth>
<value>2.7368421052631580e+00</value>
<splits>
<_><var>3</var>
<quality>438.</quality>
<le>-1.2632201194763184e+01</le></_></splits></_>
<_>
<depth>3</depth>
<value>3.</value></_>
<_>
<depth>3</depth>
<value>2.</value></_>
<_>
<depth>1</depth>
<value>2.</value></_></nodes></_></trees>
</opencv_storage>