----OpenCV的输出方法
利用randu()函数产生的随机值填充矩阵:
randu(矩阵, 随机值的下限,随机值的上限);
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat a = Mat(2, 2, CV_8UC3);
randu(a, Scalar::all(0), Scalar::all(255));
cout << "a(OpenCV默认风格) = " << a << ";" << endl;
return 0;
}
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat a = Mat(2, 2, CV_8UC3);
randu(a, Scalar::all(0), Scalar::all(255));
cout << "a(Python风格) = " << format(a, Formatter::FMT_PYTHON) << ";" << endl;
return 0;
}
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat a = Mat(2, 2, CV_8UC3);
randu(a, Scalar::all(0), Scalar::all(255));
cout << "a(逗号分隔风格) = " << format(a, Formatter::FMT_CSV) << ";" << endl;
return 0;
}
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat a = Mat(2, 2, CV_8UC3);
randu(a, Scalar::all(0), Scalar::all(255));
cout << "a(Numpy风格) = " << format(a, Formatter::FMT_NUMPY) << ";" << endl;
return 0;
}
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat a = Mat(2, 2, CV_8UC3);
randu(a, Scalar::all(0), Scalar::all(255));
cout << "a(C语言风格) = " << format(a, Formatter::FMT_C) << ";" << endl;
return 0;
}
#include
#include
using namespace std;
using namespace cv;
int main()
{
Point2f p(6, 2);
cout << "[二维点]p = " << p << ";\n" << endl;
return 0;
}
#include
#include
using namespace std;
using namespace cv;
int main()
{
Point3f p(6, 2, 1);
cout << "[三维点]p = " << p << ";\n" << endl;
return 0;
}
#include
#include
using namespace std;
using namespace cv;
int main()
{
vector<float> v;
v.push_back(3);
v.push_back(5);
v.push_back(7);
cout << "[基于Mat的vector]shortvec = " << Mat(v) << ";\n" << endl;
return 0;
}
#include
#include
using namespace std;
using namespace cv;
int main()
{
vector<Point2f> points(5);
for (size_t i = 0; i < points.size(); ++i)
points[i] = Point2f((float)(i * 5), (float)(i % 7));
cout << "[二维点向量]points = " << points << ";";
return 0;
}