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;
}
結果如下:
按列存入:
按行存入: