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;
    }

  • 相关阅读:
    USACO / Longest Prefix最长前缀(DP)
    (转)HDOJ 4006 The kth great number(优先队列)
    STL priority_queue(优先队列(堆))
    康托展开
    USACO / Magic Squares(经典BFS+Cantor展开hash)
    国家集训队论文分类整理
    国家集训队论文分类整理
    国家集训队论文分类整理
    OI / ACM 知识归纳
    学年总结跋涉ACM之路
  • 原文地址:https://www.cnblogs.com/xixixing/p/6040682.html
Copyright © 2011-2022 走看看