I am using C++. I want to print the matrix of a Mat object on different lines like this:
What I have right now is
cout << m <<endl <<endl;
Can anyone help with this please?
I am using C++. I want to print the matrix of a Mat object on different lines like this:
What I have right now is
cout << m <<endl <<endl;
Can anyone help with this please?
In this case (referring to the comments) you need to print your matrices row-wise. Make use of m.row() and m.at(). Supposed that you have 3x3 matrices as in the image:
for (int i = 0; i < 3; ++i)
{
Mat row1 = m1.row (i);
Mat row2 = m2.row (i);
Mat row3 = m3.row (i);
// this can be replaced by a loop, I spell it out for the sake of clearness
cout << row1.at(0, 0) << " " << row1.at (0, 1) << " " << row1.at (0, 2) << "\t"
<< row2.at(0, 0) << " " << row2.at (0, 1) << " " << row2.at (0, 2) << "\t"
<< row3.at(0, 0) << " " << row3.at (0, 1) << " " << row3.at (0, 2) << endl;
}
If you are looking to print it to command line, i suggest looking at OpenCV: Matrix Iteration
If you are doing this quite frequently, although not very recommended, you can derive your own Matrix class and override the <<
operator to print it the way you want it to (as in the link above)