Options
All
  • Public
  • Public/Protected
  • All
Menu

This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a real-valued scalar ( double )):

Addition, subtraction, negation: A+B, A-B, A+s, A-s, s+A, s-A, -A Scaling: A*alpha Per-element multiplication and division: A.mul(B), A/B, alpha/A Matrix multiplication: A*B Transposition: A.t() (means A) Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems: A.inv([method]) (~ A<sup>-1</sup>), A.inv([method])*B (~ X: AX=B) Comparison: A cmpop B, A cmpop alpha, alpha cmpop A, where cmpop is one of >, >=, ==, !=, <=, <. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0. Bitwise logical operations: A logicop B, A logicop s, s logicop A, ~A, where logicop is one of &, |, ^. Element-wise minimum and maximum: min(A, B), min(A, alpha), max(A, B), max(A, alpha) Element-wise absolute value: abs(A) Cross-product, dot-product: A.cross(B), A.dot(B) Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, mean, sum, countNonZero, trace, determinant, repeat, and others. Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated initializers, matrix constructors and operators that extract sub-matrices (see Mat description). Mat_() constructors to cast the result to the proper type.

Comma-separated initializers and probably some other operations may require additional explicit Mat() or Mat_() constructor calls to resolve a possible ambiguity. Here are examples of matrix expressions:

// compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD)
SVD svd(A);
Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t();

// compute the new vector of parameters in the Levenberg-Marquardt algorithm
x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err);

// sharpen image using "unsharp mask" algorithm
Mat blurred; double sigma = 1, threshold = 5, amount = 1;
GaussianBlur(img, blurred, Size(), sigma, sigma);
Mat lowContrastMask = abs(img - blurred) < threshold;
Mat sharpened = img*(1+amount) + blurred*(-amount);
img.copyTo(sharpened, lowContrastMask);

Source: opencv2/core/mat.hpp.

Hierarchy

Index

Constructors

constructor

Properties

a

a: Mat

allocator

allocator: MatAllocator

alpha

alpha: double

b

b: Mat

beta

beta: double

c

c: Mat

cols

cols: int

data

data: uchar

data16S

data16S: Int16Array

data16U

data16U: Uint16Array

data32F

data32F: Float32Array

data32S

data32S: Int32Array

data32U

data32U: Uint32Array

data64F

data64F: Float64Array

data8S

data8S: Int8Array

data8U

data8U: Uint8Array

dataend

dataend: uchar

datalimit

datalimit: uchar

datastart

datastart: uchar

dims

dims: int

flags

flags: int

op

op: MatOp

rows

rows: int

s

size

size: MatSize

step

step: MatStep

u

Methods

addref

  • addref(): void
  • The method increments the reference counter associated with the matrix data. If the matrix header points to an external data set (see [Mat::Mat] ), the reference counter is NULL, and the method has no effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It is called implicitly by the matrix assignment operator. The reference counter increment is an atomic operation on the platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in different threads.

    Returns void

adjustROI

  • The method is complimentary to [Mat::locateROI] . The typical use of these functions is to determine the submatrix position within the parent matrix and then shift the position somehow. Typically, it can be required for filtering operations when pixels outside of the ROI should be taken into account. When all the method parameters are positive, the ROI needs to grow in all directions by the specified amount, for example:

      A.adjustROI(2, 2, 2, 2);

    In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the filtering with the 5x5 kernel.

    adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not be increased in the upward direction.

    The function is used internally by the OpenCV filtering functions, like filter2D , morphological operations, and so on.

    [copyMakeBorder]

    Parameters

    • dtop: int

      Shift of the top submatrix boundary upwards.

    • dbottom: int

      Shift of the bottom submatrix boundary downwards.

    • dleft: int

      Shift of the left submatrix boundary to the left.

    • dright: int

      Shift of the right submatrix boundary to the right.

    Returns Mat

begin

  • The methods return the matrix read-only or read-write iterators. The use of matrix iterators is very similar to the use of bi-directional STL iterators. In the example below, the alpha blending function is rewritten using the matrix iterators:

      template<typename T>
      void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
      {
          typedef Vec<T, 4> VT;
    
          const float alpha_scale = (float)std::numeric_limits<T>::max(),
                      inv_scale = 1.f/alpha_scale;
    
          CV_Assert( src1.type() == src2.type() &&
                     src1.type() == traits::Type<VT>::value &&
                     src1.size() == src2.size());
          Size size = src1.size();
          dst.create(size, src1.type());
    
          MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end = src1.end<VT>();
          MatConstIterator_<VT> it2 = src2.begin<VT>();
          MatIterator_<VT> dst_it = dst.begin<VT>();
    
          for( ; it1 != it1_end; ++it1, ++it2, ++dst_it )
          {
              VT pix1 = *it1, pix2 = *it2;
              float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale;
    dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta),
                           saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta),
                           saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta),
                           saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale));
          }
      }

    Parameters

    • arg25: any

    Returns MatIterator_

  • Parameters

    • arg26: any

    Returns MatConstIterator_

channels

  • channels(): int

charAt

  • charAt(i: any): any

charPtr

  • charPtr(i: any, j: any): any

checkVector

  • checkVector(elemChannels: int, depth?: int, requireContinuous?: bool): int
  • -1 if the requirement is not satisfied. Otherwise, it returns the number of elements in the matrix. Note that an element may have multiple channels. The following code demonstrates its usage for a 2-d matrix:

          cv::Mat mat(20, 1, CV_32FC2);
          int n = mat.checkVector(2);
          CV_Assert(n == 20); // mat has 20 elements
    
          mat.create(20, 2, CV_32FC1);
          n = mat.checkVector(1);
          CV_Assert(n == -1); // mat is neither a column nor a row vector
    
          n = mat.checkVector(2);
          CV_Assert(n == 20); // the 2 columns are considered as 1 element

    The following code demonstrates its usage for a 3-d matrix:

          int dims[] = {1, 3, 5}; // 1 plane, every plane has 3 rows and 5 columns
          mat.create(3, dims, CV_32FC1); // for 3-d mat, it MUST have only 1 channel
          n = mat.checkVector(5); // the 5 columns are considered as 1 element
          CV_Assert(n == 3);
    
          int dims2[] = {3, 1, 5}; // 3 planes, every plane has 1 row and 5 columns
          mat.create(3, dims2, CV_32FC1);
          n = mat.checkVector(5); // the 5 columns are considered as 1 element
          CV_Assert(n == 3);

    Parameters

    • elemChannels: int

      Number of channels or number of columns the matrix should have. For a 2-D matrix, when the matrix has only 1 column, then it should have elemChannels channels; When the matrix has only 1 channel, then it should have elemChannels columns. For a 3-D matrix, it should have only one channel. Furthermore, if the number of planes is not one, then the number of rows within every plane has to be 1; if the number of rows within every plane is not 1, then the number of planes has to be 1.

    • Optional depth: int

      The depth the matrix should have. Set it to -1 when any depth is fine.

    • Optional requireContinuous: bool

      Set it to true to require the matrix to be continuous

    Returns int

clone

col

colRange

  • colRange(startcol: int, endcol: int): Mat
  • colRange(r: Range): Mat
  • The method makes a new header for the specified column span of the matrix. Similarly to [Mat::row] and [Mat::col] , this is an O(1) operation.

    Parameters

    • startcol: int

      An inclusive 0-based start index of the column span.

    • endcol: int

      An exclusive 0-based ending index of the column span.

    Returns Mat

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • r: Range

      Range structure containing both the start and the end indices.

    Returns Mat

convertTo

  • convertTo(m: OutputArray, rtype: int, alpha?: double, beta?: double): OutputArray
  • The method converts source pixel values to the target data type. saturate_cast<> is applied at the end to avoid possible overflows:

    \\[m(x,y) = saturate \\_ cast<rType>( \\alpha (*this)(x,y) + \\beta )\\]

    Parameters

    • m: OutputArray

      output matrix; if it does not have a proper size or type before the operation, it is reallocated.

    • rtype: int

      desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.

    • Optional alpha: double

      optional scale factor.

    • Optional beta: double

      optional delta added to the scaled values.

    Returns OutputArray

copySize

copyTo

  • copyTo(m: OutputArray): OutputArray
  • copyTo(m: OutputArray, mask: InputArray): OutputArray
  • The method copies the matrix data to another matrix. Before copying the data, the method invokes :

      m.create(this->size(), this->type());

    so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.

    When the operation mask is specified, if the [Mat::create] call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data.

    Parameters

    • m: OutputArray

      Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

    Returns OutputArray

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • m: OutputArray

      Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

    • mask: InputArray

      Operation mask of the same size as *this. Its non-zero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.

    Returns OutputArray

create

  • create(rows: int, cols: int, type: int): void
  • create(size: Size, type: int): Size
  • create(ndims: int, sizes: any, type: int): void
  • create(sizes: any, type: int): void
  • This is one of the key [Mat] methods. Most new-style OpenCV functions and methods that produce arrays call this method for each output array. The method uses the following algorithm:

    If the current array shape and the type match the new ones, return immediately. Otherwise, de-reference the previous data by calling [Mat::release]. Initialize the new header. Allocate the new data of [total()]*elemSize() bytes. Allocate the new, associated with the data, reference counter and set it to 1.

    Such a scheme makes the memory management robust and efficient at the same time and helps avoid extra typing for you. This means that usually there is no need to explicitly allocate output arrays. That is, instead of writing:

      Mat color;
      ...
      Mat gray(color.rows, color.cols, color.depth());
      cvtColor(color, gray, COLOR_BGR2GRAY);

    you can simply write:

      Mat color;
      ...
      Mat gray;
      cvtColor(color, gray, COLOR_BGR2GRAY);

    because cvtColor, as well as the most of OpenCV functions, calls [Mat::create()] for the output array internally.

    Parameters

    • rows: int

      New number of rows.

    • cols: int

      New number of columns.

    • type: int

      New matrix type.

    Returns void

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • size: Size

      Alternative new matrix size specification: Size(cols, rows)

    • type: int

      New matrix type.

    Returns Size

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • ndims: int

      New array dimensionality.

    • sizes: any

      Array of integers specifying a new array shape.

    • type: int

      New matrix type.

    Returns void

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • sizes: any

      Array of integers specifying a new array shape.

    • type: int

      New matrix type.

    Returns void

cross

deallocate

  • deallocate(): void

delete

  • delete(): void
  • delete(): void

deleteLater

  • deleteLater(...a: any[]): any

depth

  • The method returns the identifier of the matrix element depth (the type of each individual channel). For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of matrix types contains the following values:

    CV_8U - 8-bit unsigned integers ( 0..255 ) CV_8S - 8-bit signed integers ( -128..127 ) CV_16U - 16-bit unsigned integers ( 0..65535 ) CV_16S - 16-bit signed integers ( -32768..32767 ) CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )

    Returns int

diag

dot

doublePtr

  • doublePtr(i: any, j: any): any

elemSize

  • The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , the method returns 3*sizeof(short) or 6.

    Returns size_t

elemSize1

  • The method returns the matrix element channel size in bytes, that is, it ignores the number of channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2.

    Returns size_t

empty

  • The method returns true if [Mat::total()] is 0 or if [Mat::data] is NULL. Because of [pop_back()] and [resize()] methods [M.total()] == 0 does not imply that M.data == NULL.

    Returns bool

end

floatPtr

  • floatPtr(i: any, j: any): any

forEach

  • forEach(arg29: any, arg30: any, operation: any): any
  • forEach(arg31: any, arg32: any, operation: any): any
  • The operation passed as argument has to be a function pointer, a function object or a lambda(C++11).

    Example 1. All of the operations below put 0xFF the first channel of all matrix elements:

      Mat image(1920, 1080, CV_8UC3);
      typedef cv::Point3_<uint8_t> Pixel;
    
      // first. raw pointer access.
      for (int r = 0; r < image.rows; ++r) {
          Pixel* ptr = image.ptr<Pixel>(r, 0);
          const Pixel* ptr_end = ptr + image.cols;
          for (; ptr != ptr_end; ++ptr) {
              ptr->x = 255;
          }
      }
    
      // Using MatIterator. (Simple but there are a Iterator's overhead)
      for (Pixel &p : cv::Mat_<Pixel>(image)) {
          p.x = 255;
      }
    
      // Parallel execution with function object.
      struct Operator {
          void operator ()(Pixel &pixel, const int * position) {
              pixel.x = 255;
          }
      };
      image.forEach<Pixel>(Operator());
    
      // Parallel execution using C++11 lambda.
      image.forEach<Pixel>([](Pixel &p, const int * position) -> void {
          p.x = 255;
      });

    Example 2. Using the pixel's position:

      // Creating 3D matrix (255 x 255 x 255) typed uint8_t
      // and initialize all elements by the value which equals elements position.
      // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3).
    
      int sizes[] = { 255, 255, 255 };
      typedef cv::Point3_<uint8_t> Pixel;
    
      Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3);
    
      image.forEach<Pixel>([&](Pixel& pixel, const int position[]) -> void {
          pixel.x = position[0];
          pixel.y = position[1];
          pixel.z = position[2];
      });

    Parameters

    • arg29: any
    • arg30: any
    • operation: any

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg31: any
    • arg32: any
    • operation: any

    Returns any

get

  • get(i: number): Mat
  • get(i: number, j: number, data: any): Mat

getUMat

intPtr

  • intPtr(i: any, j: any): any
  • intPtr(i: any, j: any): any

inv

isAliasOf

  • isAliasOf(...a: any[]): any

isContinuous

  • isContinuous(): bool
  • The method returns true if the matrix elements are stored continuously without gaps at the end of each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous. Matrices created with [Mat::create] are always continuous. But if you extract a part of the matrix using [Mat::col], [Mat::diag], and so on, or constructed a matrix header for externally allocated data, such matrices may no longer have this property.

    The continuity flag is stored as a bit in the [Mat::flags] field and is computed automatically when you construct a matrix header. Thus, the continuity check is a very fast operation, though theoretically it could be done as follows:

      // alternative implementation of Mat::isContinuous()
      bool myCheckMatContinuity(const Mat& m)
      {
          //return (m.flags & Mat::CONTINUOUS_FLAG) != 0;
          return m.rows == 1 || m.step == m.cols*m.elemSize();
      }

    The method is used in quite a few of OpenCV functions. The point is that element-wise operations (such as arithmetic and logical operations, math functions, alpha blending, color space transformations, and others) do not depend on the image geometry. Thus, if all the input and output arrays are continuous, the functions can process them as very long single-row vectors. The example below illustrates how an alpha-blending function can be implemented:

      template<typename T>
      void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
      {
          const float alpha_scale = (float)std::numeric_limits<T>::max(),
                      inv_scale = 1.f/alpha_scale;
    
          CV_Assert( src1.type() == src2.type() &&
                     src1.type() == CV_MAKETYPE(traits::Depth<T>::value, 4) &&
                     src1.size() == src2.size());
          Size size = src1.size();
          dst.create(size, src1.type());
    
          // here is the idiom: check the arrays for continuity and,
          // if this is the case,
          // treat the arrays as 1D vectors
          if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() )
          {
              size.width *= size.height;
              size.height = 1;
          }
          size.width *= 4;
    
          for( int i = 0; i < size.height; i++ )
          {
              // when the arrays are continuous,
              // the outer loop is executed only once
              const T* ptr1 = src1.ptr<T>(i);
              const T* ptr2 = src2.ptr<T>(i);
              T* dptr = dst.ptr<T>(i);
    
              for( int j = 0; j < size.width; j += 4 )
              {
                  float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale;
                  dptr[j] = saturate_cast<T>(ptr1[j]*alpha + ptr2[j]*beta);
                  dptr[j+1] = saturate_cast<T>(ptr1[j+1]*alpha + ptr2[j+1]*beta);
                  dptr[j+2] = saturate_cast<T>(ptr1[j+2]*alpha + ptr2[j+2]*beta);
                  dptr[j+3] = saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale);
              }
          }
      }

    This approach, while being very simple, can boost the performance of a simple element-operation by 10-20 percents, especially if the image is rather small and the operation is quite simple.

    Another OpenCV idiom in this function, a call of [Mat::create] for the destination array, that allocates the destination array unless it already has the proper size and type. And while the newly allocated arrays are always continuous, you still need to check the destination array because [Mat::create] does not always allocate a new matrix.

    Returns bool

isDeleted

  • isDeleted(...a: any[]): any

locateROI

  • After you extracted a submatrix from a matrix using [Mat::row], [Mat::col], [Mat::rowRange], [Mat::colRange], and others, the resultant submatrix points just to the part of the original big matrix. However, each submatrix contains information (represented by datastart and dataend fields) that helps reconstruct the original matrix size and the position of the extracted submatrix within the original matrix. The method locateROI does exactly that.

    Parameters

    • wholeSize: Size

      Output parameter that contains the size of the whole matrix containing this as a part.

    • ofs: Point

      Output parameter that contains an offset of this inside the whole matrix.

    Returns Size

mul

pop_back

  • pop_back(nelems?: size_t): void
  • The method removes one or more rows from the bottom of the matrix.

    Parameters

    • Optional nelems: size_t

      Number of removed rows. If it is greater than the total number of rows, an exception is thrown.

    Returns void

ptr

  • The methods return uchar* or typed pointer to the specified matrix row. See the sample in [Mat::isContinuous] to know how to use these methods.

    Parameters

    • Optional i0: int

      A 0-based row index.

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • Optional i0: int

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • row: int

      Index along the dimension 0

    • col: int

      Index along the dimension 1

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • row: int

      Index along the dimension 0

    • col: int

      Index along the dimension 1

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • idx: any

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • idx: any

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns uchar

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg37: any
    • Optional i0: int

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg38: any
    • Optional i0: int

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg39: any
    • row: int

      Index along the dimension 0

    • col: int

      Index along the dimension 1

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg40: any
    • row: int

      Index along the dimension 0

    • col: int

      Index along the dimension 1

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg43: any
    • idx: any

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg44: any
    • idx: any

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns Vec

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    Returns Vec

push_back

  • push_back(arg47: any, elem: any): any
  • push_back(arg48: any, elem: Mat_): Mat_
  • push_back(arg49: any, elem: any): any
  • push_back(m: Mat): Mat
  • The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of the STL vector class. When elem is [Mat] , its type and the number of columns must be the same as in the container matrix.

    Parameters

    • arg47: any
    • elem: any

      Added element(s).

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg48: any
    • elem: Mat_

      Added element(s).

    Returns Mat_

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • arg49: any
    • elem: any

      Added element(s).

    Returns any

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • m: Mat

      Added line(s).

    Returns Mat

push_back_

  • push_back_(elem: any): void

put

  • put(i: number, j: number, data: any): any

release

  • release(): void
  • The method decrements the reference counter associated with the matrix data. When the reference counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers are set to NULL's. If the matrix header points to an external data set (see [Mat::Mat] ), the reference counter is NULL, and the method has no effect in this case.

    This method can be called manually to force the matrix data deallocation. But since this method is automatically called in the destructor, or by any other method that changes the data pointer, it is usually not needed. The reference counter decrement and check for 0 is an atomic operation on the platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in different threads.

    Returns void

reserve

  • The method reserves space for sz rows. If the matrix already has enough space to store sz rows, nothing happens. If the matrix is reallocated, the first [Mat::rows] rows are preserved. The method emulates the corresponding method of the STL vector class.

    Parameters

    Returns void

reserveBuffer

  • reserveBuffer(sz: size_t): void
  • The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, nothing happens. If matrix has to be reallocated its previous content could be lost.

    Parameters

    Returns void

reshape

  • reshape(cn: int, rows?: int): Mat
  • reshape(cn: int, newndims: int, newsz: any): Mat
  • reshape(cn: int, newshape: any): Mat
  • The method makes a new matrix header for *this elements. The new matrix may have a different size and/or different number of channels. Any combination is possible if:

    No extra elements are included into the new matrix and no elements are excluded. Consequently, the product rowscolschannels() must stay the same after the transformation. No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of rows, or the operation changes the indices of elements row in some other way, the matrix must be continuous. See [Mat::isContinuous] .

    For example, if there is a set of 3D points stored as an STL vector, and you want to represent the points as a 3xN matrix, do the following:

      std::vector<Point3f> vec;
      ...
      Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation
                        reshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel.
                                    // Also, an O(1) operation
                           t(); // finally, transpose the Nx3 matrix.
                                // This involves copying all the elements

    Parameters

    • cn: int

      New number of channels. If the parameter is 0, the number of channels remains the same.

    • Optional rows: int

      New number of rows. If the parameter is 0, the number of rows remains the same.

    Returns Mat

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • cn: int
    • newndims: int
    • newsz: any

    Returns Mat

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • cn: int
    • newshape: any

    Returns Mat

resize

  • The methods change the number of matrix rows. If the matrix is reallocated, the first min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL vector class.

    Parameters

    • sz: size_t

      New number of rows.

    Returns void

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • sz: size_t

      New number of rows.

    • s: Scalar

      Value assigned to the newly added elements.

    Returns Scalar

roi

  • Sometimes, you will have to play with certain region of images. For eye detection in images, first face detection is done all over the image and when face is obtained, we select the face region alone and search for eyes inside it instead of searching whole image. It improves accuracy (because eyes are always on faces) and performance (because we search for a small area).

    Heads up : in JS seems only one argument is expected.

    Parameters

    Returns Mat

row

rowRange

  • rowRange(startrow: int, endrow: int): Mat
  • rowRange(r: Range): Mat
  • The method makes a new header for the specified row span of the matrix. Similarly to [Mat::row] and [Mat::col] , this is an O(1) operation.

    Parameters

    • startrow: int

      An inclusive 0-based start index of the row span.

    • endrow: int

      An exclusive 0-based ending index of the row span.

    Returns Mat

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • r: Range

      Range structure containing both the start and the end indices.

    Returns Mat

set

  • set(i: number, t: Mat): void

setTo

  • setTo(value: InputArray | Scalar, mask?: InputArray): Mat
  • This is an advanced variant of the [Mat::operator=(const Scalar& s)] operator.

    Parameters

    • value: InputArray | Scalar

      Assigned scalar converted to the actual array type.

    • Optional mask: InputArray

      Operation mask of the same size as *this. Its non-zero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels

    Returns Mat

shortPtr

  • shortPtr(i: any, j: any): any

step1

  • The method returns a matrix step divided by [Mat::elemSize1()] . It can be useful to quickly access an arbitrary matrix element.

    Parameters

    • Optional i: int

    Returns size_t

t

total

type

ucharAt

  • ucharAt(i: any): any

ucharPtr

  • ucharPtr(i: any, j: any): any

updateContinuityFlag

  • updateContinuityFlag(): void

ushortPtr

  • ushortPtr(i: any, j: any): any

Static diag

  • The method creates a square diagonal matrix from specified main diagonal.

    Parameters

    • d: Mat

      One-dimensional matrix that represents the main diagonal.

    Returns Mat

Static eye

  • The method returns a Matlab-style identity matrix initializer, similarly to [Mat::zeros]. Similarly to [Mat::ones], you can use a scale operation to create a scaled identity matrix efficiently:

      // make a 4x4 diagonal matrix with 0.1's on the diagonal.
      Mat A = Mat::eye(4, 4, CV_32F)*0.1;

    In case of multi-channels type, identity matrix will be initialized only for the first channel, the others will be set to 0's

    Parameters

    • rows: int

      Number of rows.

    • cols: int

      Number of columns.

    • type: int

      Created matrix type.

    Returns MatExpr

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • size: Size

      Alternative matrix size specification as Size(cols, rows) .

    • type: int

      Created matrix type.

    Returns MatExpr

Static getDefaultAllocator

Static getStdAllocator

Static ones

  • The method returns a Matlab-style 1's array initializer, similarly to [Mat::zeros]. Note that using this method you can initialize an array with an arbitrary value, using the following Matlab idiom:

      Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3.

    The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it just remembers the scale factor (3 in this case) and use it when actually invoking the matrix initializer.

    In case of multi-channels type, only the first channel will be initialized with 1's, the others will be set to 0's.

    Parameters

    • rows: int

      Number of rows.

    • cols: int

      Number of columns.

    • type: int

      Created matrix type.

    Returns MatExpr

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • size: Size

      Alternative to the matrix size specification Size(cols, rows) .

    • type: int

      Created matrix type.

    Returns MatExpr

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • ndims: int

      Array dimensionality.

    • sz: any

      Array of integers specifying the array shape.

    • type: int

      Created matrix type.

    Returns MatExpr

Static setDefaultAllocator

Static zeros

  • The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant array as a function parameter, part of a matrix expression, or as a matrix initializer:

      Mat A;
      A = Mat::zeros(3, 3, CV_32F);

    In the example above, a new matrix is allocated only if A is not a 3x3 floating-point matrix. Otherwise, the existing matrix A is filled with zeros.

    Parameters

    • rows: int

      Number of rows.

    • cols: int

      Number of columns.

    • type: int

      Created matrix type.

    Returns MatExpr

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • size: Size

      Alternative to the matrix size specification Size(cols, rows) .

    • type: int

      Created matrix type.

    Returns MatExpr

  • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters

    • ndims: int

      Array dimensionality.

    • sz: any

      Array of integers specifying the array shape.

    • type: int

      Created matrix type.

    Returns MatExpr

Generated using TypeDoc