Question of Reshaping a matrix

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. .

edit retag close merge delete

Sort by ยป oldest newest most voted

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;
}

more

1