Reputation: 153
I am using OpenCV reshape function in order to reshape Mat of 25 rows and 1 column (so we have 25 data values) into Mat of 5 rows and 5 columns.
data = mu.reshape(5, 5);
When I look at my data variable in debugger, it has 5 rows but 1 column. If I print data at row(0) and col(0) it outputs all five values. So basically each row at col(0) contains 5 values.
My desired result is to get 5 rows and 5 columns where on each (row,col) will be one value.
Thank you in advance for your help.
Upvotes: 5
Views: 8972
Reputation: 19041
You seem to have misinterpreted the meaning of arguments of the reshape()
function.
According to the documentation the signature is
Mat Mat::reshape(int cn, int rows=0) const
With the following meaning of the arguments:
Note that the number of columns is implicit -- it's calculated from the existing matrix properties and the two parameters.
According to this, the code
data = mu.reshape(5, 5);
creates a 5-channel matrix of 5 rows and 1 column.
In order to reshape you matrix to a single channel 5x5 matrix, you have to do the following:
data = mu.reshape(1, 5);
Alternately, since the input matrix is already single channel, you can also use
data = mu.reshape(0, 5);
Upvotes: 8