目录

1、OpenCV默认风格

2、Python风格

3、CSV逗号分隔风格

4、numpy风格

5、C语言风格

OpenCV提供了不同风格的格式化输出方法。为了方便演示,首先用raandu()函数产生随机数来填充Mat矩阵,需要给定一个上限和一个下限来确保随机数在期望的范围内:

    Mat r(3, 4, CV_8UC2);
    randu(r, Scalar::all(0), Scalar::all(255));

初始化完r矩阵,下面对输出风格进行讲解。

1、OpenCV默认风格

代码:

cout << " OpenCV默认风格:" << r << endl;

输出:

 OpenCV默认风格:[ 91,   2,  79, 179,  52, 205, 236,   8;
        181, 239,  26, 248, 207, 218,  45, 183;
        158, 101, 102,  18, 118,  68, 210, 139]

2、Python风格

代码:

cout << "Python风格:" << format(r, Formatter::FMT_PYTHON) << endl;

输出:

Python风格:[[[ 91,   2], [ 79, 179], [ 52, 205], [236,   8]],
       [[181, 239], [ 26, 248], [207, 218], [ 45, 183]],
       [[158, 101], [102,  18], [118,  68], [210, 139]]]

3、CSV逗号分隔风格

代码:

cout << "CSV风格:" << format(r, Formatter::FMT_CSV) << endl;

输出:

CSV风格: 91,   2,  79, 179,  52, 205, 236,   8
       181, 239,  26, 248, 207, 218,  45, 183
       158, 101, 102,  18, 118,  68, 210, 139

4、numpy风格

代码:

cout << "numpy风格:" << format(r, Formatter::FMT_NUMPY) << endl;

输出:

numpy风格:array([[[ 91,   2], [ 79, 179], [ 52, 205], [236,   8]],
       [[181, 239], [ 26, 248], [207, 218], [ 45, 183]],
       [[158, 101], [102,  18], [118,  68], [210, 139]]], dtype=’uint8′)

5、C语言风格

代码:

cout << "C语言风格:" << format(r, Formatter::FMT_C) << endl;

输出:

C语言风格:{ 91,   2,  79, 179,  52, 205, 236,   8,
       181, 239,  26, 248, 207, 218,  45, 183,
       158, 101, 102,  18, 118,  68, 210, 139}

 

 

 

 

 

本文地址:https://blog.csdn.net/xddwz/article/details/110439006