您的位置:首页 > 其它

Mat函数的定义与vector存储到Mat中的问题

2015-06-14 11:54 369 查看
Mat类型对应的数值如下:

#define CV_8U   0
#define CV_8S   1
#define CV_16U  2
#define CV_16S  3
#define CV_32S  4
#define CV_32F  5
#define CV_64F  6


未对定义的Mat矩阵进行设置,那么他将默认为行=0,列=0,类型为cv_8UC1

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
Mat f;
cout << "f.rows =" << f.rows << endl
<<"f.cols =" << f.cols << endl
<< "f.type =" << f.type()<< endl;

system("pause");
return 0;
}




vector存入Mat的矩阵是按列存储

Mat的类型将隐式转化为vector的类型(这里cv_8UC1 转为 cv_32FC1)

int main()
{
Mat f;
vector<float> fvec(5, 4);

f.push_back(static_cast<Mat>(fvec));//按列存入
//f.push_back(static_cast<Mat>(fvec).reshape(1, 1));//按行存入

cout << "f.rows =" << f.rows << endl
<<"f.cols =" << f.cols << endl
<< "f.type =" << f.type()<< endl;

system("pause");
return 0;
}


结果如下:

按列存入:



按行存入:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: