mat.reshape not working
Hello I have a matrix M 3x3
I use reshape(0,9) so the M.at(0,1) should be the 4th element but it becomes the 2nd element. Help please. If i am wrong then please tell me how do i convert a 2D matrix into a 1D column vector.
EDIT: I dunno how to show the code. Its too big
My matrix is 92 x 112. some of the data below.
-40 -39
-44
....
In matlab if i reshape it becomes
-40
-44
...
-39
-39 becomes the 93rd element. In opencv I reshape it becomes
-40
-39
....
-39 becomes the SECOND element and i dunno where the -44 goes to. I used M.reshape(0,92*112). Matlab is giving me the right answer
Here is the short piece of code that I have
cout << Im.at<float>(0,0) << endl;
cout << Im.at<float>(0,1) << endl;
waitKey(0);
// Reshape to column vector -- Wrong
Mat temp;
Im.reshape(0, 92*112).copyTo(temp);
cout << temp.at<float>(0,0) << endl;
cout << temp.at<float>(1,0) << endl;
What I am getting above is that the elements in (0,0) and (0,1) are equal to (0,0) and (1,0) after being reshaped. Im(0,1) should be equal to temp(113,0) or temp(93,0) but I am not getting such values. Is there another function to reshape a 2D Mat ?
EDIT: Okay it seems like my understanding of the reshape function was totally wrong. Thanks again berak. I had thought OpenCV would go 'down' the array but it seems like OpenCV would move from top left to bottom right
please show us your code.
I have tried it and it works for small matrices but not big ones. is there another function that I can try
be extra careful, when moving between opencv/c++ and matlab. again, there's a lot of assumptions: