zoukankan      html  css  js  c++  java
  • OpenCV——创建Mat对象、格式化输出、常用数据结构和函数(point,vector、Scalar、Size、Rect、cvtColor)

     

     

    转载至:https://www.cnblogs.com/long5683/p/9643692.html

    实践代码:

    //---------------------------------【头文件、命名空间包含部分】---------------------------
    //          描述:包含程序所使用的头文件和命名空间
    //-----------------------------------------------------------------------------------------------
    #include "opencv2/core/core.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include <iostream>
    using namespace std;
    using namespace cv;
    
    //--------------------------------------【main( )函数】-----------------------------------------
    //          描述:控制台应用程序的入口函数,我们的程序从这里开始执行
    //-----------------------------------------------------------------------------------------------
    int main(int, char**)
    {
    	//改变控制台的前景色和背景色
    	system("color 8F");
    
    	Mat I = Mat::eye(4, 4, CV_64F);
    	I.at<double>(1, 1) = CV_PI;
    	cout << "
    I = " << I << ";
    " << endl;
    
    	Mat r = Mat(10, 3, CV_8UC3);
    	randu(r, Scalar::all(0), Scalar::all(255));
    
    	//此段代码的OpenCV2版为:
    	//cout << "r (OpenCV默认风格) = " << r << ";" << endl << endl;
    	//cout << "r (Python风格) = " << format(r,"python") << ";" << endl << endl;
    	//cout << "r (Numpy风格) = " << format(r,"numpy") << ";" << endl << endl;
    	//cout << "r (逗号分隔风格) = " << format(r,"csv") << ";" << endl<< endl;
    	//cout << "r (C语言风格) = " << format(r,"C") << ";" << endl << endl;
    	//此段代码的OpenCV3版为:
    	cout << "r (OpenCV默认风格) = " << r << ";" << endl << endl;
    	cout << "r (Python风格) = " << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl;
    	cout << "r (Numpy风格) = " << format(r, Formatter::FMT_NUMPY) << ";" << endl << endl;
    	cout << "r (逗号分隔风格) = " << format(r, Formatter::FMT_CSV) << ";" << endl << endl;
    	cout << "r (C语言风格) = " << format(r, Formatter::FMT_C) << ";" << endl << endl;
    
    	Point2f p(6, 2);
    	cout << "【2维点】p = " << p << ";
    " << endl;
    
    	Point3f p3f(8, 2, 0);
    	cout << "【3维点】p3f = " << p3f << ";
    " << endl;
    
    	vector<float> v;
    	v.push_back(3);
    	v.push_back(5);
    	v.push_back(7);
    
    	cout << "【基于Mat的vector】shortvec = " << Mat(v) << ";
    " << endl;
    
    	vector<Point2f> points(20);
    	for (size_t i = 0; i < points.size(); ++i)
    		points[i] = Point2f((float)(i * 5), (float)(i % 7));
    
    	cout << "【二维点向量】points = " << points << ";";
    
    	getchar();//按任意键退出
    
    	return 0;
    
    }
    

      

  • 相关阅读:
    《ACM国际大学生程序设计竞赛题解I》——6.8
    数据结构篇
    从SG函数浅谈解决博弈问题的通法
    动态规划的泛式解题思路
    bzoj1057: [ZJOI2007]棋盘制作
    bzoj3884: 上帝与集合的正确用法
    bzoj1564: [NOI2009]二叉查找树
    bzoj4347: [POI2016]Nim z utrudnieniem
    bzoj1131: [POI2008]Sta
    bzoj1566: [NOI2009]管道取珠
  • 原文地址:https://www.cnblogs.com/fcfc940503/p/11263929.html
Copyright © 2011-2022 走看看