Mat函數的定義與vector存儲到Mat中的問題

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

這裏寫圖片描述


  1. vector存入Mat的矩陣是按列存儲
  2. 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;
}

結果如下:

按列存入:
這裏寫圖片描述

按行存入:
這裏寫圖片描述

發佈了23 篇原創文章 · 獲贊 16 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章