我正在使用C ++。我想在不同的行上打印Mat对象的矩阵,如下所示:
我现在所拥有的是
cout << m <<endl <<endl;
有人可以帮忙吗?
答案 0 :(得分:3)
在这种情况下(参考注释),您需要按行打印矩阵。使用m.row()和m.at()。假设您有3x3矩阵,如图中所示:
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;
}
答案 1 :(得分:2)
如果您打算将其打印到命令行,我建议您查看 OpenCV: Matrix Iteration
如果您经常这样做,虽然不是很推荐,但您可以派生自己的Matrix类并覆盖<<
运算符,以您希望的方式打印它(如上面的链接)