格式化输出风格: OpenCV, matlab, python, numpy, csv 和 C 风格
可输出的类型:矩阵、点(二维、三维)、图、容器
#include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { //单位矩阵,主对角线是1 Mat I = Mat::eye(4, 4, CV_64F); I.at<double>(1,1) = CV_PI;//第2行2列的值赋值为PI cout << "I = " << I << ";" << endl << endl; //图 Mat r = Mat(10, 3, CV_8UC3);//10*3的3通道矩阵 randu(r, Scalar::all(0), Scalar::all(255));//元素被赋值[0,255)随机值 cout << "默认风格= " << r << ";" << endl << endl; cout << "matlab风格= " << format(r, Formatter::FMT_MATLAB) << ";" << endl << endl; cout << "python风格= " << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl; cout << "numpy风格= " << format(r, Formatter::FMT_NUMPY) << ";" << endl << endl; cout << "csv风格= " << format(r, Formatter::FMT_CSV) << ";" << endl << endl; cout << "c风格= " << format(r, Formatter::FMT_C) << ";" << endl << endl; //二维点 Point2f p(5, 1); cout << "p = " << p << ";" << endl; //二维点对象的容器,20个点 vector<Point2f> points(20); for (size_t i = 0; i < points.size(); ++i) points[i] = Point2f((float)(i * 5), (float)(i % 7));//横坐标是5的倍数,纵坐标是7的余数 cout << "points = " << points << ";" << endl; //浮点型对象的容器,元素是1,2,3 vector<float> v; v.push_back(1); v.push_back(2); v.push_back(3); cout << "shortvec = " << Mat(v) << endl; return 0; }