Misleading documentation for matrix reshape operation (Bug #1510)


Added by galkin-vv - over 13 years ago. Updated over 12 years ago.


Status:Done Start date:
Priority:Low Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:documentation
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Consider the following code:

1Mat_<Vec3b> matrix_with_3channels;
2//some initialization

and the value returned by call

1Mat mat_reshaped = matrix_with_3channels.reshape(1);

The documentation in source:trunk/opencv/modules/core/doc/basic_structures.rst mention the reshape function for Mat_'s base class Mat with second default parameter

1Mat Mat::reshape(int cn, int rows=0)

and doesn't mention any function specialized in Mat_.

So, according to the docs the call above should set mat_reshaped to matrix with 1 channel (and modified number of columns/rows).

But the source:trunk/opencv/modules/core/include/opencv2/core/core.hpp defines Mat_<> member

1    //! some more overriden methods
2    Mat_ reshape(int _rows) const;

with implementation in source:trunk/opencv/modules/core/include/opencv2/core/mat.hpp
as

1template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::reshape(int _rows) const
2{ return Mat_<_Tp>(Mat::reshape(0,_rows)); }

So really mat_reshaped get matrix with 3 channels and 1 row, so the documentation is very misleading here.


Associated revisions

Revision 8b0d9f4f
Added by Vadim Pisarevsky almost 13 years ago

excluded dangerously overriden Mat_::reshape() method (ticket #1510)

History

Updated by Alexander Shishkov almost 13 years ago

  • Priority changed from High to Normal
  • Target version deleted ()
  • Description changed from Consider the following code: <pre> Mat_<Vec3b> matrix_with_3chann... to Consider the following code: <pre><code class="cpp"> Ma... More

Updated by Alexander Shishkov almost 13 years ago

  • Priority changed from Normal to Low

Updated by Alexander Shishkov almost 13 years ago

  • Target version deleted ()

Updated by Ilya Lysenkov almost 13 years ago

  • Target version set to 2.4.0
  • Assignee set to Ilya Lysenkov

Updated by Ilya Lysenkov almost 13 years ago

  • Assignee deleted (Ilya Lysenkov)

Updated by Vadim Pisarevsky almost 13 years ago

Indeed, Mat_::reshape() looked like a potential problem. I checked OpenCV code and we seem not to use this method. I removed it in SVN, r7974. Let's hope, it will not break a lot of user code.

  • Status changed from Open to Done
  • Assignee set to Vadim Pisarevsky

Updated by Daniel Takacs over 12 years ago

Vadim Pisarevsky wrote:

Indeed, Mat_::reshape() looked like a potential problem. I checked OpenCV code and we seem not to use this method. I removed it in SVN, r7974. Let's hope, it will not break a lot of user code.

Sadly it broke our code...
I think the main problem with cv::Mat_<T>::reshape was not the different arguments, but the lack of the documentation.
It was a nice overload because it returned cv::Mat_<T> and not cv::Mat as the original cv::Mat::reshape.

Also available in: Atom PDF