@techstark/opencv-js
Version:
OpenCV JavaScript version for node.js or browser
1,037 lines • 73.9 kB
TypeScript
import type { AccessFlag, bool, double, EmscriptenEmbindInstance, InputArray, int, MatAllocator, MatCommaInitializer_, MatConstIterator_, MatExpr, MatIterator_, MatSize, MatStep, Matx, OutputArray, Point, Point3_, Point_, Rect, Scalar, Size, size_t, typename, uchar, UMat, UMatData, UMatUsageFlags, Vec } from "./_types";
/**
* <a name="d3/d63/classcv_1_1Mat_1CVMat_Details"></a> The class [Mat](#d3/d63/classcv_1_1Mat})
* 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](#dd/da9/classcv_1_1SparseMat}) ). The data layout of the array `M` is
* defined by the array `M.step[]`, so that the address of element `$(i_0,...,i_{M.dims-1})$`, where
* `$0\\leq i_k<M.size[k]$`, is computed as: `\\[addr(M_{i_0,...,i_{M.dims-1}}) = M.data +
* M.step[0]*i_0 + M.step[1]*i_1 + ... + M.step[M.dims-1]*i_{M.dims-1}\\]` In case of a 2-dimensional
* array, the above formula is reduced to: `\\[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\\]`
* 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](#d3/d63/classcv_1_1Mat}) 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](#d3/d63/classcv_1_1Mat}) header for user-allocated data and process it in-place using OpenCV
* functions.
*
* There are many different ways to create a [Mat](#d3/d63/classcv_1_1Mat}) 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.
*
* ```cpp
* // 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()](#d3/d63/classcv_1_1Mat_1a55ced2c8d844d683ea9a725c60037ad0}) 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:
*
* ```cpp
* // 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](#d3/d63/classcv_1_1Mat}) constructor but the
* created array will be 2-dimensional with the number of columns set to 1. So,
* [Mat::dims](#d3/d63/classcv_1_1Mat_1a39cf614aa52567e9a945cd2609bd767b}) 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()](#d3/d63/classcv_1_1Mat_1adff2ea98da45eae0833e73582dd4a660}) 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:
*
* ```cpp
* // 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()](#d3/d63/classcv_1_1Mat_1a40b5b3371a9c2a4b2b8ce0c8068d7c96}):
*
* ```cpp
* 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()](#d3/d63/classcv_1_1Mat_1adff2ea98da45eae0833e73582dd4a660})` 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:
*
* ```cpp
* void process_video_frame(const unsigned char* pixels,
* int width, int height, int step)
* {
* Mat img(height, width, CV_8UC3, pixels, step);
* GaussianBlur(img, img, Size(7,7), 1.5, 1.5);
* }
* ```
*
* Quickly initialize small matrices and/or get a super-fast element access.
*
* ```cpp
* 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()](#d3/d63/classcv_1_1Mat_1a0b57b6a326c8876d944d188a46e0f556}),
* [ones()](#d3/d63/classcv_1_1Mat_1a69ae0402d116fc9c71908d8508dc2f09}),
* [eye()](#d3/d63/classcv_1_1Mat_1a2cf9b9acde7a9852542bbc20ef851ed2}), for example:
*
* ```cpp
* // 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:
*
* ```cpp
* // 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](#d3/d63/classcv_1_1Mat}) 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()](#d3/d63/classcv_1_1Mat_1ae48d4913285518e2c21a3457017e716e}).
*
* 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()](#d3/d63/classcv_1_1Mat_1af2d2652e552d7de635988f18a84b53e5}) ), you can access
* the element `$M_{ij}$` of a 2-dimensional array as:
*
* ```cpp
* 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 [] :
*
* ```cpp
* // 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:
*
* ```cpp
* // 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:
*
* ```cpp
* // 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()](#d2/de8/group__core__array_1ga45dd56da289494ce874be2324856898f}).
*
* Matrix Expressions and arithmetic see [MatExpr](#d1/d10/classcv_1_1MatExpr})
*
* Source:
* [opencv2/core/mat.hpp](https://github.com/opencv/opencv/tree/master/modules/core/include/opencv2/core/mat.hpp#L2073).
*
*/
export declare class Mat extends EmscriptenEmbindInstance {
allocator: MatAllocator;
cols: int;
data: Uint8Array;
data8S: Int8Array;
data8U: Uint8Array;
data16U: Uint16Array;
data16S: Int16Array;
data32U: Uint32Array;
data32S: Int32Array;
data32F: Float32Array;
data64F: Float64Array;
dataend: uchar;
datalimit: uchar;
datastart: uchar;
dims: int;
/**
* includes several bit-fields:
*
* the magic signature
* continuity flag
* depth
* number of channels
*
*/
flags: int;
rows: int;
size: MatSize;
step: MatStep;
u: UMatData;
/**
* 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 de-referenced.
*/
constructor();
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param rows Number of rows in a 2D array.
*
* @param cols Number of columns in a 2D array.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*/
constructor(rows: int, cols: int, type: int);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*/
constructor(size: Size, type: int);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param rows Number of rows in a 2D array.
*
* @param cols Number of columns in a 2D array.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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) .
*/
constructor(rows: int, cols: int, type: int, s: Scalar);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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) .
*/
constructor(size: Size, type: int, s: Scalar);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param ndims Array dimensionality.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*/
constructor(ndims: int, sizes: any, type: int);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*/
constructor(sizes: any, type: int);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param ndims Array dimensionality.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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) .
*/
constructor(ndims: int, sizes: any, type: int, s: Scalar);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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) .
*/
constructor(sizes: any, type: int, s: Scalar);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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 sub-array 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 sub-array, use Mat::clone() .
*/
constructor(m: Mat);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param rows Number of rows in a 2D array.
*
* @param cols Number of columns in a 2D array.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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.
*
* @param 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.
*/
constructor(rows: int, cols: int, type: int, data: any, step?: size_t);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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.
*
* @param 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.
*/
constructor(size: Size, type: int, data: any, step?: size_t);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param ndims Array dimensionality.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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.
*
* @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always
* set to the element size). If not specified, the matrix is assumed to be continuous.
*/
constructor(ndims: int, sizes: any, type: int, data: any, steps?: any);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param sizes Array of integers specifying an n-dimensional array shape.
*
* @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),
* ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
*
* @param 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.
*
* @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always
* set to the element size). If not specified, the matrix is assumed to be continuous.
*/
constructor(sizes: any, type: int, data: any, steps?: any);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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 sub-array 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 sub-array, use Mat::clone() .
*
* @param 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.
*
* @param colRange Range of the m columns to take. Use Range::all() to take all the columns.
*/
constructor(m: Mat, rowRange: Range, colRange?: Range);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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 sub-array 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 sub-array, use Mat::clone() .
*
* @param roi Region of interest.
*/
constructor(m: Mat, roi: Rect);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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 sub-array 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 sub-array, use Mat::clone() .
*
* @param ranges Array of selected ranges of m along each dimensionality.
*/
constructor(m: Mat, ranges: Range);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param 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 sub-array 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 sub-array, use Mat::clone() .
*
* @param ranges Array of selected ranges of m along each dimensionality.
*/
constructor(m: Mat, ranges: Range);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param vec STL vector whose elements form the matrix. The matrix has a single column and the
* number of rows equal to the number of vector elements. Type of the matrix matches the type of vector
* elements. The constructor can handle arbitrary types, for which there is a properly declared
* DataType . This means that the vector elements must be primitive numbers or uni-type numerical
* tuples of numbers. Mixed-type structures are not supported. The corresponding constructor is
* explicit. Since STL vectors are not automatically converted to Mat instances, you should write
* Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements
* will be added to the vector because it can potentially yield vector data reallocation, and, thus,
* the matrix data pointer will be invalid.
*
* @param copyData Flag to specify whether the underlying data of the STL vector should be copied to
* (true) or shared with (false) the newly constructed matrix. When the data is copied, the allocated
* buffer is managed using Mat reference counting mechanism. While the data is shared, the reference
* counter is NULL, and you should not deallocate the data until the matrix is not destructed.
*/
constructor(arg3: any, vec: any, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg4: any, arg5?: typename, list?: any);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg6: any, sizes: any, list: any);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg7: any, _Nm: size_t, arr: any, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg8: any, n: int, vec: Vec, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg9: any, m: int, n: int, mtx: Matx, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg10: any, pt: Point_, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg11: any, pt: Point3_, copyData?: bool);
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
constructor(arg12: any, commaInitializer: MatCommaInitializer_);
constructor(m: any);
constructor(m: Mat);
/**
* 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.
*/
addref(): void;
/**
* 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:
*
* ```cpp
* A.adjustROI(2, 2, 2, 2);
* ```
*
* In this example, the matrix size is increased by 4 elements in each direction. The matrix is
* shifted by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for
* the filtering with the 5x5 kernel.
*
* adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the
* adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is
* located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not
* be increased in the upward direction.
*
* The function is used internally by the OpenCV filtering functions, like filter2D , morphological
* operations, and so on.
*
* [copyMakeBorder]
*
* @param dtop Shift of the top submatrix boundary upwards.
*
* @param dbottom Shift of the bottom submatrix boundary downwards.
*
* @param dleft Shift of the left submatrix boundary to the left.
*
* @param dright Shift of the right submatrix boundary to the right.
*/
adjustROI(dtop: int, dbottom: int, dleft: int, dright: int): Mat;
/**
* The methods return the matrix read-only or read-write iterators. The use of matrix iterators is
* very similar to the use of bi-directional STL iterators. In the example below, the alpha blending
* function is rewritten using the matrix iterators:
*
* ```cpp
* template<typename T>
* void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
* {
* typedef Vec<T, 4> VT;
*
* const float alpha_scale = (float)std::numeric_limits<T>::max(),
* inv_scale = 1.f/alpha_scale;
*
* CV_Assert( src1.type() == src2.type() &&
* src1.type() == traits::Type<VT>::value &&
* src1.size() == src2.size());
* Size size = src1.size();
* dst.create(size, src1.type());
*
* MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end = src1.end<VT>();
* MatConstIterator_<VT> it2 = src2.begin<VT>();
* MatIterator_<VT> dst_it = dst.begin<VT>();
*
* for( ; it1 != it1_end; ++it1, ++it2, ++dst_it )
* {
* VT pix1 = *it1, pix2 = *it2;
* float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale;
* dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta),
* saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta),
* saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta),
* saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale));
* }
* }
* ```
*/
begin(arg25: any): MatIterator_;
begin(arg26: any): MatConstIterator_;
/**
* The method returns the number of matrix channels.
*/
channels(): int;
/**
* -1 if the requirement is not satisfied. Otherwise, it returns the number of elements in the
* matrix. Note that an element may have multiple channels.
* The following code demonstrates its usage for a 2-d matrix:
*
* ```cpp
* cv::Mat mat(20, 1, CV_32FC2);
* int n = mat.checkVector(2);
* CV_Assert(n == 20); // mat has 20 elements
*
* mat.create(20, 2, CV_32FC1);
* n = mat.checkVector(1);
* CV_Assert(n == -1); // mat is neither a column nor a row vector
*
* n = mat.checkVector(2);
* CV_Assert(n == 20); // the 2 columns are considered as 1 element
* ```
*
* The following code demonstrates its usage for a 3-d matrix:
*
* ```cpp
* int dims[] = {1, 3, 5}; // 1 plane, every plane has 3 rows and 5 columns
* mat.create(3, dims, CV_32FC1); // for 3-d mat, it MUST have only 1 channel
* n = mat.checkVector(5); // the 5 columns are considered as 1 element
* CV_Assert(n == 3);
*
* int dims2[] = {3, 1, 5}; // 3 planes, every plane has 1 row and 5 columns
* mat.create(3, dims2, CV_32FC1);
* n = mat.checkVector(5); // the 5 columns are considered as 1 element
* CV_Assert(n == 3);
* ```
*
* @param 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.
*
* @param depth The depth the matrix should have. Set it to -1 when any depth is fine.
*
* @param requireContinuous Set it to true to require the matrix to be continuous
*/
checkVector(elemChannels: int, depth?: int, requireContinuous?: bool): int;
/**
* 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.
*/
clone(): Mat;
/**
* 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.
*
* @param x A 0-based column index.
*/
col(x: int): Mat;
/**
* The method makes a new header for the specified column span of the matrix. Similarly to [Mat::row]
* and [Mat::col] , this is an O(1) operation.
*
* @param startcol An inclusive 0-based start index of the column span.
*
* @param endcol An exclusive 0-based ending index of the column span.
*/
colRange(startcol: int, endcol: int): Mat;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param r Range structure containing both the start and the end indices.
*/
colRange(r: Range): Mat;
/**
* The method converts source pixel values to the target data type. saturate_cast<> is applied at the
* end to avoid possible overflows:
*
* `\\[m(x,y) = saturate \\_ cast<rType>( \\alpha (*this)(x,y) + \\beta )\\]`
*
* @param m output matrix; if it does not have a proper size or type before the operation, it is
* reallocated.
*
* @param 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.
*
* @param alpha optional scale factor.
*
* @param beta optional delta added to the scaled values.
*/
convertTo(m: OutputArray, rtype: int, alpha?: double, beta?: double): OutputArray;
copySize(m: Mat): Mat;
/**
* The method copies the matrix data to another matrix. Before copying the data, the method invokes :
*
*
* ```cpp
* 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.
*
* @param m Destination matrix. If it does not have a proper size or type before the operation, it is
* reallocated.
*/
copyTo(m: OutputArray): OutputArray;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param m Destination matrix. If it does not have a proper size or type before the operation, it is
* reallocated.
*
* @param 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.
*/
copyTo(m: OutputArray, mask: InputArray): OutputArray;
/**
* 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:
*
* ```cpp
* Mat color;
* ...
* Mat gray(color.rows, color.cols, color.depth());
* cvtColor(color, gray, COLOR_BGR2GRAY);
* ```
*
* you can simply write:
*
* ```cpp
* 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.
*
* @param rows New number of rows.
*
* @param cols New number of columns.
*
* @param type New matrix type.
*/
create(rows: int, cols: int, type: int): void;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param size Alternative new matrix size specification: Size(cols, rows)
*
* @param type New matrix type.
*/
create(size: Size, type: int): Size;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param ndims New array dimensionality.
*
* @param sizes Array of integers specifying a new array shape.
*
* @param type New matrix type.
*/
create(ndims: int, sizes: any, type: int): void;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*
* @param sizes Array of integers specifying a new array shape.
*
* @param type New matrix type.
*/
create(sizes: any, type: int): void;
/**
* 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.
*
* @param m Another cross-product operand.
*/
cross(m: InputArray): Mat;
deallocate(): void;
/**
* 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 )
*/
depth(): int;
/**
* 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.
*
* @param 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: Matm=(Mat_<int>(3,3)<<
* 1,2,3,
* 4,5,6,
* 7,8,9);
* Matd0=m.diag(0);
* Matd1=m.diag(1);
* Matd_1=m.diag(-1);
* The resulting matrices are d0=
* [1;
* 5;
* 9]
* d1=
* [2;
* 6]
* d_1=
* [4;
* 8]
*/
diag(d?: int): Mat;
/**
* 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.
*
* @param m another dot-product operand.
*/
dot(m: InputArray): InputArray;
/**
* 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.
*/
elemSize(): size_t;
/**
* 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.
*/
elemSize1(): size_t;
/**
* 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`.
*/
empty(): bool;
/**
* The methods return the matrix read-only or read-write iterators, set to the point following the
* last matrix element.
*/
end(arg27: any): MatIterator_;
end(arg28: any): MatConstIterator_;
/**
* The operation passed as argument has to be a function pointer, a function object or a
* lambda(C++11).
*
* Example 1. All of the operations below put 0xFF the first channel of all matrix elements:
*
* ```cpp
* Mat image(1920, 1080, CV_8UC3);
* typedef cv::Point3_<uint8_t> Pixel;
*
* // first. raw pointer access.
* for (int r = 0; r < image.rows; ++r) {
* Pixel* ptr = image.ptr<Pixel>(r, 0);
* const Pixel* ptr_end = ptr + image.cols;
* for (; ptr != ptr_end; ++ptr) {
* ptr->x = 255;
* }
* }
*
* // Using MatIterator. (Simple but there are a Iterator's overhead)
* for (Pixel &p : cv::Mat_<Pixel>(image)) {
* p.x = 255;
* }
*
* // Parallel execution with function object.
* struct Operator {
* void operator ()(Pixel &pixel, const int * position) {
* pixel.x = 255;
* }
* };
* image.forEach<Pixel>(Operator());
*
* // Parallel execution using C++11 lambda.
* image.forEach<Pixel>([](Pixel &p, const int * position) -> void {
* p.x = 255;
* });
* ```
*
* Example 2. Using the pixel's position:
*
* ```cpp
* // Creating 3D matrix (255 x 255 x 255) typed uint8_t
* // and initialize all elements by the value which equals elements position.
* // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3).
*
* int sizes[] = { 255, 255, 255 };
* typedef cv::Point3_<uint8_t> Pixel;
*
* Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3);
*
* image.forEach<Pixel>([&](Pixel& pixel, const int position[]) -> void {
* pixel.x = position[0];
* pixel.y = position[1];
* pixel.z = position[2];
* });
* ```
*/
forEach(arg29: any, arg30: any, operation: any): any;
/**
* This is an overloaded member function, provided for convenience. It differs from the above
* function only in what argument(s) it accepts.
*/
forEach(arg31: any, arg32: any, operation: any): any;
getUMat(accessFlags: AccessFlag, usageFlags?: UMatUsageFlags): UMat;
/**
* 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.
*
* @param method Matrix inversion method. One of cv::DecompTypes
*/
inv(method?: int): MatExpr;
/**
* 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:
*
* ```cpp
* // 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:
*
* ```cpp
* 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 si