OpenCV4 study notes - 2. Understand cv :: Mat

cv :: Mat is an important class in OpenCV, for representing multi-dimensional array of single or multiple channels. It is used to store the complex or real vector or matrix, grayscale or color images, vector field, cloud point, tensor, histogram and the like.

There are many ways to create cv::Matobjects:

  1. Mat(nrows, ncols, type[, fillValue])
  2. Copy constructor or assignment operator
  3. Construct a header for a part of another array
// 创建一个 7x7 的复数矩阵,并以 1+3j 填充
Mat M(7, 7, CV_32FC2, Scalar(1, 3));

// 创建一个 100x100 的单通道8bit 矩阵,并以 255 填充
Mat M(100, 100, CV_8UC1, Scalar(255));

// 创建一个 100x100 的3通道8bit 矩阵
Mat M(100, 100, CV_8UC3);

Mat M1;
M.copyTo(M1);

Mat A = Mat::eye(10, 10, CV_32S);

Mat img(Size(320, 240), CV_8UC3);
Mat roi(img, Rect(10, 10, 100, 100));
Mat B = img(Range::all(), Range(1, 3));

Public Attributes:

  • cols: number of columns
  • rows: the number of lines
  • dims: Dimensions
  • data: the data pointer points to uchar

Public Member Functions:

  • empty: determining whether the data is empty
  • at: a template function that returns a reference to the specified matrix element
  • begin, end: for iterative
  • channels: Channel Matrices
  • clone: ​​Returns the complete copy of the matrix
  • copyTo: matrix copied to another matrix
  • convertTo: conversion element type
  • dot: matrix multiplication
  • mul: multiplying element

Static Public Member Functions:

  • diag: Creating a diagonal matrix
  • eye: Create a matrix
  • ones: Create a full-matrix 1
  • zeros: Create a full-matrix 0

Reproduced in: https: //www.jianshu.com/p/092240d35949

Guess you like

Origin blog.csdn.net/weixin_34014277/article/details/91333469