zoukankan      html  css  js  c++  java
  • 格式化输出,可输出的类型(OpenCV案例源码cout_mat.cpp解读)

    格式化输出风格: 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;
    }

  • 相关阅读:
    007 连接
    006 group by having
    005 运算null 排序 模糊查询 聚合函数
    004 列、distinct、between、in、null
    003 约束和关系
    002 表的概念操作
    5-04用Sql语句创建表
    5-03使用视图创建表
    5-01表达基本概念
    4-04数据库的备份与还原
  • 原文地址:https://www.cnblogs.com/xixixing/p/6040682.html
Copyright © 2011-2022 走看看