Ask Your Question
0

Question of Reshaping a matrix

asked Jan 20 '18

Weifa Gan gravatar image

updated Jan 20 '18

I am a new learner for opencv. When I want to reshape m33f to m91f, it will be error due to no "typedef Matx<float,9,1> Matx91f". Then what shoud i do ?pleace help me to deal with the problem. Thank you in advance. image description image description.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Jan 20 '18

phillity gravatar image

updated Jan 20 '18

Using Matx:

#include "opencv2/core.hpp"

#include <iostream>

using namespace cv;
using namespace std;


int main(int argc, char *argv[])
{
    //create and fill a 3x3 matrix with normally distributed random numbers with mean of 1 and standard deviation of 3
    Matx33f m33f = Matx33f::randn(1, 3);
    cout << "m33f" << m33f << endl << endl;

    //create a 9x1 matrix, fill it previous 3x3 matrix reshaped to a 9x1 matrix
    Matx<float, 9, 1> m91f = m33f.reshape<9, 1>();
    cout << "m91f" << m91f << endl << endl;

    return 0;
}

Alternatively, using Mat:

#include "opencv2/core.hpp"

#include <iostream>

using namespace cv;
using namespace std;


int main(int argc, char *argv[])
{
    //create a 3x3 matrix with floating point datatype
    Mat m33f = Mat(3, 3, CV_32F);
    //fill matrix with normally distributed random numbers with mean of 1 and standard deviation of 3
    randn(m33f, 1, 3);
    cout << "m33f" << m33f << endl << endl;

    //create a 9x1 matrix, fill it previous 3x3 matrix reshaped to a 9x1 matrix
    //reshape has 0 for first argument meaning no change in number of channels and 9 for second argument meaning 9 rows 
    Mat m91f = m33f.reshape(0, 9);
    cout << "m91f" << m91f << endl << endl;

    return 0;
}
Preview: (hide)

Comments

1

Great! Thanks your help.

Weifa Gan gravatar imageWeifa Gan (Jan 20 '18)edit

Question Tools

1 follower

Stats

Asked: Jan 20 '18

Seen: 263 times

Last updated: Jan 19 '18