[−][src]Struct opencv::core::Mat
ndimensional dense array class \anchor CVMat_Details
The class Mat represents an ndimensional dense numerical singlechannel or multichannel array. It
can be used to store real or complexvalued vectors and matrices, grayscale or color images, voxel
volumes, vector fields, point clouds, tensors, histograms (though, very highdimensional 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 , where , is
computed as:
In case of a 2dimensional array, the above formula is reduced to:
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 2dimensional matrices are stored rowbyrow, 3dimensional matrices are stored planebyplane,
and so on. M.step[M.dims1] 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 userallocated data and process it inplace 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 8bit singlechannel array, CV_32FC2 means a 2channel (complex) floatingpoint 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 15channel 8bit 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 multidimensional array:
// create a 100x100x100 8bit 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 2dimensional 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 5th row, multiplied by 3 to the 3rd row M.row(3) = M.row(3) + M.row(5)*3; // now copy the 7th column to the 1st 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 subarray 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
submatrices.

Make a header for userallocated 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 superfast 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 MATLABstyle array initializers, zeros(), ones(), eye(), for example:
// create a doubleprecision identity matrix and add it to M. M += Mat::eye(M.rows, M.cols, CV_64F);
 Use a commaseparated initializer:
// create a 3x3 doubleprecision 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 commaseparated 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 referencecounting mechanism. If the array header is built on top of userallocated 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 of a 2dimensional array as:
M.at<double>(i,j) += 1.f;
assuming that M
is a doubleprecision floatingpoint 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 doubleprecision 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 elementwise. 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 STLstyle iterators that are smart enough to skip gaps between successive rows:
// compute sum of positive matrix elements, iteratorbased 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 randomaccess iterators, so they can be passed to any STL algorithm, including std::sort().
Note: Matrix Expressions and arithmetic see MatExpr
Implementations
impl Mat
[src]
pub fn as_raw_Mat(&self) > *const c_void
[src]
pub fn as_raw_mut_Mat(&mut self) > *mut c_void
[src]
impl Mat
[src]
pub fn default() > Result<Mat>
[src]
These are various constructors that form a matrix. As noted in the AutomaticAllocation, often the default constructor is enough, and the proper matrix will be allocated by an OpenCV function. The constructed matrix can further be assigned to another matrix or matrix expression or can be allocated with Mat::create . In the former case, the old content is dereferenced.
pub unsafe fn new_rows_cols(rows: i32, cols: i32, typ: i32) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 rows: Number of rows in a 2D array.
 cols: Number of columns in a 2D array.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
pub unsafe fn new_size(size: Size, typ: i32) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 size: 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
pub fn new_rows_cols_with_default(
rows: i32,
cols: i32,
typ: i32,
s: Scalar
) > Result<Mat>
[src]
rows: i32,
cols: i32,
typ: i32,
s: Scalar
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 rows: Number of rows in a 2D array.
 cols: Number of columns in a 2D array.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 s: An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
pub fn new_size_with_default(size: Size, typ: i32, s: Scalar) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 size: 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 s: An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
pub unsafe fn new_nd(ndims: i32, sizes: &i32, typ: i32) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 ndims: Array dimensionality.
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
pub unsafe fn new_nd_vec(sizes: &Vector<i32>, typ: i32) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
pub fn new_nd_with_default(sizes: &[i32], typ: i32, s: Scalar) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 ndims: Array dimensionality.
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 s: An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
pub fn new_nd_vec_with_default(
sizes: &Vector<i32>,
typ: i32,
s: Scalar
) > Result<Mat>
[src]
sizes: &Vector<i32>,
typ: i32,
s: Scalar
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 s: An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
pub fn copy(m: &Mat) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 m: Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() .
pub unsafe fn new_rows_cols_with_data(
rows: i32,
cols: i32,
typ: i32,
data: *mut c_void,
step: size_t
) > Result<Mat>
[src]
rows: i32,
cols: i32,
typ: i32,
data: *mut c_void,
step: size_t
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 rows: Number of rows in a 2D array.
 cols: Number of columns in a 2D array.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 data: Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it.
 step: Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
C++ default parameters
 step: AUTO_STEP
pub unsafe fn new_size_with_data(
size: Size,
typ: i32,
data: *mut c_void,
step: size_t
) > Result<Mat>
[src]
size: Size,
typ: i32,
data: *mut c_void,
step: size_t
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 size: 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 data: Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it.
 step: Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
C++ default parameters
 step: AUTO_STEP
pub unsafe fn new_nd_with_data(
sizes: &[i32],
typ: i32,
data: *mut c_void,
steps: &size_t
) > Result<Mat>
[src]
sizes: &[i32],
typ: i32,
data: *mut c_void,
steps: &size_t
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 ndims: Array dimensionality.
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 data: Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it.
 steps: Array of ndims1 steps in case of a multidimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.
C++ default parameters
 steps: 0
pub unsafe fn new_nd_vec_with_data(
sizes: &Vector<i32>,
typ: i32,
data: *mut c_void,
steps: &size_t
) > Result<Mat>
[src]
sizes: &Vector<i32>,
typ: i32,
data: *mut c_void,
steps: &size_t
) > Result<Mat>
download data from GpuMat
Overloaded parameters
Parameters
 sizes: Array of integers specifying an ndimensional array shape.
 type: Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
 data: Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it.
 steps: Array of ndims1 steps in case of a multidimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.
C++ default parameters
 steps: 0
pub fn rowscols(m: &Mat, row_range: &Range, col_range: &Range) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 m: Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() .
 rowRange: Range of the m rows to take. As usual, the range start is inclusive and the range end is exclusive. Use Range::all() to take all the rows.
 colRange: Range of the m columns to take. Use Range::all() to take all the columns.
C++ default parameters
 col_range: Range::all()
pub fn roi(m: &Mat, roi: Rect) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 m: Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() .
 roi: Region of interest.
pub fn ranges(m: &Mat, ranges: &Vector<Range>) > Result<Mat>
[src]
download data from GpuMat
Overloaded parameters
Parameters
 m: Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() .
 ranges: Array of selected ranges of m along each dimensionality.
pub fn new(m: &GpuMat) > Result<Mat>
[src]
download data from GpuMat
pub fn diag_mat(d: &Mat) > Result<Mat>
[src]
creates a diagonal matrix
The method creates a square diagonal matrix from specified main diagonal.
Parameters
 d: Onedimensional matrix that represents the main diagonal.
pub fn zeros(rows: i32, cols: i32, typ: i32) > Result<MatExpr>
[src]
Returns a zero array of the specified size and type.
The method returns a Matlabstyle 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 floatingpoint matrix. Otherwise, the existing matrix A is filled with zeros.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
pub fn zeros_size(size: Size, typ: i32) > Result<MatExpr>
[src]
Returns a zero array of the specified size and type.
The method returns a Matlabstyle 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 floatingpoint matrix. Otherwise, the existing matrix A is filled with zeros.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
Overloaded parameters
 size: Alternative to the matrix size specification Size(cols, rows) .
 type: Created matrix type.
pub fn zeros_nd(sz: &[i32], typ: i32) > Result<MatExpr>
[src]
Returns a zero array of the specified size and type.
The method returns a Matlabstyle 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 floatingpoint matrix. Otherwise, the existing matrix A is filled with zeros.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
Overloaded parameters
 ndims: Array dimensionality.
 sz: Array of integers specifying the array shape.
 type: Created matrix type.
pub fn ones(rows: i32, cols: i32, typ: i32) > Result<MatExpr>
[src]
Returns an array of all 1's of the specified size and type.
The method returns a Matlabstyle 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.
Note: In case of multichannels type, only the first channel will be initialized with 1's, the others will be set to 0's.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
pub fn ones_size(size: Size, typ: i32) > Result<MatExpr>
[src]
Returns an array of all 1's of the specified size and type.
The method returns a Matlabstyle 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.
Note: In case of multichannels type, only the first channel will be initialized with 1's, the others will be set to 0's.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
Overloaded parameters
 size: Alternative to the matrix size specification Size(cols, rows) .
 type: Created matrix type.
pub fn ones_nd(sz: &[i32], typ: i32) > Result<MatExpr>
[src]
Returns an array of all 1's of the specified size and type.
The method returns a Matlabstyle 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.
Note: In case of multichannels type, only the first channel will be initialized with 1's, the others will be set to 0's.
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
Overloaded parameters
 ndims: Array dimensionality.
 sz: Array of integers specifying the array shape.
 type: Created matrix type.
pub fn eye(rows: i32, cols: i32, typ: i32) > Result<MatExpr>
[src]
Returns an identity matrix of the specified size and type.
The method returns a Matlabstyle 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;
Note: In case of multichannels type, identity matrix will be initialized only for the first channel, the others will be set to 0's
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
pub fn eye_size(size: Size, typ: i32) > Result<MatExpr>
[src]
Returns an identity matrix of the specified size and type.
The method returns a Matlabstyle 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;
Note: In case of multichannels type, identity matrix will be initialized only for the first channel, the others will be set to 0's
Parameters
 rows: Number of rows.
 cols: Number of columns.
 type: Created matrix type.
Overloaded parameters
 size: Alternative matrix size specification as Size(cols, rows) .
 type: Created matrix type.
pub fn copy_mut(m: &mut Mat) > Result<Mat>
[src]
impl Mat
[src]
pub fn from_exact_iter<T: DataType>(
s: impl ExactSizeIterator<Item = T>
) > Result<Self>
[src]
s: impl ExactSizeIterator<Item = T>
) > Result<Self>
Create new Mat
from the iterator of known size
pub fn from_slice<T: DataType>(s: &[T]) > Result<Self>
[src]
pub fn from_slice_2d<T: DataType>(s: &[impl AsRef<[T]>]) > Result<Self>
[src]
pub fn try_into_typed<T: DataType>(self) > Result<Mat_<T>> where
Self: Sized,
[src]
Self: Sized,
Trait Implementations
impl Boxed for Mat
[src]
pub unsafe fn from_raw(ptr: *mut c_void) > Self
[src]
pub fn into_raw(self) > *mut c_void
[src]
pub fn as_raw(&self) > *const c_void
[src]
pub fn as_raw_mut(&mut self) > *mut c_void
[src]
impl Clone for Mat
[src]
pub fn clone(&self) > Self
[src]
Calls try_clone() and panics if that fails
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Mat
[src]
impl Drop for Mat
[src]
impl<T: DataType> From<Mat_<T>> for Mat
[src]
impl MatTrait for Mat
[src]
pub fn as_raw_Mat(&self) > *const c_void
[src]
pub fn as_raw_mut_Mat(&mut self) > *mut c_void
[src]
pub fn flags(&self) > i32
[src]
pub fn set_flags(&mut self, val: i32)
[src]
pub fn dims(&self) > i32
[src]
pub fn set_dims(&mut self, val: i32)
[src]
pub fn rows(&self) > i32
[src]
pub fn set_rows(&mut self, val: i32)
[src]
pub fn cols(&self) > i32
[src]
pub fn set_cols(&mut self, val: i32)
[src]
pub fn data_mut(&mut self) > &mut u8
[src]
pub unsafe fn set_data(&mut self, val: &mut u8)
[src]
pub fn datastart(&self) > &u8
[src]
pub fn dataend(&self) > &u8
[src]
pub fn datalimit(&self) > &u8
[src]
pub fn u(&mut self) > UMatData
[src]
pub fn set_u(&mut self, val: &mut UMatData)
[src]
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]
&self,
access_flags: AccessFlag,
usage_flags: UMatUsageFlags
) > Result<UMat>
pub fn row(&self, y: i32) > Result<Mat>
[src]
pub fn col(&self, x: i32) > Result<Mat>
[src]
pub fn row_bounds(&self, startrow: i32, endrow: i32) > Result<Mat>
[src]
pub fn row_range(&self, r: &Range) > Result<Mat>
[src]
pub fn col_bounds(&self, startcol: i32, endcol: i32) > Result<Mat>
[src]
pub fn col_range(&self, r: &Range) > Result<Mat>
[src]
pub fn diag(&self, d: i32) > Result<Mat>
[src]
pub fn try_clone(&self) > Result<Mat>
[src]
pub fn copy_to(&self, m: &mut dyn ToOutputArray) > Result<()>
[src]
pub fn copy_to_masked(
&self,
m: &mut dyn ToOutputArray,
mask: &dyn ToInputArray
) > Result<()>
[src]
&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<()>
[src]
&self,
m: &mut dyn ToOutputArray,
rtype: i32,
alpha: f64,
beta: f64
) > Result<()>
pub fn assign_to(&self, m: &mut Mat, typ: i32) > Result<()>
[src]
pub fn set_to(
&mut self,
value: &dyn ToInputArray,
mask: &dyn ToInputArray
) > Result<Mat>
[src]
&mut self,
value: &dyn ToInputArray,
mask: &dyn ToInputArray
) > Result<Mat>
pub fn reshape(&self, cn: i32, rows: i32) > Result<Mat>
[src]
pub fn reshape_nd(&self, cn: i32, newsz: &[i32]) > Result<Mat>
[src]
pub fn reshape_nd_vec(&self, cn: i32, newshape: &Vector<i32>) > Result<Mat>
[src]
pub fn t(&self) > Result<MatExpr>
[src]
pub fn inv(&self, method: i32) > Result<MatExpr>
[src]
pub fn mul(&self, m: &dyn ToInputArray, scale: f64) > Result<MatExpr>
[src]
pub fn cross(&self, m: &dyn ToInputArray) > Result<Mat>
[src]
pub fn dot(&self, m: &dyn ToInputArray) > Result<f64>
[src]
pub unsafe fn create_rows_cols(
&mut self,
rows: i32,
cols: i32,
typ: i32
) > Result<()>
[src]
&mut self,
rows: i32,
cols: i32,
typ: i32
) > Result<()>
pub unsafe fn create_size(&mut self, size: Size, typ: i32) > Result<()>
[src]
pub unsafe fn create_nd(&mut self, sizes: &[i32], typ: i32) > Result<()>
[src]
pub unsafe fn create_nd_vec(
&mut self,
sizes: &Vector<i32>,
typ: i32
) > Result<()>
[src]
&mut self,
sizes: &Vector<i32>,
typ: i32
) > Result<()>
pub fn addref(&mut self) > Result<()>
[src]
pub fn release(&mut self) > Result<()>
[src]
pub fn deallocate(&mut self) > Result<()>
[src]
pub fn reserve(&mut self, sz: size_t) > Result<()>
[src]
pub fn reserve_buffer(&mut self, sz: size_t) > Result<()>
[src]
pub fn resize(&mut self, sz: size_t) > Result<()>
[src]
pub fn resize_with_default(&mut self, sz: size_t, s: Scalar) > Result<()>
[src]
pub fn push_back(&mut self, m: &Mat) > Result<()>
[src]
pub fn pop_back(&mut self, nelems: size_t) > Result<()>
[src]
pub fn locate_roi(&self, whole_size: &mut Size, ofs: &mut Point) > Result<()>
[src]
pub fn adjust_roi(
&mut self,
dtop: i32,
dbottom: i32,
dleft: i32,
dright: i32
) > Result<Mat>
[src]
&mut self,
dtop: i32,
dbottom: i32,
dleft: i32,
dright: i32
) > Result<Mat>
pub fn is_continuous(&self) > Result<bool>
[src]
pub fn is_submatrix(&self) > Result<bool>
[src]
pub fn elem_size(&self) > Result<size_t>
[src]
pub fn elem_size1(&self) > Result<size_t>
[src]
pub fn typ(&self) > Result<i32>
[src]
pub fn depth(&self) > Result<i32>
[src]
pub fn channels(&self) > Result<i32>
[src]
pub fn step1(&self, i: i32) > Result<size_t>
[src]
pub fn empty(&self) > Result<bool>
[src]
pub fn total(&self) > Result<size_t>
[src]
pub fn total_slice(&self, start_dim: i32, end_dim: i32) > Result<size_t>
[src]
pub fn check_vector(
&self,
elem_channels: i32,
depth: i32,
require_continuous: bool
) > Result<i32>
[src]
&self,
elem_channels: i32,
depth: i32,
require_continuous: bool
) > Result<i32>
pub unsafe fn ptr_mut(&mut self, i0: i32) > Result<&mut u8>
[src]
pub unsafe fn ptr(&self, i0: i32) > Result<&u8>
[src]
pub unsafe fn ptr_2d_mut(&mut self, row: i32, col: i32) > Result<&mut u8>
[src]
pub unsafe fn ptr_2d(&self, row: i32, col: i32) > Result<&u8>
[src]
pub unsafe fn ptr_3d_mut(
&mut self,
i0: i32,
i1: i32,
i2: i32
) > Result<&mut u8>
[src]
&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>
[src]
pub unsafe fn ptr_nd_mut(&mut self, idx: &[i32]) > Result<&mut u8>
[src]
pub unsafe fn ptr_nd(&self, idx: &[i32]) > Result<&u8>
[src]
pub fn at_mut<T: DataType>(&mut self, i0: i32) > Result<&mut T>
[src]
pub fn at<T: DataType>(&self, i0: i32) > Result<&T>
[src]
pub fn at_2d_mut<T: DataType>(&mut self, row: i32, col: i32) > Result<&mut T>
[src]
pub fn at_2d<T: DataType>(&self, row: i32, col: i32) > Result<&T>
[src]
pub fn at_3d_mut<T: DataType>(
&mut self,
i0: i32,
i1: i32,
i2: i32
) > Result<&mut T>
[src]
&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>
[src]
pub fn at_nd_mut<T: DataType>(&mut self, idx: &[i32]) > Result<&mut T>
[src]
pub fn at_nd<T: DataType>(&self, idx: &[i32]) > Result<&T>
[src]
pub fn at_pt_mut<T: DataType>(&mut self, pt: Point) > Result<&mut T>
[src]
pub fn at_pt<T: DataType>(&self, pt: Point) > Result<&T>
[src]
pub fn update_continuity_flag(&mut self) > Result<()>
[src]
impl Send for Mat
[src]
impl ToInputArray for Mat
[src]
pub fn input_array(&self) > Result<_InputArray>
[src]
impl<'_> ToInputArray for &'_ Mat
[src]
pub fn input_array(&self) > Result<_InputArray>
[src]
impl ToInputOutputArray for Mat
[src]
pub fn input_output_array(&mut self) > Result<_InputOutputArray>
[src]
impl<'_> ToInputOutputArray for &'_ mut Mat
[src]
pub fn input_output_array(&mut self) > Result<_InputOutputArray>
[src]
impl ToOutputArray for Mat
[src]
pub fn output_array(&mut self) > Result<_OutputArray>
[src]
impl<'_> ToOutputArray for &'_ mut Mat
[src]
pub fn output_array(&mut self) > Result<_OutputArray>
[src]
impl<T: DataType> TryFrom<Mat> for Mat_<T>
[src]
type Error = Error
The type returned in the event of a conversion error.
pub fn try_from(mat: Mat) > Result<Self, Self::Error>
[src]
impl VectorElement for Mat where
Vector<Mat>: VectorExtern<Mat>,
[src]
Vector<Mat>: VectorExtern<Mat>,
Auto Trait Implementations
impl RefUnwindSafe for Mat
[src]
impl !Sync for Mat
[src]
impl Unpin for Mat
[src]
impl UnwindSafe for Mat
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) > &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) > T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) > Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,