OpenCV学习笔记------基本数据结构

开发环境配置参考:vs2017+OpenCV~

//图像数据结构实例
#include"opencv2/core/core.hpp"
#include<iostream>

using namespace cv;
using namespace std;


int main(int, char**)
{
	//用构造函数建立数据  2*2的矩阵  里面的元素为8位  U表示(unsigned)为无符号数  C表示(channe)通道数有3个
	Mat M(2,2,CV_8UC3,Scalar(0, 0, 255));
	cout << "M = " << endl << " " << M << endl;


	//用create函数建立数据
	M.create(2, 2, CV_8UC(2));
	cout << "M = " << endl << " " << M << endl;



	//建立多维矩阵   无法用<<输出
	int sz[3] = { 2, 2, 2 };
	Mat L(3, sz, CV_8UC(1), Scalar::all(0));



	//用MATLAB风格的眼建立数据
	Mat E = Mat::eye(3, 3, CV_64F);
	cout << "E = " << endl << " " << E << endl;


	//数据都是1
	Mat O = Mat::ones(2, 2, CV_32F);
	cout << "O = " << endl << " " << O << endl;


	//数据都是0
	Mat Z= Mat::zeros(2, 2, CV_8UC1);
	cout << "Z = " << endl << " " << Z << endl;


	//建立3*3双精度矩阵,值由<<输入
	Mat C = (Mat_<double>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
	cout << "C = " << endl << " " << C << endl;


	//复制第一行数据
	Mat RowClone = C.row(0).clone();
	cout << "RowClone = " << endl << " " << RowClone << endl;


	//以随机数值填入矩阵内
	Mat R = Mat(3, 2, CV_8UC3);
	randu(R, Scalar::all(0),Scalar::all(255));

	//展示各种输出格式选项
	cout << "R (default) = " << endl << R << endl;
	cout << "R (python)  = " << endl << format(R, "python") << endl;
	cout << "R (numpy)   = " << endl << format(R, "numpy") << endl;
	cout << "R(csv)      = " << endl << format(R, "csv") << endl;
	cout << "R(C)        = " << endl << format(R, "C") << endl;

	//图像中二维的点
	Point2f P(5,1);
	cout << "Point (2D)" << P << endl;
	
	//图像中三维的点
	Point2f P3f(5,1);
	cout << "Point(3D)" << P3f << endl;

	vector<float> v;
	v.push_back((float) CV_PI);
	v.push_back(2);
	v.push_back(3.01f);

	cout << "浮点向量矩阵 = " << Mat(v) << endl << endl;
	
	vector<Point2f> vPoints(5);
	for (size_t i = 0; i < vPoints.size(); ++i)
		vPoints[i] = Point2f((float)(i * 5), (float)(i % 7));
	cout << "二维图点向量 = " << vPoints << endl;

	getchar();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值