当前位置:网站首页>Opencv learning notes - cv:: mat class

Opencv learning notes - cv:: mat class

2022-06-24 12:05:00 cc_ rong

Catalog

Mat Initialization function

Access pixels

Method 1 : Use at function

Method 2 : Using Iterators


Mat Initialization function

// Default constructor 
cv::Mat  
// Copy structure 
cv::Mat(const Mat& mat)
//  Specify copy construction for rows and columns 
cv::Mat(const Mat& mat, const cv::Range& rows, const cv::Range& cols);
//  Appoint ROI( Areas of interest ) Copy construction of 
cv::Mat(const Mat& mat, const cv::Rect& roi);
//  Use n Copy construction of data within the specified range in the dimension group 
cv::Mat(const Mat& mat, const cv::Range* ranges);
//  A two-dimensional array of the specified type 
cv::Mat(int rows, int cols, int type);
//  Specify the type of 2D data , And specify the initialization value 
cv::Mat(int rows, int cols, int type, const Scalar& s);
//  Use pre-existing data , And specify a two-dimensional array of types 
cv::Mat(int rows, int cols, int type, void *data, size_t step = AUTO_STEP);
//  A two-dimensional array specifying size and type 
cv::Mat(cv::Size sz, int type)
//  A two-dimensional array specifying size and type , And specify the initial value 
cv::Mat(cv::Size sz, int type, const Scalar& s);
//  Use pre-existing data , A two-dimensional array of the specified type 
cv::Mat(cv::Size sz, int type, void *data, size_t step = AUTO_STEP);
//  Specify the type of multidimensional data 
cv::Mat(int ndims, const int *sizes, int type);
//  Specify the type of multidimensional data , And the initial value 
cv::Mat(int ndims, const int *sizes, int type, const Scalar& s);
//  Use pre-existing data , Multidimensional array of specified type 
cv::Mat(int ndims, const int* sizes, int type, void* data, size_t step = AUTO_STEP);

//mat Template constructor for 
//  Construction as cv::Vec The specified data type 、 The size is n One dimensional array of 
cv::Mat(const cv::Vec<T, n>& vec, bool copyData = true);
//  Construction as cv::Matx The specified data type 、 The size is mXn Two dimensional array of 
cv::Mat(const cv::Matx<T, m, n>& vec, bool copyData = true);
//  structure STL Of vector A one-dimensional array of the specified data type 
cv::Mat mat(const std::vector<T>& vec, bool copyData = true);

// structure mat Static method of 
//  Use zeros() The function definition specifies the size (rows X cols) And type (type) Of cv::Mat( All for 0) Matrix 
cv::Mat::zeros(int rows, int cols, int type);
//  Use ones() The function definition specifies the size (rows X cols) And type (type) Of cv::Mat( All for 1) Matrix 
cv::Mat::ones(int rows, int cols, int type);
//  Use eye() The function definition specifies the size (rows X cols) And type (type) The identity matrix of 
cv::Mat::eye(int rows, int cols, int type);

Access pixels

Method 1 : Use at function

// Direct access   at function 
cv::Mat mat = cv::Mat::eye(10, 10, 32FC1);
m.at<float>(3, 3)

// Multi channel array operation 
cv::Mat mat = cv::Mat::eye(10, 10, 32FC2);
m.at<cv::Vec2f>(3, 3)[0];
m.at<cv::Vec2f>(3, 3)[1];

Method 2 : Using Iterators

int sz[3] = {4, 4, 4};
Mat m(3, sz, CV_32FC3);
cv::MatIterator<cv::Vec3b>  it = m.begin();

while(it != m.end()) {
    cout << (*)it[0];
    it++;
}
原网站

版权声明
本文为[cc_ rong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241000269445.html