OpenCV的5种格式化输出方法Mat类型数据

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main()
{
     system("chcp 65001");  //控制台中文支持
     Mat r = Mat(10, 3, CV_8UC3);
     randu(r, Scalar::all(0), Scalar::all(255));  //randu随机矩阵[0, 255]之间

     cout << "r(opencv默认风格) = " << r << ";" << endl << endl;

    // cout << "r(Python风格_openCV2) = " << format(r, "python") << ";" << endl << endl;
    cout << "r(Python风格_openCV3) = " << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl;

    //cout << "r(,分隔风格_openCV2) = " << format(r, "csv") << ";" << endl << endl;
    cout << "r(,分隔风格_openCV3) = " << format(r, Formatter::FMT_CSV) << ";" << endl << endl;

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

    // cout << "r(C语言风格_openCV2) = " << format(r, "c") << ";" << endl << endl;
    cout << "r(C语言风格_openCV3) = " << format(r, Formatter::FMT_C) << ";" << endl << endl;
    return 0;
}

 

0、准备

  system("chcp 65001");  //控制台中文支持
     Mat r = Mat(10, 3, CV_8UC3);
     randu(r, Scalar::all(0), Scalar::all(255));  //randu随机矩阵[0, 255]之间

1、默认风格

 cout << "r(opencv默认风格) = " << r << ";" << endl << endl;

7f4828d6c34e8e1ebc3dfc57ffa371f7de4.jpg

2、

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

3b6bed5a2ff1aa1850f968d0bf3e1706f31.jpg

3、

cout << "r(,分隔风格_openCV2) = " << format(r, "csv") << ";" << endl << endl;
    cout << "r(,分隔风格_openCV3) = " << format(r, Formatter::FMT_CSV) << ";" << endl << endl;

7289e1354b0ac7b64211adac90d84cd218b.jpg

4、

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

a133d7f822ea146ee357cef003db1ab36c6.jpg

5、

 // cout << "r(C语言风格_openCV2) = " << format(r, "c") << ";" << endl << endl;
    cout << "r(C语言风格_openCV3) = " << format(r, Formatter::FMT_C) << ";" << endl << endl;

8b5ec3aabd04cd4cbd35da7c348061e8755.jpg

 

-----

转载于:https://my.oschina.net/u/3919756/blog/1936421

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值