[][src]Trait opencv::core::prelude::MatTrait

pub trait MatTrait {
    pub fn as_raw_Mat(&self) -> *const c_void;
pub fn as_raw_mut_Mat(&mut self) -> *mut c_void; pub fn flags(&self) -> i32 { ... }
pub fn set_flags(&mut self, val: i32) { ... }
pub fn dims(&self) -> i32 { ... }
pub fn set_dims(&mut self, val: i32) { ... }
pub fn rows(&self) -> i32 { ... }
pub fn set_rows(&mut self, val: i32) { ... }
pub fn cols(&self) -> i32 { ... }
pub fn set_cols(&mut self, val: i32) { ... }
pub fn data_mut(&mut self) -> &mut u8 { ... }
pub unsafe fn set_data(&mut self, val: &mut u8) { ... }
pub fn datastart(&self) -> &u8 { ... }
pub fn dataend(&self) -> &u8 { ... }
pub fn datalimit(&self) -> &u8 { ... }
pub fn u(&mut self) -> UMatData { ... }
pub fn set_u(&mut self, val: &mut UMatData) { ... }
pub fn mat_size(&self) -> MatSize { ... }
pub fn mat_step(&self) -> MatStep { ... }
pub fn get_umat(
        &self,
        access_flags: AccessFlag,
        usage_flags: UMatUsageFlags
    ) -> Result<UMat> { ... }
pub fn row(&self, y: i32) -> Result<Mat> { ... }
pub fn col(&self, x: i32) -> Result<Mat> { ... }
pub fn row_bounds(&self, startrow: i32, endrow: i32) -> Result<Mat> { ... }
pub fn row_range(&self, r: &Range) -> Result<Mat> { ... }
pub fn col_bounds(&self, startcol: i32, endcol: i32) -> Result<Mat> { ... }
pub fn col_range(&self, r: &Range) -> Result<Mat> { ... }
pub fn diag(&self, d: i32) -> Result<Mat> { ... }
pub fn try_clone(&self) -> Result<Mat> { ... }
pub fn copy_to(&self, m: &mut dyn ToOutputArray) -> Result<()> { ... }
pub fn copy_to_masked(
        &self,
        m: &mut dyn ToOutputArray,
        mask: &dyn ToInputArray
    ) -> Result<()> { ... }
pub fn convert_to(
        &self,
        m: &mut dyn ToOutputArray,
        rtype: i32,
        alpha: f64,
        beta: f64
    ) -> Result<()> { ... }
pub fn assign_to(&self, m: &mut Mat, typ: i32) -> Result<()> { ... }
pub fn set_to(
        &mut self,
        value: &dyn ToInputArray,
        mask: &dyn ToInputArray
    ) -> Result<Mat> { ... }
pub fn reshape(&self, cn: i32, rows: i32) -> Result<Mat> { ... }
pub fn reshape_nd(&self, cn: i32, newsz: &[i32]) -> Result<Mat> { ... }
pub fn reshape_nd_vec(&self, cn: i32, newshape: &Vector<i32>) -> Result<Mat> { ... }
pub fn t(&self) -> Result<MatExpr> { ... }
pub fn inv(&self, method: i32) -> Result<MatExpr> { ... }
pub fn mul(&self, m: &dyn ToInputArray, scale: f64) -> Result<MatExpr> { ... }
pub fn cross(&self, m: &dyn ToInputArray) -> Result<Mat> { ... }
pub fn dot(&self, m: &dyn ToInputArray) -> Result<f64> { ... }
pub unsafe fn create_rows_cols(
        &mut self,
        rows: i32,
        cols: i32,
        typ: i32
    ) -> Result<()> { ... }
pub unsafe fn create_size(&mut self, size: Size, typ: i32) -> Result<()> { ... }
pub unsafe fn create_nd(&mut self, sizes: &[i32], typ: i32) -> Result<()> { ... }
pub unsafe fn create_nd_vec(
        &mut self,
        sizes: &Vector<i32>,
        typ: i32
    ) -> Result<()> { ... }
pub fn addref(&mut self) -> Result<()> { ... }
pub fn release(&mut self) -> Result<()> { ... }
pub fn deallocate(&mut self) -> Result<()> { ... }
pub fn reserve(&mut self, sz: size_t) -> Result<()> { ... }
pub fn reserve_buffer(&mut self, sz: size_t) -> Result<()> { ... }
pub fn resize(&mut self, sz: size_t) -> Result<()> { ... }
pub fn resize_with_default(&mut self, sz: size_t, s: Scalar) -> Result<()> { ... }
pub fn push_back(&mut self, m: &Mat) -> Result<()> { ... }
pub fn pop_back(&mut self, nelems: size_t) -> Result<()> { ... }
pub fn locate_roi(
        &self,
        whole_size: &mut Size,
        ofs: &mut Point
    ) -> Result<()> { ... }
pub fn adjust_roi(
        &mut self,
        dtop: i32,
        dbottom: i32,
        dleft: i32,
        dright: i32
    ) -> Result<Mat> { ... }
pub fn is_continuous(&self) -> Result<bool> { ... }
pub fn is_submatrix(&self) -> Result<bool> { ... }
pub fn elem_size(&self) -> Result<size_t> { ... }
pub fn elem_size1(&self) -> Result<size_t> { ... }
pub fn typ(&self) -> Result<i32> { ... }
pub fn depth(&self) -> Result<i32> { ... }
pub fn channels(&self) -> Result<i32> { ... }
pub fn step1(&self, i: i32) -> Result<size_t> { ... }
pub fn empty(&self) -> Result<bool> { ... }
pub fn total(&self) -> Result<size_t> { ... }
pub fn total_slice(&self, start_dim: i32, end_dim: i32) -> Result<size_t> { ... }
pub fn check_vector(
        &self,
        elem_channels: i32,
        depth: i32,
        require_continuous: bool
    ) -> Result<i32> { ... }
pub unsafe fn ptr_mut(&mut self, i0: i32) -> Result<&mut u8> { ... }
pub unsafe fn ptr(&self, i0: i32) -> Result<&u8> { ... }
pub unsafe fn ptr_2d_mut(&mut self, row: i32, col: i32) -> Result<&mut u8> { ... }
pub unsafe fn ptr_2d(&self, row: i32, col: i32) -> Result<&u8> { ... }
pub unsafe fn ptr_3d_mut(
        &mut self,
        i0: i32,
        i1: i32,
        i2: i32
    ) -> Result<&mut u8> { ... }
pub unsafe fn ptr_3d(&self, i0: i32, i1: i32, i2: i32) -> Result<&u8> { ... }
pub unsafe fn ptr_nd_mut(&mut self, idx: &[i32]) -> Result<&mut u8> { ... }
pub unsafe fn ptr_nd(&self, idx: &[i32]) -> Result<&u8> { ... }
pub fn at_mut<T: DataType>(&mut self, i0: i32) -> Result<&mut T> { ... }
pub fn at<T: DataType>(&self, i0: i32) -> Result<&T> { ... }
pub fn at_2d_mut<T: DataType>(
        &mut self,
        row: i32,
        col: i32
    ) -> Result<&mut T> { ... }
pub fn at_2d<T: DataType>(&self, row: i32, col: i32) -> Result<&T> { ... }
pub fn at_3d_mut<T: DataType>(
        &mut self,
        i0: i32,
        i1: i32,
        i2: i32
    ) -> Result<&mut T> { ... }
pub fn at_3d<T: DataType>(&self, i0: i32, i1: i32, i2: i32) -> Result<&T> { ... }
pub fn at_nd_mut<T: DataType>(&mut self, idx: &[i32]) -> Result<&mut T> { ... }
pub fn at_nd<T: DataType>(&self, idx: &[i32]) -> Result<&T> { ... }
pub fn at_pt_mut<T: DataType>(&mut self, pt: Point) -> Result<&mut T> { ... }
pub fn at_pt<T: DataType>(&self, pt: Point) -> Result<&T> { ... }
pub fn update_continuity_flag(&mut self) -> Result<()> { ... } }

n-dimensional dense array class \anchor CVMat_Details

The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms may be better stored in a SparseMat ). The data layout of the array M is defined by the array M.step[], so that the address of element inline formula, where inline formula, is computed as: block formula In case of a 2-dimensional array, the above formula is reduced to: block formula Note that M.step[i] >= M.step[i+1] (in fact, M.step[i] >= M.step[i+1]*M.size[i+1] ). This means that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() .

So, the data layout in Mat is compatible with the majority of dense array types from the standard toolkits and SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any array that uses steps (or strides) to compute the position of a pixel. Due to this compatibility, it is possible to make a Mat header for user-allocated data and process it in-place using OpenCV functions.

There are many different ways to create a Mat object. The most popular options are listed below:

  • Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue]) constructor. A new array of the specified size and type is allocated. type has the same meaning as in the cvCreateMat method. For example, CV_8UC1 means a 8-bit single-channel array, CV_32FC2 means a 2-channel (complex) floating-point array, and so on.
   // make a 7x7 complex matrix filled with 1+3j.
   Mat M(7,7,CV_32FC2,Scalar(1,3));
   // and now turn M to a 100x60 15-channel 8-bit matrix.
   // The old content will be deallocated
   M.create(100,60,CV_8UC(15));

As noted in the introduction to this chapter, create() allocates only a new array when the shape or type of the current array are different from the specified ones.

  • Create a multi-dimensional array:
   // create a 100x100x100 8-bit array
   int sz[] = {100, 100, 100};
   Mat bigCube(3, sz, CV_8U, Scalar::all(0));

It passes the number of dimensions =1 to the Mat constructor but the created array will be 2-dimensional with the number of columns set to 1. So, Mat::dims is always >= 2 (can also be 0 when the array is empty).

  • Use a copy constructor or assignment operator where there can be an array or expression on the right side (see below). As noted in the introduction, the array assignment is an O(1) operation because it only copies the header and increases the reference counter. The Mat::clone() method can be used to get a full (deep) copy of the array when you need it.

  • Construct a header for a part of another array. It can be a single row, single column, several rows, several columns, rectangular region in the array (called a minor in algebra) or a diagonal. Such operations are also O(1) because the new header references the same data. You can actually modify a part of the array using this feature, for example:

   // add the 5-th row, multiplied by 3 to the 3rd row
   M.row(3) = M.row(3) + M.row(5)*3;
   // now copy the 7-th column to the 1-st column
   // M.col(1) = M.col(7); // this will not work
   Mat M1 = M.col(1);
   M.col(7).copyTo(M1);
   // create a new 320x240 image
   Mat img(Size(320,240),CV_8UC3);
   // select a ROI
   Mat roi(img, Rect(10,10,100,100));
   // fill the ROI with (0,255,0) (which is green in RGB space);
   // the original 320x240 image will be modified
   roi = Scalar(0,255,0);

Due to the additional datastart and dataend members, it is possible to compute a relative sub-array position in the main container array using locateROI():

   Mat A = Mat::eye(10, 10, CV_32S);
   // extracts A columns, 1 (inclusive) to 3 (exclusive).
   Mat B = A(Range::all(), Range(1, 3));
   // extracts B rows, 5 (inclusive) to 9 (exclusive).
   // that is, C \~ A(Range(5, 9), Range(1, 3))
   Mat C = B(Range(5, 9), Range::all());
   Size size; Point ofs;
   C.locateROI(size, ofs);
   // size will be (width=10,height=10) and the ofs will be (x=1, y=5)

As in case of whole matrices, if you need a deep copy, use the clone() method of the extracted sub-matrices.

  • Make a header for user-allocated data. It can be useful to do the following: -# Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for gstreamer, and so on). For example:

        Mat process_video_frame(const unsigned char* pixels,
                                 int width, int height, int step)
        {
            // wrap input buffer
            Mat img(height, width, CV_8UC3, (unsigned char*)pixels, step);
    
            Mat result;
            GaussianBlur(img, result, Size(7, 7), 1.5, 1.5);
    
            return result;
        }

    -# Quickly initialize small matrices and/or get a super-fast element access.

        double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}};
        Mat M = Mat(3, 3, CV_64F, m).inv();

    .

  • Use MATLAB-style array initializers, zeros(), ones(), eye(), for example:

   // create a double-precision identity matrix and add it to M.
   M += Mat::eye(M.rows, M.cols, CV_64F);
  • Use a comma-separated initializer:
   // create a 3x3 double-precision identity matrix
   Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);

With this approach, you first call a constructor of the Mat class with the proper parameters, and then you just put << operator followed by comma-separated values that can be constants, variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation errors.

Once the array is created, it is automatically managed via a reference-counting mechanism. If the array header is built on top of user-allocated data, you should handle the data by yourself. The array data is deallocated when no one points to it. If you want to release the data pointed by a array header before the array destructor is called, use Mat::release().

The next important thing to learn about the array class is element access. This manual already described how to compute an address of each array element. Normally, you are not required to use the formula directly in the code. If you know the array element type (which can be retrieved using the method Mat::type() ), you can access the element inline formula of a 2-dimensional array as:

   M.at<double>(i,j) += 1.f;

assuming that M is a double-precision floating-point array. There are several variants of the method at for a different number of dimensions.

If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to the row first, and then just use the plain C operator [] :

   // compute sum of positive matrix elements
   // (assuming that M is a double-precision matrix)
   double sum=0;
   for(int i = 0; i < M.rows; i++)
   {
       const double* Mi = M.ptr<double>(i);
       for(int j = 0; j < M.cols; j++)
           sum += std::max(Mi[j], 0.);
   }

Some operations, like the one above, do not actually depend on the array shape. They just process elements of an array one by one (or elements from multiple arrays that have the same coordinates, for example, array addition). Such operations are called element-wise. It makes sense to check whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If yes, process them as a long single row:

   // compute the sum of positive matrix elements, optimized variant
   double sum=0;
   int cols = M.cols, rows = M.rows;
   if(M.isContinuous())
   {
       cols *= rows;
       rows = 1;
   }
   for(int i = 0; i < rows; i++)
   {
       const double* Mi = M.ptr<double>(i);
       for(int j = 0; j < cols; j++)
           sum += std::max(Mi[j], 0.);
   }

In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is smaller, which is especially noticeable in case of small matrices.

Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows:

   // compute sum of positive matrix elements, iterator-based variant
   double sum=0;
   MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>();
   for(; it != it_end; ++it)
       sum += std::max(*it, 0.);

The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, including std::sort().

Note: Matrix Expressions and arithmetic see MatExpr

Required methods

pub fn as_raw_Mat(&self) -> *const c_void[src]

pub fn as_raw_mut_Mat(&mut self) -> *mut c_void[src]

Loading content...

Provided methods

pub fn flags(&self) -> i32[src]

! includes several bit-fields:

  • the magic signature
  • continuity flag
  • depth
  • number of channels

pub fn set_flags(&mut self, val: i32)[src]

! includes several bit-fields:

  • the magic signature
  • continuity flag
  • depth
  • number of channels

pub fn dims(&self) -> i32[src]

the matrix dimensionality, >= 2

pub fn set_dims(&mut self, val: i32)[src]

the matrix dimensionality, >= 2

pub fn rows(&self) -> i32[src]

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

pub fn set_rows(&mut self, val: i32)[src]

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

pub fn cols(&self) -> i32[src]

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

pub fn set_cols(&mut self, val: i32)[src]

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

pub fn data_mut(&mut self) -> &mut u8[src]

pointer to the data

pub unsafe fn set_data(&mut self, val: &mut u8)[src]

pointer to the data

pub fn datastart(&self) -> &u8[src]

helper fields used in locateROI and adjustROI

pub fn dataend(&self) -> &u8[src]

pub fn datalimit(&self) -> &u8[src]

pub fn u(&mut self) -> UMatData[src]

interaction with UMat

pub fn set_u(&mut self, val: &mut UMatData)[src]

interaction with UMat

pub fn mat_size(&self) -> MatSize[src]

pub fn mat_step(&self) -> MatStep[src]

pub fn get_umat(
    &self,
    access_flags: AccessFlag,
    usage_flags: UMatUsageFlags
) -> Result<UMat>
[src]

retrieve UMat from Mat

C++ default parameters

  • usage_flags: USAGE_DEFAULT

pub fn row(&self, y: i32) -> Result<Mat>[src]

Creates a matrix header for the specified matrix row.

The method makes a new header for the specified matrix row and returns it. This is an O(1) operation, regardless of the matrix size. The underlying data of the new matrix is shared with the original matrix. Here is the example of one of the classical basic matrix processing operations, axpy, used by LU and many other algorithms:

   inline void matrix_axpy(Mat& A, int i, int j, double alpha)
   {
       A.row(i) += A.row(j)*alpha;
   }

Note: In the current implementation, the following code does not work as expected:

   Mat A;
   ...
   A.row(i) = A.row(j); // will not work

This happens because A.row(i) forms a temporary header that is further assigned to another header. Remember that each of these operations is O(1), that is, no data is copied. Thus, the above assignment is not true if you may have expected the j-th row to be copied to the i-th row. To achieve that, you should either turn this simple assignment into an expression or use the Mat::copyTo method:

   Mat A;
   ...
   // works, but looks a bit obscure.
   A.row(i) = A.row(j) + 0;
   // this is a bit longer, but the recommended method.
   A.row(j).copyTo(A.row(i));

Parameters

  • y: A 0-based row index.

pub fn col(&self, x: i32) -> Result<Mat>[src]

Creates a matrix header for the specified matrix column.

The method makes a new header for the specified matrix column and returns it. This is an O(1) operation, regardless of the matrix size. The underlying data of the new matrix is shared with the original matrix. See also the Mat::row description.

Parameters

  • x: A 0-based column index.

pub fn row_bounds(&self, startrow: i32, endrow: i32) -> Result<Mat>[src]

Creates a matrix header for the specified row span.

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: An inclusive 0-based start index of the row span.
  • endrow: An exclusive 0-based ending index of the row span.

pub fn row_range(&self, r: &Range) -> Result<Mat>[src]

Creates a matrix header for the specified row span.

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: An inclusive 0-based start index of the row span.
  • endrow: An exclusive 0-based ending index of the row span.

Overloaded parameters

  • r: Range structure containing both the start and the end indices.

pub fn col_bounds(&self, startcol: i32, endcol: i32) -> Result<Mat>[src]

Creates a matrix header for the specified column span.

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: An inclusive 0-based start index of the column span.
  • endcol: An exclusive 0-based ending index of the column span.

pub fn col_range(&self, r: &Range) -> Result<Mat>[src]

Creates a matrix header for the specified column span.

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: An inclusive 0-based start index of the column span.
  • endcol: An exclusive 0-based ending index of the column span.

Overloaded parameters

  • r: Range structure containing both the start and the end indices.

pub fn diag(&self, d: i32) -> Result<Mat>[src]

Extracts a diagonal from a matrix

The method makes a new header for the specified matrix diagonal. The new matrix is represented as a single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation.

Parameters

  • d: index of the diagonal, with the following values:
  • d=0 is the main diagonal.
  • d<0 is a diagonal from the lower half. For example, d=-1 means the diagonal is set immediately below the main one.
  • d>0 is a diagonal from the upper half. For example, d=1 means the diagonal is set immediately above the main one. For example:
   Mat m = (Mat_<int>(3,3) <<
               1,2,3,
               4,5,6,
               7,8,9);
   Mat d0 = m.diag(0);
   Mat d1 = m.diag(1);
   Mat d_1 = m.diag(-1);

The resulting matrices are

 d0 =
   [1;
   5;
   9]
 d1 =
   [2;
   6]
 d_1 =
   [4;
   8]

C++ default parameters

  • d: 0

pub fn try_clone(&self) -> Result<Mat>[src]

Creates a full copy of the array and the underlying data.

The method creates a full copy of the array. The original step[] is not taken into account. So, the array copy is a continuous array occupying total()*elemSize() bytes.

pub fn copy_to(&self, m: &mut dyn ToOutputArray) -> Result<()>[src]

Copies the matrix to another one.

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: Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

pub fn copy_to_masked(
    &self,
    m: &mut dyn ToOutputArray,
    mask: &dyn ToInputArray
) -> Result<()>
[src]

Copies the matrix to another one.

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: Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

Overloaded parameters

  • m: Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.
  • mask: 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.

pub fn convert_to(
    &self,
    m: &mut dyn ToOutputArray,
    rtype: i32,
    alpha: f64,
    beta: f64
) -> Result<()>
[src]

Converts an array to another data type with optional scaling.

The method converts source pixel values to the target data type. saturate_cast<> is applied at the end to avoid possible overflows:

block formula

Parameters

  • m: output matrix; if it does not have a proper size or type before the operation, it is reallocated.
  • rtype: 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.
  • alpha: optional scale factor.
  • beta: optional delta added to the scaled values.

C++ default parameters

  • alpha: 1
  • beta: 0

pub fn assign_to(&self, m: &mut Mat, typ: i32) -> Result<()>[src]

Provides a functional form of convertTo.

This is an internally used method called by the @ref MatrixExpressions engine.

Parameters

  • m: Destination array.
  • type: Desired destination array depth (or -1 if it should be the same as the source type).

C++ default parameters

  • typ: -1

pub fn set_to(
    &mut self,
    value: &dyn ToInputArray,
    mask: &dyn ToInputArray
) -> Result<Mat>
[src]

Sets all or some of the array elements to the specified value.

This is an advanced variant of the Mat::operator=(const Scalar& s) operator.

Parameters

  • value: Assigned scalar converted to the actual array type.
  • mask: 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

C++ default parameters

  • mask: noArray()

pub fn reshape(&self, cn: i32, rows: i32) -> Result<Mat>[src]

Changes the shape and/or the number of channels of a 2D matrix without copying the data.

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 rows*cols*channels() 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: New number of channels. If the parameter is 0, the number of channels remains the same.
  • rows: New number of rows. If the parameter is 0, the number of rows remains the same.

C++ default parameters

  • rows: 0

pub fn reshape_nd(&self, cn: i32, newsz: &[i32]) -> Result<Mat>[src]

Changes the shape and/or the number of channels of a 2D matrix without copying the data.

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 rows*cols*channels() 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: New number of channels. If the parameter is 0, the number of channels remains the same.
  • rows: New number of rows. If the parameter is 0, the number of rows remains the same.

Overloaded parameters

pub fn reshape_nd_vec(&self, cn: i32, newshape: &Vector<i32>) -> Result<Mat>[src]

Changes the shape and/or the number of channels of a 2D matrix without copying the data.

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 rows*cols*channels() 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: New number of channels. If the parameter is 0, the number of channels remains the same.
  • rows: New number of rows. If the parameter is 0, the number of rows remains the same.

Overloaded parameters

pub fn t(&self) -> Result<MatExpr>[src]

Transposes a matrix.

The method performs matrix transposition by means of matrix expressions. It does not perform the actual transposition but returns a temporary matrix transposition object that can be further used as a part of more complex matrix expressions or can be assigned to a matrix:

   Mat A1 = A + Mat::eye(A.size(), A.type())*lambda;
   Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I)

pub fn inv(&self, method: i32) -> Result<MatExpr>[src]

Inverses a matrix.

The method performs a matrix inversion by means of matrix expressions. This means that a temporary matrix inversion object is returned by the method and can be used further as a part of more complex matrix expressions or can be assigned to a matrix.

Parameters

  • method: Matrix inversion method. One of cv::DecompTypes

C++ default parameters

  • method: DECOMP_LU

pub fn mul(&self, m: &dyn ToInputArray, scale: f64) -> Result<MatExpr>[src]

Performs an element-wise multiplication or division of the two matrices.

The method returns a temporary object encoding per-element array multiplication, with optional scale. Note that this is not a matrix multiplication that corresponds to a simpler "*" operator.

Example:

   Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5)

Parameters

  • m: Another array of the same type and the same size as *this, or a matrix expression.
  • scale: Optional scale factor.

C++ default parameters

  • scale: 1

pub fn cross(&self, m: &dyn ToInputArray) -> Result<Mat>[src]

Computes a cross-product of two 3-element vectors.

The method computes a cross-product of two 3-element vectors. The vectors must be 3-element floating-point vectors of the same shape and size. The result is another 3-element vector of the same shape and type as operands.

Parameters

  • m: Another cross-product operand.

pub fn dot(&self, m: &dyn ToInputArray) -> Result<f64>[src]

Computes a dot-product of two vectors.

The method computes a dot-product of two matrices. If the matrices are not single-column or single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D vectors. The vectors must have the same size and type. If the matrices have more than one channel, the dot products from all the channels are summed together.

Parameters

  • m: another dot-product operand.

pub unsafe fn create_rows_cols(
    &mut self,
    rows: i32,
    cols: i32,
    typ: i32
) -> Result<()>
[src]

Allocates new array data if needed.

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: New number of rows.
  • cols: New number of columns.
  • type: New matrix type.

pub unsafe fn create_size(&mut self, size: Size, typ: i32) -> Result<()>[src]

Allocates new array data if needed.

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: New number of rows.
  • cols: New number of columns.
  • type: New matrix type.

Overloaded parameters

  • size: Alternative new matrix size specification: Size(cols, rows)
  • type: New matrix type.

pub unsafe fn create_nd(&mut self, sizes: &[i32], typ: i32) -> Result<()>[src]

Allocates new array data if needed.

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: New number of rows.
  • cols: New number of columns.
  • type: New matrix type.

Overloaded parameters

  • ndims: New array dimensionality.
  • sizes: Array of integers specifying a new array shape.
  • type: New matrix type.

pub unsafe fn create_nd_vec(
    &mut self,
    sizes: &Vector<i32>,
    typ: i32
) -> Result<()>
[src]

Allocates new array data if needed.

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: New number of rows.
  • cols: New number of columns.
  • type: New matrix type.

Overloaded parameters

  • sizes: Array of integers specifying a new array shape.
  • type: New matrix type.

pub fn addref(&mut self) -> Result<()>[src]

Increments the reference counter.

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.

pub fn release(&mut self) -> Result<()>[src]

Decrements the reference counter and deallocates the matrix if needed.

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.

pub fn deallocate(&mut self) -> Result<()>[src]

internal use function, consider to use 'release' method instead; deallocates the matrix data

pub fn reserve(&mut self, sz: size_t) -> Result<()>[src]

Reserves space for the certain number of rows.

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

  • sz: Number of rows.

pub fn reserve_buffer(&mut self, sz: size_t) -> Result<()>[src]

Reserves space for the certain number of bytes.

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

  • sz: Number of bytes.

pub fn resize(&mut self, sz: size_t) -> Result<()>[src]

Changes the number of matrix rows.

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: New number of rows.

pub fn resize_with_default(&mut self, sz: size_t, s: Scalar) -> Result<()>[src]

Changes the number of matrix rows.

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: New number of rows.

Overloaded parameters

  • sz: New number of rows.
  • s: Value assigned to the newly added elements.

pub fn push_back(&mut self, m: &Mat) -> Result<()>[src]

Adds elements to the bottom of the matrix.

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

  • elem: Added element(s).

Overloaded parameters

  • m: Added line(s).

pub fn pop_back(&mut self, nelems: size_t) -> Result<()>[src]

Removes elements from the bottom of the matrix.

The method removes one or more rows from the bottom of the matrix.

Parameters

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

C++ default parameters

  • nelems: 1

pub fn locate_roi(&self, whole_size: &mut Size, ofs: &mut Point) -> Result<()>[src]

Locates the matrix header within a parent matrix.

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: Output parameter that contains the size of the whole matrix containing this as a part.
  • ofs: Output parameter that contains an offset of this inside the whole matrix.

pub fn adjust_roi(
    &mut self,
    dtop: i32,
    dbottom: i32,
    dleft: i32,
    dright: i32
) -> Result<Mat>
[src]

Adjusts a submatrix size and position within the parent matrix.

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.

Parameters

  • dtop: Shift of the top submatrix boundary upwards.
  • dbottom: Shift of the bottom submatrix boundary downwards.
  • dleft: Shift of the left submatrix boundary to the left.
  • dright: Shift of the right submatrix boundary to the right.

See also

copyMakeBorder

pub fn is_continuous(&self) -> Result<bool>[src]

Reports whether the matrix is continuous or not.

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.

pub fn is_submatrix(&self) -> Result<bool>[src]

returns true if the matrix is a submatrix of another matrix

pub fn elem_size(&self) -> Result<size_t>[src]

Returns the matrix element size in bytes.

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.

pub fn elem_size1(&self) -> Result<size_t>[src]

Returns the size of each matrix element channel in bytes.

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.

pub fn typ(&self) -> Result<i32>[src]

Returns the type of a matrix element.

The method returns a matrix element type. This is an identifier compatible with the CvMat type system, like CV_16SC3 or 16-bit signed 3-channel array, and so on.

pub fn depth(&self) -> Result<i32>[src]

Returns the depth of a matrix element.

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 )

pub fn channels(&self) -> Result<i32>[src]

Returns the number of matrix channels.

The method returns the number of matrix channels.

pub fn step1(&self, i: i32) -> Result<size_t>[src]

Returns a normalized step.

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

C++ default parameters

  • i: 0

pub fn empty(&self) -> Result<bool>[src]

Returns true if the array has no elements.

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.

pub fn total(&self) -> Result<size_t>[src]

Returns the total number of array elements.

The method returns the number of array elements (a number of pixels if the array represents an image).

pub fn total_slice(&self, start_dim: i32, end_dim: i32) -> Result<size_t>[src]

Returns the total number of array elements.

The method returns the number of elements within a certain sub-array slice with startDim <= dim < endDim

C++ default parameters

  • end_dim: INT_MAX

pub fn check_vector(
    &self,
    elem_channels: i32,
    depth: i32,
    require_continuous: bool
) -> Result<i32>
[src]

Parameters

  • elemChannels: 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.
  • depth: The depth the matrix should have. Set it to -1 when any depth is fine.
  • requireContinuous: Set it to true to require the matrix to be continuous

Returns

-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: example-2d

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

C++ default parameters

  • depth: -1
  • require_continuous: true

pub unsafe fn ptr_mut(&mut self, i0: i32) -> Result<&mut u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

C++ default parameters

  • i0: 0

pub unsafe fn ptr(&self, i0: i32) -> Result<&u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

C++ default parameters

  • i0: 0

pub unsafe fn ptr_2d_mut(&mut self, row: i32, col: i32) -> Result<&mut u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

  • row: Index along the dimension 0
  • col: Index along the dimension 1

pub unsafe fn ptr_2d(&self, row: i32, col: i32) -> Result<&u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

  • row: Index along the dimension 0
  • col: Index along the dimension 1

pub unsafe fn ptr_3d_mut(
    &mut self,
    i0: i32,
    i1: i32,
    i2: i32
) -> Result<&mut u8>
[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

pub unsafe fn ptr_3d(&self, i0: i32, i1: i32, i2: i32) -> Result<&u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

pub unsafe fn ptr_nd_mut(&mut self, idx: &[i32]) -> Result<&mut u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

pub unsafe fn ptr_nd(&self, idx: &[i32]) -> Result<&u8>[src]

Returns a pointer to the specified matrix row.

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

  • i0: A 0-based row index.

Overloaded parameters

pub fn at_mut<T: DataType>(&mut self, i0: i32) -> Result<&mut T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

C++ default parameters

  • i0: 0

pub fn at<T: DataType>(&self, i0: i32) -> Result<&T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • i0: Index along the dimension 0

C++ default parameters

  • i0: 0

pub fn at_2d_mut<T: DataType>(&mut self, row: i32, col: i32) -> Result<&mut T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • row: Index along the dimension 0
  • col: Index along the dimension 1

pub fn at_2d<T: DataType>(&self, row: i32, col: i32) -> Result<&T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • row: Index along the dimension 0
  • col: Index along the dimension 1

pub fn at_3d_mut<T: DataType>(
    &mut self,
    i0: i32,
    i1: i32,
    i2: i32
) -> Result<&mut T>
[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • i0: Index along the dimension 0
  • i1: Index along the dimension 1
  • i2: Index along the dimension 2

pub fn at_3d<T: DataType>(&self, i0: i32, i1: i32, i2: i32) -> Result<&T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • i0: Index along the dimension 0
  • i1: Index along the dimension 1
  • i2: Index along the dimension 2

pub fn at_nd_mut<T: DataType>(&mut self, idx: &[i32]) -> Result<&mut T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • idx: Array of Mat::dims indices.

pub fn at_nd<T: DataType>(&self, idx: &[i32]) -> Result<&T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

  • idx: Array of Mat::dims indices.

pub fn at_pt_mut<T: DataType>(&mut self, pt: Point) -> Result<&mut T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

special versions for 2D arrays (especially convenient for referencing image pixels)

  • pt: Element position specified as Point(j,i) .

pub fn at_pt<T: DataType>(&self, pt: Point) -> Result<&T>[src]

Returns a reference to the specified array element.

The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.

Note that the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4) and B.at<int>(2*i+1) instead of A.at<float>(0,k+4) and B.at<int>(2*i+1,0), respectively.

The example below initializes a Hilbert matrix:

   Mat H(100, 100, CV_64F);
   for(int i = 0; i < H.rows; i++)
       for(int j = 0; j < H.cols; j++)
           H.at<double>(i,j)=1./(i+j+1);

Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:

  • If matrix is of type CV_8U then use Mat.at<uchar>(y,x).
  • If matrix is of type CV_8S then use Mat.at<schar>(y,x).
  • If matrix is of type CV_16U then use Mat.at<ushort>(y,x).
  • If matrix is of type CV_16S then use Mat.at<short>(y,x).
  • If matrix is of type CV_32S then use Mat.at<int>(y,x).
  • If matrix is of type CV_32F then use Mat.at<float>(y,x).
  • If matrix is of type CV_64F then use Mat.at<double>(y,x).

Parameters

  • i0: Index along the dimension 0

Overloaded parameters

special versions for 2D arrays (especially convenient for referencing image pixels)

  • pt: Element position specified as Point(j,i) .

pub fn update_continuity_flag(&mut self) -> Result<()>[src]

internal use method: updates the continuity flag

Loading content...

Implementors

impl MatTrait for Mat[src]

impl<T> MatTrait for Mat_<T>[src]

Loading content...