Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 2016-03-24 02:46:02 -0600

Nbb gravatar image

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.

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

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 toto. I used M.reshape(0,92*112)

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)M.reshape(0,92*112). Matlab is giving me the right answer

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(1, 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.

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(1, 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.

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.

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.values. Is there another function to reshape a 2D Mat ?

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