Issue 1:
System information (version)

Detailed description

While testing turing.py, cv.imshow led to assertion failure in cvShowImage

Assertion is

CV_Assert(dst.data == (uchar*)dst_ptr);

It seems the code is assuming that dst.data points to the window->image bits. Although dst.data equals dst_ptr and the window->image buffer, cv::cvtColor, can trigger a reallocation of the dst.data array.

It looks like it works in cases where the size of the elements of the arrays don't change, but turing.py is converting from a gray scale float32 and cvtColor is converting it to RGB with a float for each value. The orginal buffer from

window->image = SelectObject( window->dc, CreateDIBSection(window->dc, binfo,

DIB_RGB_COLORS, &dst_ptr, 0, 0));

contains RGB with * bits per color.

It might be a problem in cvtColor, since in the end windows probably needs a 8bit RGB value.

This is my first day looking at opencv code, so I'm hoping someone more familiar with the code, has a better idea.

Steps to reproduce

run python sample turing.py

Issue 2:
Open CV 3.1

Windows 10

Visual Studio 2015

This bug is in cv::ml:: RTrees.

I am writing a trained RTrees out using FileStorage, which appears to work correctly. Doing a read() to deserialize causes a crash in In rtrees.cpp, line 335, in the read() method of DTreesImplForRTrees:

oobError = (double)fn["oob_error"];

This happens regardless of whether I am serializing using a MEMORY- or file-based FileStorage object. The FileNode produced by getFirstTopLevelNode() does not appear to contain the expected nodes in it.

Here is code which produces the issue for memory FileStorage:

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());

And here for file-based:

cv::FileStorage fsWrite("D:\\test.xml", cv::FileStorage::WRITE + FileStorage::FORMAT_XML);
m_ptrModel->write(fsWrite);
cv::FileStorage fsRead("D:\\test.xml", FileStorage::READ + FileStorage::FORMAT_XML);
m_ptrModel = cv::Algorithm::read<ml::RTrees>(fsRead.getFirstTopLevelNode());

Here is what the modelString and file that are produced by the write() look 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>

You should be able to duplicate the problem by taking the model string here, sticking it in a file, and simply doing a read() on it, something like:

#include "opencv2\core\core.hpp"
#include "opencv2\ml\ml.hpp"
cv::FileStorage fsRead("D:\\test.xml", FileStorage::READ + FileStorage::FORMAT_XML);
Ptr<cv::ml::RTrees> resultModel = Algorithm::read<ml::RTrees>(fsWrite.getFirstTopLevelNode());