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

      

  • 相关阅读:
    2.6.2.MySQL主从复制的原理
    2.4.5 MySQL InnoDB重做与回滚介绍
    PRML读书笔记_绪论曲线拟合部分
    python3_字符串
    PRML读书笔记_绪论
    python3_列表、元组、集合、字典
    linux_软件安装
    shell获取帮助
    linux_查看磁盘与目录容量
    linux_压缩解压命令(zip/tar)
  • 原文地址:https://www.cnblogs.com/fcfc940503/p/11263929.html
Copyright © 2020-2023  润新知