Mat类的输出格式

从前面的例程中, 可以看到 Mat 类重载了<<操作符, 可以方便得使用流操作来输出矩阵的内容。默认情况下输出的格式是类似 Matlab 中矩阵的输出格式。除了默认格式,Mat 也支持其他的输出格式。代码如下:

首先创建一个矩阵,并用随机数填充。填充的范围由 randu()函数的第二个参数和第三个参数确定,下面代码是介于 0 到 255 之间。

Mat R = Mat(3, 2, CV_8UC3);
randu(R, Scalar::all(0), Scalar::all(255));

默认格式输出的代码如下:
cout << "R (default) = " << endl << R << endl << endl;

Python 格式输出的代码如下:
cout << "R (python)  = " << endl << format(R,"python") << endl

以逗号分割的输出的代码如下:
cout << "R (csv)     = " << endl << format(R,"csv"   ) << endl
<< endl;

除了 Mat 对象可以使用<<符号输出,其他的很多类型也支持<<输出。
二维点:

Point2f P(5, 1);
cout << "Point (2D) = " << P << endl << endl;

三维点:
Point3f P3f(2, 6, 7);
cout << "Point (3D) = " << P3f << endl << endl;

原文地址:https://www.cnblogs.com/gary-guo/p/6559350.html