From ef06694779127d79f67ec30b6788175c01278fcd Mon Sep 17 00:00:00 2001 From: Elena Fedotova Date: Thu, 7 Apr 2011 20:29:59 +0000 Subject: [PATCH] Purpose: updated the core chapter --- modules/core/doc/basic_structures.rst | 566 +++++++++++----------- modules/core/doc/clustering.rst | 10 +- modules/core/doc/operations_on_arrays.rst | 390 ++++++++------- 3 files changed, 481 insertions(+), 485 deletions(-) diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index 26a369ae9..7ddaab189 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -629,7 +629,7 @@ However, if the object is deallocated in a different way, then the specialized m **Note** -: The reference increment/decrement operations are implemented as atomic operations, and therefore it is normally safe to use the classes in multi-threaded applications. The same is true for +The reference increment/decrement operations are implemented as atomic operations, and therefore it is normally safe to use the classes in multi-threaded applications. The same is true for :ref:`Mat` and other C++ OpenCV classes that operate on the reference counters. .. _Mat: @@ -693,11 +693,9 @@ There are many different ways to create a ``Mat`` object. Here are some popular * - Use the ``create(nrows, ncols, type)`` method or - the similar ``Mat(nrows, ncols, type[, fillValue])`` constructor. - A new array of the specified size and specifed type is allocated. ``type`` has the same meaning as in + Use the ``create(nrows, ncols, type)`` method or the similar ``Mat(nrows, ncols, type[, fillValue])`` constructor. A new array of the specified size and specifed type is allocated. ``type`` has the same meaning as in :func:`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: + For example, ``CV_8UC1`` means a 8-bit single-channel array, ``CV_32FC2`` means a 2-channel (complex) floating-point array, and so on: :: @@ -709,8 +707,7 @@ There are many different ways to create a ``Mat`` object. Here are some popular .. - As noted in the introduction to this chapter, ``create()`` allocates only a new array when the current array shape - or type are different from the specified ones. + As noted in the introduction to this chapter, ``create()`` allocates only a new array when the current array shape or type are different from the specified ones. * @@ -724,22 +721,15 @@ There are many different ways to create a ``Mat`` object. Here are some popular .. - Note that 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. That is why ``Mat::dims`` is always >= 2 (can also be 0 when the array is empty). + Note that 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. That is why ``Mat::dims`` is always >= 2 (can also be 0 when the array is empty). * - Use a copy constructor or assignment operator, where on the right side it can - be an array or expression (see below). Again, as noted in the introduction, - array assignment is O(1) operation because it only copies the header - and increases the reference counter. ``Mat::clone()`` method can be used to get a full - (a.k.a. deep) copy of the array when you need it. + Use a copy constructor or assignment operator, where on the right side it can be an array or expression (see below). Again, as noted in the introduction, array assignment is O(1) operation because it only copies the header and increases the reference counter. ``Mat::clone()`` method can be used to get a full (a.k.a. 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 will reference the same data. - You can actually modify a part of the array using this feature, for example: + 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 will reference the same data. You can actually modify a part of the array using this feature, for example: :: @@ -777,16 +767,14 @@ There are many different ways to create a ``Mat`` object. Here are some popular .. - As in the case of whole matrices, if you need a deep copy, use the ``clone()`` method - of the extracted sub-matrices. + As in the 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: + Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for ``gstreamer``, and so on). For example: :: @@ -809,9 +797,9 @@ There are many different ways to create a ``Mat`` object. Here are some popular .. - partial yet very common cases of this "user-allocated data" case are conversions from ``CvMat`` and ``IplImage`` to ``Mat``. For this purpose there are special constructors taking pointers to ``CvMat`` or ``IplImage`` and the optional flag indicating whether to copy the data or not. + Partial yet very common cases of this *user-allocated data* case are conversions from ``CvMat`` and ``IplImage`` to ``Mat``. For this purpose, there are special constructors taking pointers to ``CvMat`` or ``IplImage`` and the optional flag indicating whether to copy the data or not. - Backward conversion from ``Mat`` to ``CvMat`` or ``IplImage`` is provided via cast operators ``Mat::operator CvMat() const`` an ``Mat::operator IplImage()``. The operators do *not* copy the data. + Backward conversion from ``Mat`` to ``CvMat`` or ``IplImage`` is provided via cast operators ``Mat::operator CvMat() const`` and ``Mat::operator IplImage()``. The operators do NOT copy the data. :: @@ -825,7 +813,7 @@ There are many different ways to create a ``Mat`` object. Here are some popular * - by using MATLAB-style array initializers, ``zeros(), ones(), eye()`` , e.g.: + Use MATLAB-style array initializers, ``zeros(), ones(), eye()`` , for example: :: @@ -836,32 +824,32 @@ There are many different ways to create a ``Mat`` object. Here are some popular * - by using comma-separated initializer: + Use a comma-separated initializer: :: - // create 3x3 double-precision identity matrix + // create a 3x3 double-precision identity matrix Mat M = (Mat_(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1); .. - here we first call constructor of ``Mat_`` class (that we describe further) with the proper parameters, and then we just put ``<<`` operator followed by comma-separated values that can be constants, variables, expressions etc. Also, note the extra parentheses that are needed to avoid compiler errors. + Here you first call a constructor of the ``Mat_`` class (that will be described further) 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 array is created, it will be automatically managed by using reference-counting mechanism (unless the array header is built on top of user-allocated data, in which case you should handle the data by yourself). -The array data will be 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()`` . +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. Earlier it was shown how to compute address of each array element. Normally, it's not needed to use the formula directly in your code. If you know the array element type (which can be retrieved using the method ``Mat::type()`` ), you can access element -:math:`M_{ij}` of 2-dimensional array as: :: +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, it is not needed to use the formula directly in your code. If you know the array element type (which can be retrieved using the method ``Mat::type()`` ), you can access the element +:math:`M_{ij}` of a 2-dimensional array as: :: M.at(i,j) += 1.f; -assuming that M is double-precision floating-point array. There are several variants of the method ``at`` for different number of dimensions. +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 plain C operator ``[]`` : :: +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 plain C operator ``[]`` : :: // compute sum of positive matrix elements - // (assuming that M is double-precision matrix) + // (assuming that M isa double-precision matrix) double sum=0; for(int i = 0; i < M.rows; i++) { @@ -871,7 +859,7 @@ If you need to process a whole row of a 2d array, the most efficient way is to g } -Some operations, like the above one, 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, e.g. array addition). Such operations are called element-wise and it makes sense to check whether all the input/output arrays are continuous, i.e. have no gaps in the end of each row, and if yes, process them as a single long row: :: +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, that is, have no gaps in the end of each row. If yes, process them as a single long row: :: // compute sum of positive matrix elements, optimized variant double sum=0; @@ -889,7 +877,7 @@ Some operations, like the above one, do not actually depend on the array shape, } -in the case of continuous matrix the outer loop body will be executed just once, so the overhead will be smaller, which will be especially noticeable in the case of small matrices. +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: :: @@ -932,7 +920,7 @@ for a scalar ( ``Scalar`` ), * comparison: - :math:`A\gtreqqless B,\;A \ne B,\;A \gtreqqless \alpha,\;A \ne \alpha`. The result of comparison is 8-bit single channel mask, which elements are set to 255 (if the particular element or pair of elements satisfy the condition) and 0 otherwise. + :math:`A\gtreqqless B,\;A \ne B,\;A \gtreqqless \alpha,\;A \ne \alpha`. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0. * bitwise logical operations: ``A & B, A & s, A | B, A | s, A textasciicircum B, A textasciicircum s, ~ A`` * @@ -945,7 +933,7 @@ for a scalar ( ``Scalar`` ), any function of matrix or matrices and scalars that returns a matrix or a scalar, such as :func:`norm`, :func:`mean`, :func:`sum`, :func:`countNonZero`, :func:`trace`, - :func:`determinant`, :func:`repeat` etc. + :func:`determinant`, :func:`repeat` , and others. * matrix initializers ( ``eye(), zeros(), ones()`` ), matrix comma-separated initializers, matrix constructors and operators that extract sub-matrices (see :ref:`Mat` description). @@ -953,7 +941,7 @@ for a scalar ( ``Scalar`` ), * ``Mat_()`` constructors to cast the result to the proper type. -Note, however, that comma-separated initializers and probably some other operations may require additional explicit ``Mat()`` or ``Mat_()`` constuctor calls to resolve possible ambiguity. +Note, however, that comma-separated initializers and probably some other operations may require additional explicit ``Mat()`` or ``Mat_()`` constuctor calls to resolve a possible ambiguity. Below is the formal description of the ``Mat`` methods. @@ -1003,35 +991,35 @@ Mat::Mat .. c:function:: (20) Mat::Mat(const Mat& m, const Range* ranges) - Various array constructors + Provides various array constructors. - :param ndims: The array dimensionality + :param ndims: Array dimensionality. - :param rows: The number of rows in 2D array + :param rows: The number of rows in a 2D array. - :param cols: The number of columns in 2D array + :param cols: The number of columns in a 2D array. - :param size: The 2D array size: ``Size(cols, rows)`` . Note that in the ``Size()`` constructor the number of rows and the number of columns go in the reverse order. + :param size: 2D array size: ``Size(cols, rows)`` . Note that in the ``Size()`` constructor, the number of rows and the number of columns go in the reverse order. - :param sizes: The array of integers, specifying the n-dimensional array shape + :param sizes: Array of integers specifying an n-dimensional array shape. - :param type: The 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_MAX_CN`` channels) matrices + :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_MAX_CN`` channels) matrices. - :param s: The 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)`` . + :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)`` . - :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, i.e. 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, user should take care of it. + :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: The ``data`` buddy. This optional parameter specifies the number of bytes that each matrix row occupies. The value should include the padding bytes in 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 :ref:`Mat::elemSize` (). + :param step: The number of bytes each matrix row occupies. The value should include the padding bytes in 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 :ref:`Mat::elemSize` (). - :param steps: The array of ``ndims-1`` steps in the case of multi-dimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous. + :param steps: The 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. - :param m: The array that (in whole, a 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 the associated with it reference counter, if any, is incremented. That is, when you modify the matrix formed using such a constructor, you will also modify the corresponding elements of ``m`` . If you want to have an independent copy of the sub-array, use ``Mat::clone()`` . + :param m: The array that (in 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. That is, 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 img: Pointer to the old-style ``IplImage`` image structure. By default, the data is shared between the original image and the new matrix, but when ``copyData`` is set, the full copy of the image data is created. + :param img: Pointer to the old-style ``IplImage`` image structure. By default, the data is shared between the original image and the new matrix. But when ``copyData`` is set, the full copy of the image data is created. - :param vec: STL vector, which elements will form the matrix. The matrix will have a single column and the number of rows equal to the number of vector elements. Type of the matrix will match the type of vector elements. The constructor can handle arbitrary types, for which there is properly declared :ref:`DataType` , i.e. the vector elements must be primitive numbers or uni-type numerical tuples of numbers. Mixed-type structures are not supported, of course. Note that the corresponding constructor is explicit, meaning that STL vectors are not automatically converted to ``Mat`` instances, you should write ``Mat(vec)`` explicitly. Another obvious note: unless you copied the data into the matrix ( ``copyData=true`` ), no new elements should be added to the vector, because it can potentially yield vector data reallocation, and thus the matrix data pointer will become invalid. + :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 :ref:`DataType` . This means that the vector elements must be primitive numbers or uni-type numerical tuples of numbers. Mixed-type structures are not supported. Beware that the corresponding constructor is explicit. Meaning that STL vectors are not automatically converted to ``Mat`` instances, you should write ``Mat(vec)`` explicitly. Note that unless you copied the data into the matrix ( ``copyData=true`` ), no new elements should be added to the vector because it can potentially yield vector data reallocation, and, thus, the matrix data pointer will become invalid. - :param copyData: Specifies, whether the underlying data of the STL vector, or the old-style ``CvMat`` or ``IplImage`` should be copied to (true) or shared with (false) the newly constructed matrix. When the data is copied, the allocated buffer will be managed using ``Mat`` 's reference counting mechanism. While when the data is shared, the reference counter will be NULL, and you should not deallocate the data until the matrix is not destructed. + :param copyData: Flag to specify whether the underlying data of the STL vector, or the old-style ``CvMat`` or ``IplImage``, should be copied to (``true``) or shared with (``false``) the newly constructed matrix. When the data is copied, the allocated buffer will be managed using ``Mat`` 's 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. :param rowRange: The range of the ``m`` 's rows to take. As usual, the range start is inclusive and the range end is exclusive. Use ``Range::all()`` to take all the rows. @@ -1043,8 +1031,8 @@ Mat::Mat :param expr: Matrix expression. See :ref:`MatrixExpressions`. -These are various constructors that form a matrix. As noticed in the -, 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, in which case the old content is dereferenced, or be allocated with +These are various constructors that form a matrix. As noticed in the ?? +, 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, in which case the old content is de-referenced, or be allocated with :ref:`Mat::create` . .. index:: Mat::Mat @@ -1053,7 +1041,7 @@ Mat::~Mat ------------ .. cpp:function:: Mat::~Mat() - Matrix destructor + Provides a matrix destructor. The matrix destructor calls :ref:`Mat::release` . @@ -1068,15 +1056,15 @@ Mat::operator = .. cpp:function:: Mat& operator = (const Scalar& s) - Matrix assignment operators + Provides matrix assignment operators. - :param m: The assigned, right-hand-side matrix. Matrix assignment is O(1) operation, that is, no data is copied. Instead, the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is dereferenced via :ref:`Mat::release` . + :param m: The assigned, right-hand-side matrix. Matrix assignment is O(1) operation, that is, no data is copied. Instead, the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is de-referenced via :ref:`Mat::release` . - :param expr: The assigned matrix expression object. As opposite to the first form of assignment operation, the second form can reuse already allocated matrix if it has the right size and type to fit the matrix expression result. It is automatically handled by the real function that the matrix expressions is expanded to. For example, ``C=A+B`` is expanded to ``add(A, B, C)`` , and :func:`add` will take care of automatic ``C`` reallocation. + :param expr: The assigned matrix expression object. As opposite to the first form of assignment operation, the second form can reuse already allocated matrix if it has the right size and type to fit the matrix expression result. It is automatically handled by the real function that the matrix expressions is expanded to. For example, ``C=A+B`` is expanded to ``add(A, B, C)`` , and :func:`add` takes care of automatic ``C`` reallocation. - :param s: The scalar, assigned to each matrix element. The matrix size or type is not changed. + :param s: The scalar assigned to each matrix element. The matrix size or type is not changed. -These are the available assignment operators, and they all are very different, so, please, look at the operator parameters description. +These are available assignment operators. Since they all are very different, make sure to read the operator parameters description. .. index:: Mat::operator MatExpr @@ -1084,7 +1072,7 @@ Mat::operator MatExpr ------------------------- .. cpp:function:: Mat::operator MatExpr_() const - Mat-to-MatExpr cast operator + Provides a ``Mat`` -to- ``MatExpr`` cast operator. The cast operator should not be called explicitly. It is used internally by the :ref:`MatrixExpressions` engine. @@ -1097,11 +1085,11 @@ Mat::row ------------ .. cpp:function:: Mat Mat::row(int i) const - Makes a matrix header for the specified matrix row + Creates a matrix header for the specified matrix row. - :param i: the 0-based row index + :param i: A 0-based row index. -The method makes a new header for the specified matrix row and returns it. This is O(1) operation, regardless of the matrix size. The underlying data of the new matrix will be 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: :: +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) { @@ -1109,15 +1097,16 @@ The method makes a new header for the specified matrix row and returns it. This } -**Important note** -. In the current implementation the following code will not work as expected: :: +**Warning** + +In the current implementation the following code does not work as expected: :: Mat A; ... A.row(i) = A.row(j); // will not work -This is because ``A.row(i)`` forms a temporary header, which is further assigned another header. Remember, each of these operations is O(1), i.e. no data is copied. Thus, the above assignment will have absolutely no effect, while you may have expected j-th row being copied to i-th row. To achieve that, you should either turn this simple assignment into an expression, or use +This is because ``A.row(i)`` forms a temporary header, which 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 will have absolutely no effect, while 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 :ref:`Mat::copyTo` method: :: Mat A; @@ -1125,7 +1114,7 @@ This is because ``A.row(i)`` forms a temporary header, which is further assigned // works, but looks a bit obscure. A.row(i) = A.row(j) + 0; - // this is a bit longer, but the recommended method. + // this is a bit longe, but the recommended method. Mat Ai = A.row(i); M.row(j).copyTo(Ai); @@ -1137,11 +1126,11 @@ Mat::col ------------ .. cpp:function:: Mat Mat::col(int j) const - Makes a matrix header for the specified matrix column + Creates a matrix header for the specified matrix column. - :param j: the 0-based column index + :param j: A 0-based column index. -The method makes a new header for the specified matrix column and returns it. This is O(1) operation, regardless of the matrix size. The underlying data of the new matrix will be shared with the original matrix. See also +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 :ref:`Mat::row` description. .. index:: Mat::rowRange @@ -1154,17 +1143,17 @@ Mat::rowRange .. cpp:function:: Mat Mat::rowRange(const Range& r) const - Makes a matrix header for the specified row span + Creates a matrix header for the specified row span. - :param startrow: the 0-based start index of the row span + :param startrow: A 0-based start index of the row span. - :param endrow: the 0-based ending index of the row span + :param endrow: A 0-based ending index of the row span. - :param r: The :func:`Range` structure containing both the start and the end indices + :param r: The :func:`Range` structure containing both the start and the end indices. The method makes a new header for the specified row span of the matrix. Similarly to :func:`Mat::row` and -:func:`Mat::col` , this is O(1) operation. +:func:`Mat::col` , this is an O(1) operation. .. index:: Mat::colRange @@ -1176,17 +1165,17 @@ Mat::colRange .. cpp:function:: Mat Mat::colRange(const Range& r) const - Makes a matrix header for the specified row span + Creates a matrix header for the specified row span. - :param startcol: the 0-based start index of the column span + :param startcol: A 0-based start index of the column span. - :param endcol: the 0-based ending index of the column span + :param endcol: A 0-based ending index of the column span. - :param r: The :func:`Range` structure containing both the start and the end indices + :param r: The :func:`Range` structure containing both the start and the end indices. The method makes a new header for the specified column span of the matrix. Similarly to :func:`Mat::row` and -:func:`Mat::col` , this is O(1) operation. +:func:`Mat::col` , this is an O(1) operation. .. index:: Mat::diag @@ -1198,21 +1187,21 @@ Mat::diag .. cpp:function:: static Mat Mat::diag(const Mat& matD) - Extracts diagonal from a matrix, or creates a diagonal matrix. + Extracts a diagonal from a matrix, or creates a diagonal matrix. - :param d: index of the diagonal, with the following meaning: + :param d: Index of the diagonal, with the following values: * **d=0** the main diagonal - * **d>0** a diagonal from the lower half, e.g. ``d=1`` means the diagonal immediately below the main one + * **d>0** a diagonal from the lower half. For example, ``d=1`` means the diagonal is set immediately below the main one. - * **d<0** a diagonal from the upper half, e.g. ``d=1`` means the diagonal immediately above the main one + * **d<0** a diagonal from the upper half. For example, ``d=1`` means the diagonal is set immediately above the main one. - :param matD: single-column matrix that will form the diagonal matrix. + :param matD: A single-column matrix that forms the diagonal matrix. -The method makes a new header for the specified matrix diagonal. The new matrix will be represented as a single-column matrix. Similarly to +The method makes a new header for the specified matrix diagonal. The new matrix is represented as a single-column matrix. Similarly to :func:`Mat::row` and -:func:`Mat::col` , this is O(1) operation. +:func:`Mat::col` , this is an O(1) operation. .. index:: Mat::clone @@ -1222,9 +1211,9 @@ Mat::clone -------------- .. cpp:function:: Mat Mat::clone() const - Creates full copy of the array and the underlying data. + Creates a full copy of the array and the underlying data. -The method creates full copy of the array. The original ``step[]`` are not taken into the account. That is, the array copy will be a continuous array occupying ``total()*elemSize()`` bytes. +The method creates a full copy of the array. The original ``step[]`` are not taken into account. That is, the array copy is a continuous array occupying ``total()*elemSize()`` bytes. .. index:: Mat::copyTo @@ -1237,16 +1226,16 @@ Mat::copyTo Copies the matrix to another one. - :param m: The destination matrix. If it does not have a proper size or type before the operation, it will be reallocated + :param m: The destination matrix. If it does not have a proper size or type before the operation, it is reallocated. - :param mask: The operation mask. Its non-zero elements indicate, which matrix elements need to be copied + :param mask: The operation mask. Its non-zero elements indicate which matrix elements need to be copied. 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);`` will work as expected, i.e. will have no effect, the function does not handle the case of a partial overlap between the source and the destination matrices. +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, and the ``Mat::create`` call shown above reallocated the matrix, the newly allocated matrix is initialized with all 0's before copying the data. @@ -1258,17 +1247,17 @@ Mat::convertTo ------------------ .. cpp:function:: void Mat::convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const - Converts array to another datatype with optional scaling. + Converts an array to another datatype with optional scaling. - :param m: The destination matrix. If it does not have a proper size or type before the operation, it will be reallocated + :param m: The destination matrix. If it does not have a proper size or type before the operation, it is reallocated. - :param rtype: The desired destination matrix type, or rather, the depth (since the number of channels will be the same with the source one). If ``rtype`` is negative, the destination matrix will have the same type as the source. + :param rtype: The desired destination matrix type, or rather, the depth (since the number of channels are the same as the source has). If ``rtype`` is negative, the destination matrix will have the same type as the source. - :param alpha: The optional scale factor + :param alpha: The optional scale factor. - :param beta: The optional delta, added to the scaled values. + :param beta: The optional delta added to the scaled values. -The method converts source pixel values to the target datatype. ``saturate_cast<>`` is applied in the end to avoid possible overflows: +The method converts source pixel values to the target datatype. ``saturate_cast<>`` is applied at the end to avoid possible overflows: .. math:: @@ -1280,13 +1269,13 @@ Mat::assignTo ----------------- .. cpp:function:: void Mat::assignTo( Mat& m, int type=-1 ) const - Functional form of convertTo + Provides a functional form of ``convertTo``. - :param m: The destination array + :param m: The destination array. - :param type: The desired destination array depth (or -1 if it should be the same as the source one). + :param type: The desired destination array depth (or -1 if it should be the same as the source type). -This is internal-use method called by the +This is an internally used method called by the :ref:`MatrixExpressions` engine. .. index:: Mat::setTo @@ -1297,9 +1286,9 @@ Mat::setTo Sets all or some of the array elements to the specified value. - :param s: Assigned scalar, which is converted to the actual array type + :param s: Assigned scalar converted to the actual array type. - :param mask: The operation mask of the same size as ``*this`` This is the advanced variant of ``Mat::operator=(const Scalar& s)`` operator. + :param mask: Operation mask of the same size as ``*this``. This is an advanced variant of the ``Mat::operator=(const Scalar& s)`` operator. .. index:: Mat::reshape @@ -1315,15 +1304,14 @@ Mat::reshape The method makes a new matrix header for ``*this`` elements. The new matrix may have different size and/or different number of channels. Any combination is possible, as long as: -#. - No extra elements is included into the new matrix and no elements are excluded. Consequently, - the product ``rows*cols*channels()`` must stay the same after the transformation. +* + No extra elements is 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, i.e. this is O(1) operation. Consequently, if you change the number of rows, or the operation changes elements' row indices in some other way, the matrix must be continuous. See +* + 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 :func:`Mat::isContinuous` . -Here is some small example. Assuming, there is a set of 3D points that are stored as STL vector, and you want to represent the points as ``3xN`` matrix. Here is how it can be done: :: +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 vec; ... @@ -1332,7 +1320,7 @@ Here is some small example. Assuming, there is a set of 3D points that are store 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 of all the elements + // This involves copying all the elements .. index:: Mat::t @@ -1341,10 +1329,9 @@ Mat::t ---------- .. cpp:function:: MatExpr Mat::t() const - Transposes the matrix + 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 expression or be assigned to 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 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) @@ -1356,17 +1343,17 @@ Mat::inv ------------ .. cpp:function:: MatExpr Mat::inv(int method=DECOMP_LU) const - Inverses the matrix + Inverses a matrix. - :param method: The matrix inversion method, one of + :param method: The matrix inversion method. Possible values are the following: - * **DECOMP_LU** LU decomposition. The matrix must be non-singular + * **DECOMP_LU** LU decomposition. The matrix must be non-singular. - * **DECOMP_CHOLESKY** Cholesky :math:`LL^T` decomposition, for symmetrical positively defined matrices only. About twice faster than LU on big matrices. + * **DECOMP_CHOLESKY** Cholesky :math:`LL^T` decomposition, for symmetrical positively defined matrices only. This type is about twice faster than LU on big matrices. - * **DECOMP_SVD** SVD decomposition. The matrix can be a singular or even non-square, then the pseudo-inverse is computed + * **DECOMP_SVD** SVD decomposition. If the matrix is singular or even non-square, the pseudo inversion is computed. -The method performs matrix inversion by means of matrix expressions, i.e. a temporary "matrix inversion" object is returned by the method, and can further be used as a part of more complex matrix expression or be assigned to a matrix. +The method performs matrix inversion by means of matrix expressions. This means that a temporary "matrix inversion" object is returned by the method and can further be used as a part of more complex matrix expression or be assigned to a matrix. .. index:: Mat::mul @@ -1376,15 +1363,15 @@ Mat::mul .. cpp:function:: MatExpr Mat::mul(const MatExpr& m, double scale=1) const - Performs element-wise multiplication or division of the two matrices + Performs an element-wise multiplication or division of the two matrices. - :param m: Another matrix, of the same type and the same size as ``*this`` , or a matrix expression + :param m: Another matrix of the same type and the same size as ``*this`` , or a matrix expression. - :param scale: The optional scale factor + :param scale: Optional scale factor. -The method returns a temporary object encoding per-element array multiplication, with optional scale. Note that this is not a matrix multiplication, which corresponds to a simpler "*" operator. +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. -Here is a example: :: +Here is an example: :: Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5) @@ -1395,11 +1382,11 @@ Mat::cross -------------- .. cpp:function:: Mat Mat::cross(const Mat& m) const - Computes cross-product of two 3-element vectors + Computes a cross-product of two 3-element vectors. - :param m: Another cross-product operand + :param m: Another cross-product operand. -The method computes cross-product of the two 3-element vectors. The vectors must be 3-elements floating-point vectors of the same shape and the same size. The result will be another 3-element vector of the same shape and the same type as operands. +The method computes a cross-product of two 3-element vectors. The vectors must be 3-elements floating-point vectors of the same shape and the same size. The result is another 3-element vector of the same shape and the same type as operands. .. index:: Mat::dot @@ -1407,11 +1394,11 @@ Mat::dot ------------ .. cpp:function:: double Mat::dot(const Mat& m) const - Computes dot-product of two vectors + Computes a dot-product of two vectors. :param m: Another dot-product operand. -The method computes dot-product of the 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 the same type. If the matrices have more than one channel, the dot products from all the channels are summed together. +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 the same type. If the matrices have more than one channel, the dot products from all the channels are summed together. .. index:: Mat::zeros @@ -1421,25 +1408,27 @@ Mat::zeros .. cpp:function:: static MatExpr Mat::zeros(Size size, int type) .. cpp:function:: static MatExpr Mat::zeros(int ndims, const int* sizes, int type) - Returns zero array of the specified size and type + Returns a zero array of the specified size and type. - :param ndims: The array dimensionality + :param ndims: Array dimensionality. - :param rows: The number of rows + :param rows: The number of rows. - :param cols: The number of columns + :param cols: The number of columns. - :param size: Alternative matrix size specification: ``Size(cols, rows)`` :param sizes: The array of integers, specifying the array shape + :param size: Alternative matrix size specification: ``Size(cols, rows)`` + + :param sizes: An array of integers specifying the array shape. - :param type: The created matrix type + :param type: Created matrix type. -The method returns Matlab-style zero array initializer. It can be used to quickly form a constant array and use it as a function parameter, as a part of matrix expression, or as a matrix initializer. :: +The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant array and use it as a function parameter, as a part of matrix expression, or as a matrix initializer. :: Mat A; A = Mat::zeros(3, 3, CV_32F); -Note that in the above sample a new matrix will be allocated only if ``A`` is not 3x3 floating-point matrix, otherwise the existing matrix ``A`` will be filled with 0's. +Note that in the sample above a new matrix will be allocated only if ``A`` is not a 3x3 floating-point matrix. Otherwise, the existing matrix ``A`` will be filled with 0's. .. index:: Mat::ones @@ -1449,25 +1438,27 @@ Mat::ones .. cpp:function:: static MatExpr Mat::ones(Size size, int type) .. cpp:function:: static MatExpr Mat::ones(int ndims, const int* sizes, int type) - Returns array of all 1's of the specified size and type + Returns an array of all 1's of the specified size and type. - :param ndims: The array dimensionality + :param ndims: Array dimensionality. - :param rows: The number of rows + :param rows: The number of rows. - :param cols: The number of columns + :param cols: The number of columns. - :param size: Alternative matrix size specification: ``Size(cols, rows)`` :param sizes: The array of integers, specifying the array shape + :param size: Alternative matrix size specification: ``Size(cols, rows)`` + + :param sizes: An array of integers specifying the array shape. - :param type: The created matrix type + :param type: Created matrix type. -The method returns Matlab-style ones' array initializer, similarly to -:func:`Mat::zeros` . Note that using this method you can initialize an array with arbitrary value, using the following Matlab idiom: :: +The method returns a Matlab-style 1's array initializer, similarly to +:func:`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 will not form 100x100 matrix of ones and then multiply it by 3. Instead, it will just remember the scale factor (3 in this case) and use it when actually invoking the matrix initializer. +The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it will just remember the scale factor (3 in this case) and use it when actually invoking the matrix initializer. .. index:: Mat::eye @@ -1476,15 +1467,17 @@ Mat::eye .. cpp:function:: static MatExpr Mat::eye(int rows, int cols, int type) .. cpp:function:: static MatExpr Mat::eye(Size size, int type) - Returns identity matrix of the specified size and type + Returns an identity matrix of the specified size and type. - :param rows: The number of rows + :param rows: The number of rows. - :param cols: The number of columns + :param cols: The number of columns. - :param size: Alternative matrix size specification: ``Size(cols, rows)`` :param type: The created matrix type + :param size: Alternative matrix size specification: ``Size(cols, rows)`` . + + :param type: Created matrix type. -The method returns Matlab-style identity matrix initializer, similarly to +The method returns a Matlab-style identity matrix initializer, similarly to :func:`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. @@ -1503,33 +1496,35 @@ Mat::create Allocates new array data if needed. - :param ndims: The new array dimensionality + :param ndims: New array dimensionality. - :param rows: The new number of rows + :param rows: New number of rows. - :param cols: The new number of columns + :param cols: New number of columns. - :param size: Alternative new matrix size specification: ``Size(cols, rows)`` :param sizes: The array of integers, specifying the new array shape + :param size: Alternative new matrix size specification: ``Size(cols, rows)`` + + :param sizes: An array of integers specifying the new array shape. - :param type: The new matrix type + :param type: New matrix type. 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. + If the current array shape and the type match the new ones, return immediately. #. - otherwise, dereference the previous data by calling + Otherwise, de-reference the previous data by calling :func:`Mat::release` #. initialize the new header #. - allocate the new data of ``total()*elemSize()`` bytes + Allocate the new data of ``total()*elemSize()`` bytes. #. - allocate the new, associated with the data, reference counter and set it to 1. + 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 also saves quite a bit of typing for the user, i.e. usually there is no need to explicitly allocate output arrays. That is, instead of writing: :: +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; ... @@ -1545,7 +1540,7 @@ you can simply write: :: cvtColor(color, gray, CV_BGR2GRAY); -because ``cvtColor`` , as well as most of OpenCV functions, calls Mat::create() for the output array internally. +because ``cvtColor`` , as well as the most of OpenCV functions, calls ``Mat::create()`` for the output array internally. .. index:: Mat::addref @@ -1555,10 +1550,10 @@ Mat::addref --------------- .. cpp:function:: void Mat::addref() - Increments the reference counter + Increments the reference counter. -The method increments the reference counter, associated with the matrix data. If the matrix header points to an external data (see -:func:`Mat::Mat` ), the reference counter is NULL, and the method has no effect in this case. Normally, the method should not be called explicitly, to avoid memory leaks. It is called implicitly by the matrix assignment operator. The reference counter increment is the atomic operation on the platforms that support it, thus it is safe to operate on the same matrices asynchronously in different threads. +The method increments the reference counter associated with the matrix data. If the matrix header points to an external data set (see +:func:`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. .. index:: Mat::release @@ -1568,12 +1563,12 @@ Mat::release ---------------- .. cpp:function:: void Mat::release() - Decrements the reference counter and deallocates the matrix if needed + 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 (see +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 :func:`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 the atomic operation on the platforms that support it, thus it is safe to operate on the same matrices asynchronously in different threads. +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. .. index:: Mat::resize @@ -1583,11 +1578,11 @@ Mat::resize --------------- .. cpp:function:: void Mat::resize( size_t sz ) const - Changes the number of matrix rows + Changes the number of matrix rows. - :param sz: The new number of rows + :param sz: The new number of rows. -The method changes the number of matrix rows. If the matrix is reallocated, the first ``min(Mat::rows, sz)`` rows are preserved. The method emulates the corresponding method of STL vector class. +The method changes the number of matrix rows. If the matrix is reallocated, the first ``min(Mat::rows, sz)`` rows are preserved. The method emulates the corresponding method of the STL vector class. .. index:: Mat::push_back @@ -1598,11 +1593,11 @@ Mat::push_back .. c:function:: template void Mat::push_back(const T& elem) .. c:function:: template void Mat::push_back(const Mat_& elem) - Adds elements to the bottom of the matrix + Adds elements to the bottom of the matrix. - :param elem: The added element(s). + :param elem: Added element(s). -The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of STL vector class. When ``elem`` is ``Mat`` , its type and the number of columns must be the same as in the container 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. .. index:: Mat::pop_back @@ -1614,7 +1609,7 @@ Mat::pop_back Removes elements from the bottom of the matrix. - :param nelems: The number of rows removed. If it is greater than the total number of rows, an exception is thrown. + :param nelems: The number of removed rows. If it is greater than the total number of rows, an exception is thrown. The method removes one or more rows from the bottom of the matrix. @@ -1626,14 +1621,14 @@ Mat::locateROI ------------------ .. cpp:function:: void Mat::locateROI( Size& wholeSize, Point& ofs ) const - Locates matrix header within a parent matrix + Locates the matrix header within a parent matrix. - :param wholeSize: The output parameter that will contain size of the whole matrix, which ``*this`` is a part of. + :param wholeSize: An output parameter that contains the size of the whole matrix, which ``*this`` is a part of.?? - :param ofs: The output parameter that will contain offset of ``*this`` inside the whole matrix + :param ofs: An output parameter that contains an offset of ``*this`` inside the whole matrix. After you extracted a submatrix from a matrix using -:func:`Mat::row`,:func:`Mat::col`,:func:`Mat::rowRange`,:func:`Mat::colRange` etc., the result submatrix will point just to the part of the original big matrix. However, each submatrix contains some information (represented by ``datastart`` and ``dataend`` fields), using which it is possible to reconstruct the original matrix size and the position of the extracted submatrix within the original matrix. The method ``locateROI`` does exactly that. +:func:`Mat::row`,:func:`Mat::col`,:func:`Mat::rowRange`,:func:`Mat::colRange` , and others, the resultant submatrix will point just to the part of the original big matrix. However, each submatrix contains some 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. .. index:: Mat::adjustROI @@ -1643,31 +1638,31 @@ Mat::adjustROI ------------------ .. cpp:function:: Mat& Mat::adjustROI( int dtop, int dbottom, int dleft, int dright ) - Adjust submatrix size and position within the parent matrix + Adjusts a submatrix size and position within the parent matrix. - :param dtop: The shift of the top submatrix boundary upwards + :param dtop: The shift of the top submatrix boundary upwards. - :param dbottom: The shift of the bottom submatrix boundary downwards + :param dbottom: The shift of the bottom submatrix boundary downwards. - :param dleft: The shift of the left submatrix boundary to the left + :param dleft: The shift of the left submatrix boundary to the left. - :param dright: The shift of the right submatrix boundary to the right + :param dright: The shift of the right submatrix boundary to the right. -The method is complimentary to the -:func:`Mat::locateROI` . Indeed, 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 needed for filtering operations, when pixels outside of the ROI should be taken into account. When all the method's parameters are positive, it means that the ROI needs to grow in all directions by the specified amount, i.e. :: +The method is complimentary to +:func:`Mat::locateROI` . Indeed, 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); -increases the matrix size by 4 elements in each direction and shifts it by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the filtering with 5x5 kernel. +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 5x5 kernel. -It's user responsibility to make sure that adjustROI does not cross the parent matrix boundary. If it does, the function will signal an error. +It is your responsibility to make sure ``adjustROI`` does not cross the parent matrix boundary. If it does, the function signals an error. The function is used internally by the OpenCV filtering functions, like -:func:`filter2D` , morphological operations etc. +:func:`filter2D` , morphological operations, and so on. -See also -:func:`copyMakeBorder` . +See Also +:func:`copyMakeBorder` .. index:: Mat::operator() @@ -1681,15 +1676,19 @@ Mat::operator() .. cpp:function:: Mat Mat::operator()( const Ranges* ranges ) const - Extracts a rectangular submatrix + Extracts a rectangular submatrix. - :param rowRange: The start and the end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use ``Range::all()`` :param colRange: The start and the end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use ``Range::all()`` :param roi: The extracted submatrix specified as a rectangle + :param rowRange: The start and the end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use `Range::all()``. + + :param colRange: The start and the end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use ``Range::all()`` . + + :param roi: The extracted submatrix specified as a rectangle. - :param ranges: The array of selected ranges along each array dimension + :param ranges: The array of selected ranges along each array dimension. The operators make a new header for the specified sub-array of ``*this`` . They are the most generalized forms of -:func:`Mat::row`,:func:`Mat::col`,:func:`Mat::rowRange` and -:func:`Mat::colRange` . For example, ``A(Range(0, 10), Range::all())`` is equivalent to ``A.rowRange(0, 10)`` . Similarly to all of the above, the operators are O(1) operations, i.e. no matrix data is copied. +:func:`Mat::row`,:func:`Mat::col`,:func:`Mat::rowRange`, and +:func:`Mat::colRange` . For example, ``A(Range(0, 10), Range::all())`` is equivalent to ``A.rowRange(0, 10)`` . Similarly to all of the above, the operators are O(1) operations, that is, no matrix data is copied. .. index:: Mat::operator CvMat @@ -1697,9 +1696,9 @@ Mat::operator CvMat ----------------------- .. cpp:function:: Mat::operator CvMat(void) const - Creates CvMat header for the matrix + Creates the ``CvMat`` header for the matrix. -The operator makes CvMat header for the matrix without copying the underlying data. The reference counter is not taken into account by this operation, thus you should make sure than the original matrix is not deallocated while the ``CvMat`` header is used. The operator is useful for intermixing the new and the old OpenCV API's, e.g: :: +The operator creates the ``CvMat`` header for the matrix without copying the underlying data. The reference counter is not taken into account by this operation. Thus, you should make sure than the original matrix is not deallocated while the ``CvMat`` header is used. The operator is useful for intermixing the new and the old OpenCV API's, for example: :: Mat img(Size(320, 240), CV_8UC3); ... @@ -1708,7 +1707,7 @@ The operator makes CvMat header for the matrix without copying the underlying da mycvOldFunc( &cvimg, ...); -where ``mycvOldFunc`` is some function written to work with OpenCV 1.x data structures. +where ``mycvOldFunc`` is a function written to work with OpenCV 1.x data structures. .. index:: Mat::operator IplImage @@ -1716,9 +1715,9 @@ Mat::operator IplImage -------------------------- .. cpp:function:: Mat::operator IplImage(void) const - Creates IplImage header for the matrix + Creates the ``IplImage`` header for the matrix. -The operator makes IplImage header for the matrix without copying the underlying data. You should make sure than the original matrix is not deallocated while the ``IplImage`` header is used. Similarly to ``Mat::operator CvMat`` , the operator is useful for intermixing the new and the old OpenCV API's. +The operator creates the ``IplImage`` header for the matrix without copying the underlying data. You should make sure than the original matrix is not deallocated while the ``IplImage`` header is used. Similarly to ``Mat::operator CvMat`` , the operator is useful for intermixing the new and the old OpenCV API's. .. index:: Mat::total @@ -1730,7 +1729,7 @@ Mat::total Returns the total number of array elements. -The method returns the number of array elements (e.g. number of pixels if the array represents an image). +The method returns the number of array elements (a number of pixels if the array represents an image). .. index:: Mat::isContinuous @@ -1740,13 +1739,13 @@ Mat::isContinuous --------------------- .. cpp:function:: bool Mat::isContinuous(void) const - Reports whether the matrix is continuous or not + Reports whether the matrix is continuous or not. -The method returns true if the matrix elements are stored continuously, i.e. without gaps in the end of each row, and false otherwise. Obviously, ``1x1`` or ``1xN`` matrices are always continuous. Matrices created with -:func:`Mat::create` are always continuous, but if you extract a part of the matrix using -:func:`Mat::col`,:func:`Mat::diag` etc. or constructed a matrix header for externally allocated data, such matrices may no longer have this property. +The method returns ``true`` if the matrix elements are stored continuously - without gaps in the end of each row. Otherwise, it returns ``false``. Obviously, ``1x1`` or ``1xN`` matrices are always continuous. Matrices created with +:func:`Mat::create` are always continuous. But if you extract a part of the matrix using +:func:`Mat::col`,:func:`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 ``Mat::flags`` field, and is computed automatically when you construct a matrix header, thus the continuity check is very fast operation, though it could be, in theory, done as following: :: +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 it could be, in theory, done as following: :: // alternative implementation of Mat::isContinuous() bool myCheckMatContinuity(const Mat& m) @@ -1756,7 +1755,7 @@ The continuity flag is stored as a bit in ``Mat::flags`` field, and is computed } -The method is used in a quite a few of OpenCV functions, and you are welcome to use it as well. The point is that element-wise operations (such as arithmetic and logical operations, math functions, alpha blending, color space transformations etc.) do not depend on the image geometry, and thus, if all the input and all the output arrays are continuous, the functions can process them as very long single-row vectors. Here is the example of how alpha-blending function can be implemented. :: +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. Here is the example of how an alpha-blending function can be implemented. :: template void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) @@ -1802,7 +1801,7 @@ The method is used in a quite a few of OpenCV functions, and you are welcome to This trick, while being very simple, can boost performance of a simple element-operation by 10-20 percents, especially if the image is rather small and the operation is quite simple. -Also, note that we use another OpenCV idiom in this function - we call +Also, note that there is another OpenCV idiom in this function: a call of :func:`Mat::create` for the destination array instead of checking that it already has the proper size and type. And while the newly allocated arrays are always continuous, we still check the destination array, because :func:`create` does not always allocate a new matrix. @@ -1814,9 +1813,9 @@ Mat::elemSize ----------------- .. cpp:function:: size_t Mat::elemSize(void) const - Returns matrix element size in bytes + 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 will return ``3*sizeof(short)`` or 6. +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. .. index:: Mat::elemSize1 @@ -1826,9 +1825,9 @@ Mat::elemSize1 ------------------ .. cpp:function:: size_t Mat::elemSize1(void) const - Returns size of each matrix element channel in bytes + 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 will return ``sizeof(short)`` or 2. +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. .. index:: Mat::type @@ -1838,9 +1837,9 @@ Mat::type ------------- .. cpp:function:: int Mat::type(void) const - Returns matrix element type + Returns a matrix element type. -The method returns the matrix element type, an id, compatible with the ``CvMat`` type system, like ``CV_16SC3`` or 16-bit signed 3-channel array etc. +The method returns a matrix element type. This is an id, compatible with the ``CvMat`` type system, like ``CV_16SC3`` or 16-bit signed 3-channel array, and so on. .. index:: Mat::depth @@ -1850,9 +1849,9 @@ Mat::depth -------------- .. cpp:function:: int Mat::depth(void) const - Returns matrix element depth + Returns the matrix element depth. -The method returns the matrix element depth id, i.e. the type of each individual channel. For example, for 16-bit signed 3-channel array the method will return ``CV_16S`` . The complete list of matrix types: +The method returns the matrix element depth id (the type of each individual channel). For example, for a 16-bit signed 3-channel array, the method returns ``CV_16S`` . A complete list of matrix types: * ``CV_8U`` - 8-bit unsigned integers ( ``0..255`` ) @@ -1876,7 +1875,7 @@ Mat::channels ----------------- .. cpp:function:: int Mat::channels(void) const - Returns matrix element depth + Returns a matrix element depth. The method returns the number of matrix channels. @@ -1888,10 +1887,10 @@ Mat::step1 -------------- .. cpp:function:: size_t Mat::step1(void) const - Returns normalized step + Returns a normalized step. -The method returns the matrix step, divided by -:func:`Mat::elemSize1()` . It can be useful for fast access to arbitrary matrix element. +The method returns a matrix step divided by +:func:`Mat::elemSize1()` . It can be useful to quickly access an arbitrary matrix element. .. index:: Mat::size @@ -1901,9 +1900,9 @@ Mat::size ------------- .. cpp:function:: Size Mat::size(void) const - Returns the matrix size + Returns a matrix size. -The method returns the matrix size: ``Size(cols, rows)`` . +The method returns a matrix size: ``Size(cols, rows)`` . .. index:: Mat::empty @@ -1913,9 +1912,9 @@ Mat::empty -------------- .. cpp:function:: bool Mat::empty(void) const - Returns true if the array has no elemens + Returns ``true`` if the array has no elemens. -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`` . +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`` . .. index:: Mat::ptr @@ -1931,12 +1930,12 @@ Mat::ptr .. c:function:: template const _Tp* Mat::ptr(int i=0) const - Return pointer to the specified matrix row + Returns a pointer to the specified matrix row. - :param i: The 0-based row index + :param i: A 0-based row index. The methods return ``uchar*`` or typed pointer to the specified matrix row. See the sample in -:func:`Mat::isContinuous` () on how to use these methods. +:func:`Mat::isContinuous` () to know how to use these methods. .. index:: Mat::at @@ -1964,15 +1963,17 @@ Mat::at .. c:function:: template const T& Mat::at(const int* idx) const - Return reference to the specified array element + Returns a reference to the specified array element. - :param i, j, k: Indices along the dimensions 0, 1 and 2, respectively + :param i, j, k: Indices along the dimensions 0, 1, and 2, respectively. - :param pt: The element position specified as ``Point(j,i)`` :param idx: The array of ``Mat::dims`` indices + :param pt: An element position specified as ``Point(j,i)`` . + + :param idx: An array of ``Mat::dims`` indices. -The template methods return reference to the specified array element. For the sake of higher performance the index range checks are only performed in Debug configuration. +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 ``1 x N`` floating-point matrix and ``B`` is ``M x 1`` integer matrix, you can simply write ``A.at(k+4)`` and ``B.at(2*i+1)`` instead of ``A.at(0,k+4)`` and ``B.at(2*i+1,0)`` , respectively. +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(k+4)`` and ``B.at(2*i+1)`` instead of ``A.at(0,k+4)`` and ``B.at(2*i+1,0)`` , respectively. Here is an example of initialization of a Hilbert matrix: :: @@ -1990,7 +1991,7 @@ Mat::begin -------------- .. c:function:: template MatIterator_<_Tp> Mat::begin() template MatConstIterator_<_Tp> Mat::begin() const - Return the matrix iterator, set to the first matrix element + Returns the matrix iterator and sets it to the first matrix element.. 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. Here is the alpha blending function rewritten using the matrix iterators: :: @@ -2032,7 +2033,7 @@ Mat::end ------------ .. c:function:: template MatIterator_<_Tp> Mat::end() template MatConstIterator_<_Tp> Mat::end() const - Return the matrix iterator, set to the after-last matrix element + Returns the matrix iterator and sets it to the after-last matrix element. The methods return the matrix read-only or read-write iterators, set to the point following the last matrix element. @@ -2051,17 +2052,17 @@ Template matrix class derived from }; -The class ``Mat_<_Tp>`` is a "thin" template wrapper on top of ``Mat`` class. It does not have any extra data fields, nor it or ``Mat`` have any virtual methods and thus references or pointers to these two classes can be freely converted one to another. But do it with care, e.g.: :: +The class ``Mat_<_Tp>`` is a "thin" template wrapper on top of the ``Mat`` class. It does not have any extra data fields. Nor this class nor ``Mat`` has any virtual methods. Thus, references or pointers to these two classes can be freely but carefully converted one to another. For example: :: - // create 100x100 8-bit matrix + // create a 100x100 8-bit matrix Mat M(100,100,CV_8U); - // this will compile fine. no any data conversion will be done. + // this will be compiled fine. no any data conversion will be done. Mat_& M1 = (Mat_&)M; - // the program will likely crash at the statement below + // the program is likely to crash at the statement below M1(99,99) = 1.f; -While ``Mat`` is sufficient in most cases, ``Mat_`` can be more convenient if you use a lot of element access operations and if you know matrix type at compile time. Note that ``Mat::at<_Tp>(int y, int x)`` and ``Mat_<_Tp>::operator ()(int y, int x)`` do absolutely the same and run at the same speed, but the latter is certainly shorter: :: +While ``Mat`` is sufficient in most cases, ``Mat_`` can be more convenient if you use a lot of element access operations and if you know matrix type at the compilation time. Note that ``Mat::at<_Tp>(int y, int x)`` and ``Mat_<_Tp>::operator ()(int y, int x)`` do absolutely the same and run at the same speed, but the latter is certainly shorter: :: Mat_ M(20,20); for(int i = 0; i < M.rows; i++) @@ -2072,10 +2073,9 @@ While ``Mat`` is sufficient in most cases, ``Mat_`` can be more convenient if yo cout << E.at(0,0)/E.at(M.rows-1,0); -*How to use ``Mat_`` for multi-channel images/matrices?* -This is simple - just pass ``Vec`` as ``Mat_`` parameter: :: +To use ``Mat_`` for multi-channel images/matrices, pass ``Vec`` as a ``Mat_`` parameter: :: - // allocate 320x240 color image and fill it with green (in RGB space) + // allocate a 320x240 color image and fill it with green (in RGB space) Mat_ img(240, 320, Vec3b(0,255,0)); // now draw a diagonal white line for(int i = 0; i < 100; i++) @@ -2113,8 +2113,8 @@ n-ary multi-dimensional array iterator :: }; -The class is used for implementation of unary, binary and, generally, n-ary element-wise operations on multi-dimensional arrays. Some of the arguments of n-ary function may be continuous arrays, some may be not. It is possible to use conventional -``MatIterator`` 's for each array, but it can be a big overhead to increment all of the iterators after each small operations. That's where ``NAryMatIterator`` can be used. Using it, you can iterate though several matrices simultaneously as long as they have the same geometry (dimensionality and all the dimension sizes are the same). On each iteration ``it.planes[0]``,``it.planes[1]`` , ... will be the slices of the corresponding matrices. +The class is used for implementation of unary, binary, and, generally, n-ary element-wise operations on multi-dimensional arrays. Some of the arguments of n-ary function may be continuous arrays, some may be not. It is possible to use conventional +``MatIterator`` 's for each array but it can be a big overhead to increment all of the iterators after each small operations. In this case consider using ``NAryMatIterator`` . Using it, you can iterate though several matrices simultaneously as long as they have the same geometry (dimensionality and all the dimension sizes are the same). On each iteration ``it.planes[0]``,``it.planes[1]`` , ... will be the slices of the corresponding matrices. Here is an example of how you can compute a normalized and thresholded 3D color histogram: :: @@ -2122,14 +2122,14 @@ Here is an example of how you can compute a normalized and thresholded 3D color { const int histSize[] = {N, N, N}; - // make sure that the histogram has proper size and type + // make sure that the histogram has a proper size and type hist.create(3, histSize, CV_32F); // and clear it hist = Scalar(0); // the loop below assumes that the image - // is 8-bit 3-channel, so let's check it. + // is a 8-bit 3-channel. check it. CV_Assert(image.type() == CV_8UC3); MatConstIterator_ it = image.begin(), it_end = image.end(); @@ -2196,8 +2196,8 @@ Sparse n-dimensional array. :: // if try1d is true and matrix is a single-column matrix (Nx1), // then the sparse matrix will be 1-dimensional. SparseMat(const Mat& m, bool try1d=false); - // converts old-style sparse matrix to the new-style. - // all the data is copied, so that "m" can be safely + // converts an old-style sparse matrix to the new style. + // all the data is copied so that "m" can be safely // deleted after the conversion SparseMat(const CvSparseMat* m); // destructor @@ -2205,19 +2205,19 @@ Sparse n-dimensional array. :: ///////// assignment operations /////////// - // this is O(1) operation; no data is copied + // this is an O(1) operation; no data is copied SparseMat& operator = (const SparseMat& m); // (equivalent to the corresponding constructor with try1d=false) SparseMat& operator = (const Mat& m); - // creates full copy of the matrix + // creates a full copy of the matrix SparseMat clone() const; // copy all the data to the destination matrix. // the destination will be reallocated if needed. void copyTo( SparseMat& m ) const; // converts 1D or 2D sparse matrix to dense 2D matrix. - // If the sparse matrix is 1D, then the result will + // If the sparse matrix is 1D, the result will // be a single-column matrix. void copyTo( Mat& m ) const; // converts arbitrary sparse matrix to dense matrix. @@ -2226,8 +2226,8 @@ Sparse n-dimensional array. :: // converts sparse matrix to dense matrix with optional type conversion and scaling. // When rtype=-1, the destination element type will be the same // as the sparse matrix element type. - // Otherwise rtype will specify the depth and - // the number of channels will remain the same is in the sparse matrix + // Otherwise, rtype will specify the depth and + // the number of channels will remain the same as in the sparse matrix void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; // not used now @@ -2241,7 +2241,7 @@ Sparse n-dimensional array. :: void clear(); // manually increases reference counter to the header. void addref(); - // decreses the header reference counter, when it reaches 0, + // decreses the header reference counter when it reaches 0. // the header and all the underlying data are deallocated. void release(); @@ -2279,16 +2279,16 @@ Sparse n-dimensional array. :: // n-D case size_t hash(const int* idx) const; - // low-level element-acccess functions, - // special variants for 1D, 2D, 3D cases and the generic one for n-D case. + // low-level element-access functions, + // special variants for 1D, 2D, 3D cases, and the generic one for n-D case. // // return pointer to the matrix element. - // if the element is there (it's non-zero), the pointer to it is returned - // if it's not there and createMissing=false, NULL pointer is returned - // if it's not there and createMissing=true, then the new element - // is created and initialized with 0. Pointer to it is returned + // if the element is there (it is non-zero), the pointer to it is returned + // if it is not there and createMissing=false, NULL pointer is returned + // if it is not there and createMissing=true, the new element + // is created and initialized with 0. Pointer to it is returned. // If the optional hashval pointer is not NULL, the element hash value is - // not computed, but *hashval is taken instead. + // not computed but *hashval is taken instead. uchar* ptr(int i0, bool createMissing, size_t* hashval=0); uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0); uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0); @@ -2297,7 +2297,7 @@ Sparse n-dimensional array. :: // higher-level element access functions: // ref<_Tp>(i0,...[,hashval]) - equivalent to *(_Tp*)ptr(i0,...true[,hashval]). // always return valid reference to the element. - // If it's did not exist, it is created. + // If it does not exist, it is created. // find<_Tp>(i0,...[,hashval]) - equivalent to (_const Tp*)ptr(i0,...false[,hashval]). // return pointer to the element or NULL pointer if the element is not there. // value<_Tp>(i0,...[,hashval]) - equivalent to @@ -2327,7 +2327,7 @@ Sparse n-dimensional array. :: template const _Tp* find(const int* idx, size_t* hashval=0) const; // erase the specified matrix element. - // When there is no such element, the methods do nothing + // when there is no such an element, the methods do nothing void erase(int i0, int i1, size_t* hashval=0); void erase(int i0, int i1, int i2, size_t* hashval=0); void erase(const int* idx, size_t* hashval=0); @@ -2351,7 +2351,7 @@ Sparse n-dimensional array. :: template _Tp& value(Node* n); template const _Tp& value(const Node* n) const; - ////////////// some internal-use methods /////////////// + ////////////// some internally used methods /////////////// ... // pointer to the sparse matrix header @@ -2360,10 +2360,10 @@ Sparse n-dimensional array. :: The class ``SparseMat`` represents multi-dimensional sparse numerical arrays. Such a sparse array can store elements of any type that -:ref:`Mat` can store. "Sparse" means that only non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its stored elements can actually become 0. It's up to the user to detect such elements and delete them using ``SparseMat::erase`` ). The non-zero elements are stored in a hash table that grows when it's filled enough, so that the search time is O(1) in average (regardless of whether element is there or not). Elements can be accessed using the following methods: +:ref:`Mat` can store. *Sparse* means that only non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its stored elements can actually become 0. It is up to you to detect such elements and delete them using ``SparseMat::erase`` ). The non-zero elements are stored in a hash table that grows when it is filled so that the search time is O(1) in average (regardless of whether element is there or not). Elements can be accessed using the following methods: -#. - query operations ( ``SparseMat::ptr`` and the higher-level ``SparseMat::ref``, ``SparseMat::value`` and ``SparseMat::find`` ), e.g.: +* + Query operations ( ``SparseMat::ptr`` and the higher-level ``SparseMat::ref``, ``SparseMat::value`` and ``SparseMat::find`` ), for example: :: @@ -2380,8 +2380,8 @@ The class ``SparseMat`` represents multi-dimensional sparse numerical arrays. Su .. -#. - sparse matrix iterators. They are similar to ``MatIterator``, but different from :ref:`NAryMatIterator`. That is, the iteration loop is familiar to STL users: +* + Sparse matrix iterators. They are similar to ``MatIterator`` but different from :ref:`NAryMatIterator`. That is, the iteration loop is familiar to STL users: :: @@ -2406,10 +2406,10 @@ The class ``SparseMat`` represents multi-dimensional sparse numerical arrays. Su .. - If you run this loop, you will notice that elements are enumerated in no any logical order (lexicographical etc.), they come in the same order as they stored in the hash table, i.e. semi-randomly. You may collect pointers to the nodes and sort them to get the proper ordering. Note, however, that pointers to the nodes may become invalid when you add more elements to the matrix; this is because of possible buffer reallocation. + If you run this loop, you will notice that elements are not enumerated in a logical order (lexicographical, and so on). They come in the same order as they are stored in the hash table (semi-randomly). You may collect pointers to the nodes and sort them to get the proper ordering. Note, however, that pointers to the nodes may become invalid when you add more elements to the matrix. This may happen due to possible buffer reallocation. -#. - a combination of the above 2 methods when you need to process 2 or more sparse matrices simultaneously, e.g. this is how you can compute unnormalized cross-correlation of the 2 floating-point sparse matrices: +* + Combination of the above 2 methods when you need to process 2 or more sparse matrices simultaneously. For example, this is how you can compute unnormalized cross-correlation of the 2 floating-point sparse matrices: :: @@ -2417,7 +2417,7 @@ The class ``SparseMat`` represents multi-dimensional sparse numerical arrays. Su { const SparseMat *_a = &a, *_b = &b; // if b contains less elements than a, - // it's faster to iterate through b + // it is faster to iterate through b if(_a->nzcount() > _b->nzcount()) std::swap(_a, _b); SparseMatConstIterator_ it = _a->begin(), @@ -2428,9 +2428,9 @@ The class ``SparseMat`` represents multi-dimensional sparse numerical arrays. Su // take the next element from the first matrix float avalue = *it; const Node* anode = it.node(); - // and try to find element with the same index in the second matrix. + // and try to find an element with the same index in the second matrix. // since the hash value depends only on the element index, - // we reuse hashvalue stored in the node + // reuse the hash value stored in the node float bvalue = _b->value(anode->idx,&anode->hashval); ccorr += avalue*bvalue; } @@ -2475,7 +2475,7 @@ Template sparse n-dimensional array class derived from int channels() const; // more convenient element access operations. - // ref() is retained (but <_Tp> specification is not need anymore); + // ref() is retained (but <_Tp> specification is not needed anymore); // operator () is equivalent to SparseMat::value<_Tp> _Tp& ref(int i0, size_t* hashval=0); _Tp operator()(int i0, size_t* hashval=0) const; @@ -2493,8 +2493,8 @@ Template sparse n-dimensional array class derived from SparseMatConstIterator_<_Tp> end() const; }; -``SparseMat_`` is a thin wrapper on top of :ref:`SparseMat` , made in the same way as ``Mat_`` . -It simplifies notation of some operations, and that's it. :: +``SparseMat_`` is a thin wrapper on top of :ref:`SparseMat` created in the same way as ``Mat_`` . +It simplifies notation of some operations. :: int sz[] = {10, 20, 30}; SparseMat_ M(3, sz); diff --git a/modules/core/doc/clustering.rst b/modules/core/doc/clustering.rst index c6687054c..412ebde13 100644 --- a/modules/core/doc/clustering.rst +++ b/modules/core/doc/clustering.rst @@ -10,15 +10,15 @@ kmeans .. c:function:: double kmeans( const Mat\& samples, int clusterCount, Mat\& labels, TermCriteria termcrit, int attempts, int flags, Mat* centers ) - Finds the centers of clusters and groups the input samples around the clusters. + Finds centers of clusters and groups input samples around the clusters. - :param samples: Floating-point matrix of input samples, one row per sample + :param samples: Floating-point matrix of input samples, one row per sample. - :param clusterCount: The number of clusters to split the set by + :param clusterCount: The number of clusters to split the set by. - :param labels: The input/output integer array that will store the cluster indices for every sample + :param labels: The input/output integer array that stores the cluster indices for every sample. - :param termcrit: Specifies maximum number of iterations and/or accuracy (distance the centers can move by between subsequent iterations) + :param termcrit: Specifies the maximum number of iterations and/or accuracy (distance the centers can move by between subsequent iterations) :param attempts: How many times the algorithm is executed using different initial labelings. The algorithm returns the labels that yield the best compactness (see the last function parameter) diff --git a/modules/core/doc/operations_on_arrays.rst b/modules/core/doc/operations_on_arrays.rst index cd3348ed3..84655fdce 100644 --- a/modules/core/doc/operations_on_arrays.rst +++ b/modules/core/doc/operations_on_arrays.rst @@ -13,22 +13,21 @@ abs .. c:function:: MatExpr<...> abs(const MatExpr<...>& src) - Computes absolute value of each matrix element + Computes an absolute value of each matrix element. - :param src: matrix or matrix expression + :param src: Matrix or matrix expression. ``abs`` is a meta-function that is expanded to one of :func:`absdiff` forms: - * ``C = abs(A-B)`` is equivalent to ``absdiff(A, B, C)`` and + * ``C = abs(A-B)`` is equivalent to ``absdiff(A, B, C)`` * ``C = abs(A)`` is equivalent to ``absdiff(A, Scalar::all(0), C)`` . - * ``C = Mat_ >(abs(A*alpha + beta))`` is equivalent to ``convertScaleAbs(A, C, alpha, beta)``. + * ``C = Mat_ >(abs(A*alpha + beta))`` is equivalent to ``convertScaleAbs(A, C, alpha, beta)`` -The output matrix will have the same size and the same type as the input one -(except for the last case, where ``C`` will be ``depth=CV_8U`` ). +The output matrix has the same size and the same type as the input one (except for the last case, where ``C`` will be ``depth=CV_8U`` ). -See also: :ref:`MatrixExpressions`, :func:`absdiff` +See Also: :ref:`MatrixExpressions`, :func:`absdiff` .. index:: absdiff @@ -40,14 +39,14 @@ absdiff .. c:function:: void absdiff(const Mat& src1, const Mat& src2, Mat& dst) .. c:function:: void absdiff(const Mat& src1, const Scalar& sc, Mat& dst) - Computes per-element absolute difference between 2 arrays or between array and a scalar. + Computes the per-element absolute difference between 2 arrays or between an array and a scalar. - :param src1: The first input array - :param src2: The second input array; Must be the same size and same type as ``src1`` + :param src1: The first input array. + :param src2: The second input array of the same size and type as ``src1`` . - :param sc: Scalar; the second input parameter + :param sc: A scalar. This is the second input parameter. - :param dst: The destination array; it will have the same size and same type as ``src1`` ; see ``Mat::create`` + :param dst: The destination array of the same size and type as ``src1`` . See ``Mat::create`` . The functions ``absdiff`` compute: @@ -56,15 +55,15 @@ The functions ``absdiff`` compute: .. math:: \texttt{dst} (I) = \texttt{saturate} (| \texttt{src1} (I) - \texttt{src2} (I)|) - * or absolute difference between array and a scalar: + * absolute difference between an array and a scalar: .. math:: \texttt{dst} (I) = \texttt{saturate} (| \texttt{src1} (I) - \texttt{sc} |) -where ``I`` is multi-dimensional index of array elements. -in the case of multi-channel arrays each channel is processed independently. +where ``I`` is a multi-dimensional index of array elements. +In case of multi-channel arrays, each channel is processed independently. -See also: :func:`abs` +See Also: :func:`abs` .. index:: add @@ -80,15 +79,15 @@ add Computes the per-element sum of two arrays or an array and a scalar. - :param src1: The first source array + :param src1: The first source array. - :param src2: The second source array. It must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param sc: Scalar; the second input parameter + :param sc: A scalar. This is the second input parameter. - :param dst: The destination array; it will have the same size and same type as ``src1`` ; see ``Mat::create`` + :param dst: The destination array of the same size and type as ``src1`` . See ``Mat::create`` . - :param mask: The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed + :param mask: An optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. The functions ``add`` compute: @@ -100,23 +99,23 @@ The functions ``add`` compute: \texttt{dst} (I) = \texttt{saturate} ( \texttt{src1} (I) + \texttt{src2} (I)) \quad \texttt{if mask} (I) \ne0 * - or the sum of array and a scalar: + the sum of an array and a scalar: .. math:: \texttt{dst} (I) = \texttt{saturate} ( \texttt{src1} (I) + \texttt{sc} ) \quad \texttt{if mask} (I) \ne0 -where ``I`` is multi-dimensional index of array elements. +where ``I`` is a multi-dimensional index of array elements. -The first function in the above list can be replaced with matrix expressions: :: +The first function in the list above can be replaced with matrix expressions: :: dst = src1 + src2; dst += src1; // equivalent to add(dst, src1, dst); -in the case of multi-channel arrays each channel is processed independently. +In case of multi-channel arrays, each channel is processed independently. -See also: +See Also: :func:`subtract`,:func:`addWeighted`,:func:`scaleAdd`,:func:`convertScale`,:ref:`MatrixExpressions` .. index:: addWeighted @@ -129,17 +128,17 @@ addWeighted Computes the weighted sum of two arrays. - :param src1: The first source array + :param src1: The first source array. - :param alpha: Weight for the first array elements + :param alpha: Weight for the first array elements. - :param src2: The second source array; must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param beta: Weight for the second array elements + :param beta: Weight for the second array elements. - :param dst: The destination array; it will have the same size and same type as ``src1`` + :param dst: The destination array of the same size and type as ``src1`` . - :param gamma: Scalar, added to each sum + :param gamma: A scalar added to each sum. The functions ``addWeighted`` calculate the weighted sum of two arrays as follows: @@ -147,16 +146,16 @@ The functions ``addWeighted`` calculate the weighted sum of two arrays as follow \texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} ) -where ``I`` is multi-dimensional index of array elements. +where ``I`` is a multi-dimensional index of array elements. The first function can be replaced with a matrix expression: :: dst = src1*alpha + src2*beta + gamma; -In the case of multi-channel arrays each channel is processed independently. +In case of multi-channel arrays, each channel is processed independently. -See also: +See Also: :func:`add`,:func:`subtract`,:func:`scaleAdd`,:func:`convertScale`,:ref:`MatrixExpressions` .. index:: bitwise_and @@ -169,19 +168,19 @@ bitwise_and .. c:function:: void bitwise_and(const Mat& src1, const Scalar& sc, Mat& dst, const Mat& mask=Mat()) - Calculates per-element bit-wise conjunction of two arrays and an array and a scalar. + Calculates the per-element bit-wise conjunction of two arrays or an array and a scalar. - :param src1: The first source array + :param src1: The first source array. - :param src2: The second source array. It must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param sc: Scalar; the second input parameter + :param sc: A scalar. This is the second input parameter. - :param dst: The destination array; it will have the same size and same type as ``src1`` ; see ``Mat::create`` + :param dst: The destination array of the same size and type as ``src1`` . See ``Mat::create`` . - :param mask: The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed + :param mask: An optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. -The functions ``bitwise_and`` compute per-element bit-wise logical conjunction: +The functions ``bitwise_and`` compute the per-element bit-wise logical conjunction: * of two arrays @@ -191,15 +190,15 @@ The functions ``bitwise_and`` compute per-element bit-wise logical conjunction: \texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 * - or array and a scalar: + an array and a scalar: .. math:: \texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{sc} \quad \texttt{if mask} (I) \ne0 -In the case of floating-point arrays their machine-specific bit representations (usually IEEE754-compliant) are used for the operation, and in the case of multi-channel arrays each channel is processed independently. +In case of floating-point arrays, their machine-specific bit representations (usually IEEE754-compliant) are used for the operation. In case of multi-channel arrays, each channel is processed independently. -See also:,, +See Also: ?? .. index:: bitwise_not @@ -209,13 +208,13 @@ bitwise_not ----------- .. c:function:: void bitwise_not(const Mat& src, Mat& dst) - Inverts every bit of array + Inverts every bit of an array. - :param src1: The source array + :param src1: The source array. - :param dst: The destination array; it is reallocated to be of the same size and the same type as ``src`` ; see ``Mat::create`` + :param dst: The destination array. It is reallocated to be of the same size and type as ``src`` . See ``Mat::create`` . - :param mask: The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed + :param mask: An optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. The functions ``bitwise_not`` compute per-element bit-wise inversion of the source array: @@ -223,7 +222,7 @@ The functions ``bitwise_not`` compute per-element bit-wise inversion of the sour \texttt{dst} (I) = \neg \texttt{src} (I) -In the case of floating-point source array its machine-specific bit representation (usually IEEE754-compliant) is used for the operation. in the case of multi-channel arrays each channel is processed independently. +In case of a floating-point source array, its machine-specific bit representation (usually IEEE754-compliant) is used for the operation. In case of multi-channel arrays, each channel is processed independently. .. index:: bitwise_or @@ -235,19 +234,19 @@ bitwise_or .. c:function:: void bitwise_or(const Mat& src1, const Scalar& sc, Mat& dst, const Mat& mask=Mat()) - Calculates per-element bit-wise disjunction of two arrays and an array and a scalar. + Calculates the per-element bit-wise disjunction of two arrays or an array and a scalar. - :param src1: The first source array + :param src1: The first source array. - :param src2: The second source array. It must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param sc: Scalar; the second input parameter + :param sc: A scalar. This is the second input parameter. - :param dst: The destination array; it is reallocated to be of the same size and the same type as ``src1`` ; see ``Mat::create`` + :param dst: The destination array. It is reallocated to be of the same size and type as ``src1`` . See ``Mat::create`` . - :param mask: The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed + :param mask: An optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. -The functions ``bitwise_or`` compute per-element bit-wise logical disjunction +The functions ``bitwise_or`` compute the per-element bit-wise logical disjunction: * of two arrays @@ -257,13 +256,13 @@ The functions ``bitwise_or`` compute per-element bit-wise logical disjunction \texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 * - or array and a scalar: + an array and a scalar: .. math:: \texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{sc} \quad \texttt{if mask} (I) \ne0 -In the case of floating-point arrays their machine-specific bit representations (usually IEEE754-compliant) are used for the operation. in the case of multi-channel arrays each channel is processed independently. +In case of floating-point arrays, their machine-specific bit representations (usually IEEE754-compliant) are used for the operation. In case of multi-channel arrays, each channel is processed independently. .. index:: bitwise_xor @@ -275,19 +274,19 @@ bitwise_xor .. c:function:: void bitwise_xor(const Mat& src1, const Scalar& sc, Mat& dst, const Mat& mask=Mat()) - Calculates per-element bit-wise "exclusive or" operation on two arrays and an array and a scalar. + Calculates the per-element bit-wise "exclusive or" operation on two arrays or an array and a scalar. - :param src1: The first source array + :param src1: The first source array. - :param src2: The second source array. It must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param sc: Scalar; the second input parameter + :param sc: A scalar. This is the second input parameter. - :param dst: The destination array; it is reallocated to be of the same size and the same type as ``src1`` ; see ``Mat::create`` + :param dst: The destination array. It is reallocated to be of the same size and type as ``src1`` . See ``Mat::create`` . - :param mask: The optional operation mask, 8-bit single channel array; specifies elements of the destination array to be changed + :param mask: An optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. -The functions ``bitwise_xor`` compute per-element bit-wise logical "exclusive or" operation +The functions ``bitwise_xor`` compute the per-element bit-wise logical "exclusive or" operation: * on two arrays @@ -295,13 +294,13 @@ The functions ``bitwise_xor`` compute per-element bit-wise logical "exclusive or \texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 - * or array and a scalar: + * an array and a scalar: .. math:: \texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{sc} \quad \texttt{if mask} (I) \ne0 -In the case of floating-point arrays their machine-specific bit representations (usually IEEE754-compliant) are used for the operation. in the case of multi-channel arrays each channel is processed independently. +In case of floating-point arrays, their machine-specific bit representations (usually IEEE754-compliant) are used for the operation. In case of multi-channel arrays, each channel is processed independently. .. index:: calcCovarMatrix @@ -314,17 +313,17 @@ calcCovarMatrix .. c:function:: void calcCovarMatrix( const Mat& samples, Mat& covar, Mat& mean, int flags, int ctype=CV_64F) - Calculates covariation matrix of a set of vectors + Calculates the covariance matrix of a set of vectors. - :param samples: The samples, stored as separate matrices, or as rows or columns of a single matrix + :param samples: Samples stored either as separate matrices or as rows/columns of a single matrix. - :param nsamples: The number of samples when they are stored separately + :param nsamples: The number of samples when they are stored separately. - :param covar: The output covariance matrix; it will have type= ``ctype`` and square size + :param covar: The output covariance matrix of the type= ``ctype`` and square size. - :param mean: The input or output (depending on the flags) array - the mean (average) vector of the input vectors + :param mean: The input or output (depending on the flags) array - the mean (average) vector of the input vectors. - :param flags: The operation flags, a combination of the following values + :param flags: Operation flags, a combination of the following values: * **CV_COVAR_SCRAMBLED** The output covariance matrix is calculated as: @@ -332,7 +331,7 @@ calcCovarMatrix \texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...], - that is, the covariance matrix will be :math:`\texttt{nsamples} \times \texttt{nsamples}` . Such an unusual covariance matrix is used for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for face recognition). Eigenvalues of this "scrambled" matrix will match the eigenvalues of the true covariance matrix and the "true" eigenvectors can be easily calculated from the eigenvectors of the "scrambled" covariance matrix. + The covariance matrix will be :math:`\texttt{nsamples} \times \texttt{nsamples}` . Such an unusual covariance matrix is used for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of the "scrambled" covariance matrix. * **CV_COVAR_NORMAL** The output covariance matrix is calculated as: @@ -340,20 +339,19 @@ calcCovarMatrix \texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...] \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T, - that is, ``covar`` will be a square matrix of the same size as the total number of elements in each input vector. One and only one of ``CV_COVAR_SCRAMBLED`` and ``CV_COVAR_NORMAL`` must be specified + ``covar`` will be a square matrix of the same size as the total number of elements in each input vector. One and only one of ``CV_COVAR_SCRAMBLED`` and ``CV_COVAR_NORMAL`` must be specified. - * **CV_COVAR_USE_AVG** If the flag is specified, the function does not calculate ``mean`` from the input vectors, but, instead, uses the passed ``mean`` vector. This is useful if ``mean`` has been pre-computed or known a-priori, or if the covariance matrix is calculated by parts - in this case, ``mean`` is not a mean vector of the input sub-set of vectors, but rather the mean vector of the whole set. + * **CV_COVAR_USE_AVG** If the flag is specified, the function does not calculate ``mean`` from the input vectors but, instead, uses the passed ``mean`` vector. This is useful if ``mean`` has been pre-computed or known in advance, or if the covariance matrix is calculated by parts. In this case, ``mean`` is not a mean vector of the input sub-set of vectors but rather the mean vector of the whole set. - * **CV_COVAR_SCALE** If the flag is specified, the covariance matrix is scaled. In the "normal" mode ``scale`` is ``1./nsamples`` ; in the "scrambled" mode ``scale`` is the reciprocal of the total number of elements in each input vector. By default (if the flag is not specified) the covariance matrix is not scaled (i.e. ``scale=1`` ). + * **CV_COVAR_SCALE** If the flag is specified, the covariance matrix is scaled. In the "normal" mode, ``scale`` is ``1./nsamples`` . In the "scrambled" mode, ``scale`` is the reciprocal of the total number of elements in each input vector. By default (if the flag is not specified), the covariance matrix is not scaled ( ``scale=1`` ). - * **CV_COVAR_ROWS** [Only useful in the second variant of the function] The flag means that all the input vectors are stored as rows of the ``samples`` matrix. ``mean`` should be a single-row vector in this case. + * **CV_COVAR_ROWS** [Only useful in the second variant of the function] If the flag is specified, all the input vectors are stored as rows of the ``samples`` matrix. ``mean`` should be a single-row vector in this case. - * **CV_COVAR_COLS** [Only useful in the second variant of the function] The flag means that all the input vectors are stored as columns of the ``samples`` matrix. ``mean`` should be a single-column vector in this case. + * **CV_COVAR_COLS** [Only useful in the second variant of the function] If the flag is specified, all the input vectors are stored as columns of the ``samples`` matrix. ``mean`` should be a single-column vector in this case. -The functions ``calcCovarMatrix`` calculate the covariance matrix -and, optionally, the mean vector of the set of input vectors. +The functions ``calcCovarMatrix`` calculate the covariance matrix and, optionally, the mean vector of the set of input vectors. -See also: +See Also: :func:`PCA`,:func:`mulTransposed`,:func:`Mahalanobis` .. index:: cartToPolar @@ -365,26 +363,26 @@ cartToPolar .. c:function:: void cartToPolar(const Mat& x, const Mat& y, Mat& magnitude, Mat& angle, bool angleInDegrees=false) - Calculates the magnitude and angle of 2d vectors. + Calculates the magnitude and angle of 2D vectors. - :param x: The array of x-coordinates; must be single-precision or double-precision floating-point array + :param x: The array of x-coordinates. This must be a single-precision or double-precision floating-point array. - :param y: The array of y-coordinates; it must have the same size and same type as ``x`` + :param y: The array of y-coordinates. It must have the same size and same type as ``x`` . - :param magnitude: The destination array of magnitudes of the same size and same type as ``x`` + :param magnitude: The destination array of magnitudes of the same size and type as ``x`` . - :param angle: The destination array of angles of the same size and same type as ``x``. The angles are measured in radians :math:`(0` to :math:`2 \pi )` or in degrees (0 to 360 degrees). + :param angle: The destination array of angles of the same size and type as ``x`` . The angles are measured in radians :math:`(0` to :math:`2 \pi )` or in degrees (0 to 360 degrees). - :param angleInDegrees: The flag indicating whether the angles are measured in radians, which is default mode, or in degrees + :param angleInDegrees: The flag indicating whether the angles are measured in radians, which is a default mode, or in degrees. -The function ``cartToPolar`` calculates either the magnitude, angle, or both of every 2d vector (x(I),y(I)): +The function ``cartToPolar`` calculates either the magnitude, angle, or both for every 2D vector (x(I),y(I)): .. math:: \begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array} The angles are calculated with -:math:`\sim\,0.3^\circ` accuracy. For the (0,0) point, the angle is set to 0. +:math:`\sim\,0.3^\circ` accuracy. For the point (0,0) , the angle is set to 0. .. index:: checkRange @@ -397,22 +395,20 @@ checkRange Checks every element of an input array for invalid values. - :param src: The array to check + :param src: The array to check. - :param quiet: The flag indicating whether the functions quietly return false when the array elements are out of range, or they throw an exception. + :param quiet: The flag indicating whether the functions quietly return false when the array elements are out of range or they throw an exception. - :param pos: The optional output parameter, where the position of the first outlier is stored. In the second function ``pos`` , when not NULL, must be a pointer to array of ``src.dims`` elements + :param pos: An optional output parameter, where the position of the first outlier is stored. In the second function ``pos`` , when not NULL, must be a pointer to array of ``src.dims`` elements. - :param minVal: The inclusive lower boundary of valid values range + :param minVal: The inclusive lower boundary of valid values range. - :param maxVal: The exclusive upper boundary of valid values range + :param maxVal: The exclusive upper boundary of valid values range. -The functions ``checkRange`` check that every array element is -neither NaN nor -:math:`\pm \infty` . When ``minVal < -DBL_MAX`` and ``maxVal < DBL_MAX`` , then the functions also check that -each value is between ``minVal`` and ``maxVal`` . in the case of multi-channel arrays each channel is processed independently. +The functions ``checkRange`` check that every array element is neither NaN nor +:math:`\pm \infty` . When ``minVal < -DBL_MAX`` and ``maxVal < DBL_MAX`` , the functions also check that each value is between ``minVal`` and ``maxVal`` . In case of multi-channel arrays, each channel is processed independently. If some values are out of range, position of the first outlier is stored in ``pos`` (when -:math:`\texttt{pos}\ne0` ), and then the functions either return false (when ``quiet=true`` ) or throw an exception. +:math:`\texttt{pos}\ne0` ). Then, the functions either return false (when ``quiet=true`` ) or throw an exception. .. index:: compare @@ -425,17 +421,17 @@ compare .. c:function:: void compare(const Mat& src1, double value, Mat& dst, int cmpop) - Performs per-element comparison of two arrays or an array and scalar value. + Performs the per-element comparison of two arrays or an array and scalar value. - :param src1: The first source array + :param src1: The first source array. - :param src2: The second source array; must have the same size and same type as ``src1`` + :param src2: The second source array of the same size and type as ``src1`` . - :param value: The scalar value to compare each array element with + :param value: A scalar value to compare each array element with. - :param dst: The destination array; will have the same size as ``src1`` and type= ``CV_8UC1`` + :param dst: The destination array of the same size as ``src1`` and type= ``CV_8UC1`` . - :param cmpop: The flag specifying the relation between the elements to be checked + :param cmpop: The flag specifying the relation between the elements to be checked. * **CMP_EQ** :math:`\texttt{src1}(I) = \texttt{src2}(I)` or :math:`\texttt{src1}(I) = \texttt{value}` * **CMP_GT** :math:`\texttt{src1}(I) > \texttt{src2}(I)` or :math:`\texttt{src1}(I) > \texttt{value}` @@ -444,7 +440,7 @@ compare * **CMP_LE** :math:`\texttt{src1}(I) \leq \texttt{src2}(I)` or :math:`\texttt{src1}(I) \leq \texttt{value}` * **CMP_NE** :math:`\texttt{src1}(I) \ne \texttt{src2}(I)` or :math:`\texttt{src1}(I) \ne \texttt{value}` -The functions ``compare`` compare each element of ``src1`` with the corresponding element of ``src2`` or with real scalar ``value`` . When the comparison result is true, the corresponding element of destination array is set to 255, otherwise it is set to 0: +The functions ``compare`` compare each element of ``src1`` with the corresponding element of ``src2`` or with the real scalar ``value`` . When the comparison result is true, the corresponding element of destination array is set to 255. Otherwise, it is set to 0: * ``dst(I) = src1(I) cmpop src2(I) ? 255 : 0`` * ``dst(I) = src1(I) cmpop value ? 255 : 0`` @@ -456,7 +452,7 @@ The comparison operations can be replaced with the equivalent matrix expressions ... -See also: +See Also: :func:`checkRange`,:func:`min`,:func:`max`,:func:`threshold`,:ref:`MatrixExpressions` .. index:: completeSymm @@ -470,11 +466,11 @@ completeSymm Copies the lower or the upper half of a square matrix to another half. - :param mtx: Input-output floating-point square matrix + :param mtx: Input-output floating-point square matrix. - :param lowerToUpper: If true, the lower half is copied to the upper half, otherwise the upper half is copied to the lower half + :param lowerToUpper: If true, the lower half is copied to the upper half. Otherwise, the upper half is copied to the lower half. -The function ``completeSymm`` copies the lower half of a square matrix to its another half; the matrix diagonal remains unchanged: +The function ``completeSymm`` copies the lower half of a square matrix to its another half. The matrix diagonal remains unchanged: * :math:`\texttt{mtx}_{ij}=\texttt{mtx}_{ji}` for @@ -484,7 +480,7 @@ The function ``completeSymm`` copies the lower half of a square matrix to its an :math:`\texttt{mtx}_{ij}=\texttt{mtx}_{ji}` for :math:`i < j` if ``lowerToUpper=true`` -See also: :func:`flip`,:func:`transpose` +See Also: :func:`flip`,:func:`transpose` .. index:: convertScaleAbs @@ -495,23 +491,23 @@ convertScaleAbs .. c:function:: void convertScaleAbs(const Mat& src, Mat& dst, double alpha=1, double beta=0) - Scales, computes absolute values and converts the result to 8-bit. + Scales, computes absolute values, and converts the result to 8-bit. - :param src: The source array + :param src: The source array. - :param dst: The destination array + :param dst: The destination array. - :param alpha: The optional scale factor + :param alpha: An optional scale factor. - :param beta: The optional delta added to the scaled values + :param beta: An optional delta added to the scaled values. -On each element of the input array the function ``convertScaleAbs`` performs 3 operations sequentially: scaling, taking absolute value, conversion to unsigned 8-bit type: +On each element of the input array, the function ``convertScaleAbs`` performs three operations sequentially: scaling, taking an absolute value, conversion to an unsigned 8-bit type: .. math:: \texttt{dst} (I)= \texttt{saturate\_cast} (| \texttt{src} (I)* \texttt{alpha} + \texttt{beta} |) -in the case of multi-channel arrays the function processes each channel independently. When the output is not 8-bit, the operation can be emulated by calling ``Mat::convertTo`` method (or by using matrix expressions) and then by computing absolute value of the result, for example: :: +In case of multi-channel arrays, the function processes each channel independently. When the output is not 8-bit, the operation can be emulated by calling the ``Mat::convertTo`` method (or by using matrix expressions) and then by computing an absolute value of the result. For example: :: Mat_ A(30,30); randu(A, Scalar(-100), Scalar(100)); @@ -521,7 +517,7 @@ in the case of multi-channel arrays the function processes each channel independ // but it will allocate a temporary matrix -See also: +See Also: :func:`Mat::convertTo`,:func:`abs` .. index:: countNonZero @@ -535,15 +531,15 @@ countNonZero Counts non-zero array elements. - :param mtx: Single-channel array + :param mtx: Single-channel array. -The function ``cvCountNonZero`` returns the number of non-zero elements in mtx: +The function ``cvCountNonZero`` returns the number of non-zero elements in ``mtx`` : .. math:: \sum _{I: \; \texttt{mtx} (I) \ne0 } 1 -See also: +See Also: :func:`mean`,:func:`meanStdDev`,:func:`norm`,:func:`minMaxLoc`,:func:`calcCovarMatrix` .. index:: cubeRoot @@ -555,11 +551,11 @@ cubeRoot .. c:function:: float cubeRoot(float val) - Computes cube root of the argument + Computes the cube root of an argument. - :param val: The function argument + :param val: A function argument. -The function ``cubeRoot`` computes :math:`\sqrt[3]{\texttt{val}}`. Negative arguments are handled correctly, *NaN* +The function ``cubeRoot`` computes :math:`\sqrt[3]{\texttt{val}}`. Negative arguments are handled correctly. *NaN* and :math:`\pm\infty` are not handled. The accuracy approaches the maximum possible accuracy for single-precision data. .. index:: cvarrToMat @@ -571,28 +567,28 @@ cvarrToMat .. c:function:: Mat cvarrToMat(const CvArr* src, bool copyData=false, bool allowND=true, int coiMode=0) - Converts ``CvMat``, ``IplImage`` or ``CvMatND`` to ``Mat``. + Converts ``CvMat``, ``IplImage`` , or ``CvMatND`` to ``Mat``. - :param src: The source ``CvMat``, ``IplImage`` or ``CvMatND`` + :param src: The source ``CvMat``, ``IplImage`` , or ``CvMatND`` . - :param copyData: When it is false (default value), no data is copied, only the new header is created. In this case the original array should not be deallocated while the new matrix header is used. The the parameter is true, all the data is copied, then user may deallocate the original array right after the conversion + :param copyData: When it is false (default value), no data is copied and only the new header is created. In this case, the original array should not be deallocated while the new matrix header is used. If the parameter is true, all the data is copied and you may deallocate the original array right after the conversion. - :param allowND: When it is true (default value), then ``CvMatND`` is converted to ``Mat`` if it's possible (e.g. then the data is contiguous). If it's not possible, or when the parameter is false, the function will report an error + :param allowND: When it is true (default value), ``CvMatND`` is converted to ``Mat`` , if it is possible (for example, when the data is contiguous). If it is not possible, or when the parameter is false, the function will report an error. :param coiMode: The parameter specifies how the IplImage COI (when set) is handled. - * If ``coiMode=0`` , the function will report an error if COI is set. + * If ``coiMode=0`` , the function reports an error if COI is set. - * If ``coiMode=1`` , the function will never report an error; instead it returns the header to the whole original image and user will have to check and process COI manually, see :func:`extractImageCOI` . + * If ``coiMode=1`` , the function never reports an error. Instead, it returns the header to the whole original image and you will have to check and process COI manually. See :func:`extractImageCOI` . -The function ``cvarrToMat`` converts ``CvMat``, ``IplImage`` or ``CvMatND`` header to +The function ``cvarrToMat`` converts ``CvMat``, ``IplImage`` , or ``CvMatND`` header to :func:`Mat` header, and optionally duplicates the underlying data. The constructed header is returned by the function. -When ``copyData=false`` , the conversion is done really fast (in O(1) time) and the newly created matrix header will have ``refcount=0`` , which means that no reference counting is done for the matrix data, and user has to preserve the data until the new header is destructed. Otherwise, when ``copyData=true`` , the new buffer will be allocated and managed as if you created a new matrix from scratch and copy the data there. That is, ``cvarrToMat(src, true) :math:`\sim` cvarrToMat(src, false).clone()`` (assuming that COI is not set). The function provides uniform way of supporting +When ``copyData=false`` , the conversion is done really fast (in O(1) time) and the newly created matrix header will have ``refcount=0`` , which means that no reference counting is done for the matrix data. In this case, you have to preserve the data until the new header is destructed. Otherwise, when ``copyData=true`` , the new buffer is allocated and managed as if you created a new matrix from scratch and copied the data there. That is, ``cvarrToMat(src, true) :math:`\sim` cvarrToMat(src, false).clone()`` (assuming that COI is not set). The function provides a uniform way of supporting ``CvArr`` paradigm in the code that is migrated to use new-style data structures internally. The reverse transformation, from :func:`Mat` to ``CvMat`` or -``IplImage`` can be done by simple assignment: :: +``IplImage`` can be done by a simple assignment: :: CvMat* A = cvCreateMat(10, 10, CV_32F); cvSetIdentity(A); @@ -603,29 +599,29 @@ When ``copyData=false`` , the conversion is done really fast (in O(1) time) and CvMat C1 = B1; // now A, A1, B, B1, C and C1 are different headers // for the same 10x10 floating-point array. - // note, that you will need to use "&" - // to pass C & C1 to OpenCV functions, e.g: + // note that you will need to use "&" + // to pass C & C1 to OpenCV functions, for example: printf(" Normally, the function is used to convert an old-style 2D array ( ``CvMat`` or -``IplImage`` ) to ``Mat`` , however, the function can also take -``CvMatND`` on input and create -:func:`Mat` for it, if it's possible. And for ``CvMatND A`` it is possible if and only if ``A.dim[i].size*A.dim.step[i] == A.dim.step[i-1]`` for all or for all but one ``i, 0 < i < A.dims`` . That is, the matrix data should be continuous or it should be representable as a sequence of continuous matrices. By using this function in this way, you can process -``CvMatND`` using arbitrary element-wise function. But for more complex operations, such as filtering functions, it will not work, and you need to convert +``IplImage`` ) to ``Mat`` . However, the function can also take +``CvMatND`` as an input and create +:func:`Mat` for it, if it is possible. And, for ``CvMatND A`` , it is possible if and only if ``A.dim[i].size*A.dim.step[i] == A.dim.step[i-1]`` for all or for all but one ``i, 0 < i < A.dims`` . That is, the matrix data should be continuous or it should be representable as a sequence of continuous matrices. By using this function in this way, you can process +``CvMatND`` using an arbitrary element-wise function. But for more complex operations, such as filtering functions, it will not work, and you need to convert ``CvMatND`` to :func:`MatND` using the corresponding constructor of the latter. -The last parameter, ``coiMode`` , specifies how to react on an image with COI set: by default it's 0, and then the function reports an error when an image with COI comes in. And ``coiMode=1`` means that no error is signaled - user has to check COI presence and handle it manually. The modern structures, such as +The last parameter, ``coiMode`` , specifies how to deal with an image with COI set. By default, it is 0 and the function reports an error when an image with COI comes in. And ``coiMode=1`` means that no error is signalled. You have to check COI presence and handle it manually. The modern structures, such as :func:`Mat` and -:func:`MatND` do not support COI natively. To process individual channel of an new-style array, you will need either to organize loop over the array (e.g. using matrix iterators) where the channel of interest will be processed, or extract the COI using +:func:`MatND` do not support COI natively. To process an individual channel of a new-style array, you need either to organize a loop over the array (for example, using matrix iterators) where the channel of interest will be processed, or extract the COI using :func:`mixChannels` (for new-style arrays) or -:func:`extractImageCOI` (for old-style arrays), process this individual channel and insert it back to the destination array if need (using +:func:`extractImageCOI` (for old-style arrays), process this individual channel, and insert it back to the destination array if needed (using :func:`mixChannel` or :func:`insertImageCOI` , respectively). -See also: +See Also: :func:`cvGetImage`,:func:`cvGetMat`,:func:`cvGetMatND`,:func:`extractImageCOI`,:func:`insertImageCOI`,:func:`mixChannels` .. index:: dct @@ -715,7 +711,7 @@ Also, the function's performance depends very much, and not monotonically, on th size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); } -See also: +See Also: :func:`dft`,:func:`getOptimalDFTSize`,:func:`idct` .. index:: dft @@ -860,7 +856,7 @@ What can be optimized in the above sample? All of the above improvements have been implemented in :func:`matchTemplate` and :func:`filter2D` , therefore, by using them, you can get even better performance than with the above theoretically optimal implementation (though, those two functions actually compute cross-correlation, not convolution, so you will need to "flip" the kernel or the image around the center using :func:`flip` ). -See also: +See Also: :func:`dct`,:func:`getOptimalDFTSize`,:func:`mulSpectrums`,:func:`filter2D`,:func:`matchTemplate`,:func:`flip`,:func:`cartToPolar`,:func:`magnitude`,:func:`phase` .. index:: divide @@ -901,7 +897,7 @@ or a scalar by array, when there is no ``src1`` : The result will have the same type as ``src1`` . When ``src2(I)=0``,``dst(I)=0`` too. -See also: +See Also: :func:`multiply`,:func:`add`,:func:`subtract`,:ref:`MatrixExpressions` .. index:: determinant @@ -925,7 +921,7 @@ For symmetric positive-determined matrices, it is also possible to compute :math:`\texttt{mtx}=U \cdot W \cdot V^T` and then calculate the determinant as a product of the diagonal elements of :math:`W` . -See also: +See Also: :func:`SVD`,:func:`trace`,:func:`invert`,:func:`solve`,:ref:`MatrixExpressions` .. index:: eigen @@ -964,7 +960,7 @@ as the source matrix with eigenvectors and a vector the length of the source matrix with eigenvalues. The selected eigenvectors/-values are always in the first highindex - lowindex + 1 rows. -See also: +See Also: :func:`SVD`,:func:`completeSymm`,:func:`PCA` .. index:: exp @@ -995,7 +991,7 @@ The maximum relative error is about :math:`10^{-10}` for double-precision. Currently, the function converts denormalized values to zeros on output. Special values (NaN, :math:`\pm \infty` ) are not handled. -See also: +See Also: :func:`log`,:func:`cartToPolar`,:func:`polarToCart`,:func:`phase`,:func:`pow`,:func:`sqrt`,:func:`magnitude` .. index:: extractImageCOI @@ -1019,7 +1015,7 @@ The function ``extractImageCOI`` is used to extract image COI from an old-style To extract a channel from a new-style matrix, use :func:`mixChannels` or -:func:`split` See also: +:func:`split` See Also: :func:`mixChannels`,:func:`split`,:func:`merge`,:func:`cvarrToMat`,:func:`cvSetImageCOI`,:func:`cvGetImageCOI` .. index:: fastAtan2 @@ -1055,7 +1051,7 @@ flip :param dst: The destination array; will have the same size and same type as ``src`` - :param flipCode: Specifies how to flip the array: 0 means flipping around the x-axis, positive (e.g., 1) means flipping around y-axis, and negative (e.g., -1) means flipping around both axes. See also the discussion below for the formulas. + :param flipCode: Specifies how to flip the array: 0 means flipping around the x-axis, positive (e.g., 1) means flipping around y-axis, and negative (e.g., -1) means flipping around both axes. See Also the discussion below for the formulas. The function ``flip`` flips the array in one of three different ways (row and column indices are 0-based): @@ -1084,7 +1080,7 @@ The example scenarios of function use are: :math:`\texttt{flipCode} > 0` or :math:`\texttt{flipCode} = 0` ) -See also: :func:`transpose`,:func:`repeat`,:func:`completeSymm` +See Also: :func:`transpose`,:func:`repeat`,:func:`completeSymm` .. index:: gemm @@ -1126,7 +1122,7 @@ The function can be replaced with a matrix expression, e.g. the above call can b dst = alpha*src1.t()*src2 + beta*src3.t(); -See also: +See Also: :func:`mulTransposed`,:func:`transform`,:ref:`MatrixExpressions` .. index:: getConvertElem @@ -1162,7 +1158,7 @@ getConvertElem The functions ``getConvertElem`` and ``getConvertScaleElem`` return pointers to the functions for converting individual pixels from one type to another. While the main function purpose is to convert single pixels (actually, for converting sparse matrices from one type to another), you can use them to convert the whole row of a dense matrix or the whole matrix at once, by setting ``cn = matrix.cols*matrix.rows*matrix.channels()`` if the matrix data is continuous. -See also: +See Also: :func:`Mat::convertTo`,:func:`MatND::convertTo`,:func:`SparseMat::convertTo` .. index:: getOptimalDFTSize @@ -1190,7 +1186,7 @@ The function returns a negative number if ``vecsize`` is too large (very close t While the function cannot be used directly to estimate the optimal vector size for DCT transform (since the current DCT implementation supports only even-size vectors), it can be easily computed as ``getOptimalDFTSize((vecsize+1)/2)*2`` . -See also: +See Also: :func:`dft`,:func:`dct`,:func:`idft`,:func:`idct`,:func:`mulSpectrums` .. index:: idct @@ -1212,7 +1208,7 @@ idct ``idct(src, dst, flags)`` is equivalent to ``dct(src, dst, flags | DCT_INVERSE)``. -See also: :func:`dct`,:func:`dft`,:func:`idft`,:func:`getOptimalDFTSize` +See Also: :func:`dct`,:func:`dft`,:func:`idft`,:func:`getOptimalDFTSize` .. index:: idft @@ -1239,7 +1235,7 @@ See :func:`dft` for details. Note, that none of ``dft`` and ``idft`` scale the result by default. Thus, you should pass ``DFT_SCALE`` to one of ``dft`` or ``idft`` explicitly to make these transforms mutually inverse. -See also: :func:`dft`,:func:`dct`,:func:`idct`,:func:`mulSpectrums`,:func:`getOptimalDFTSize` +See Also: :func:`dft`,:func:`dct`,:func:`idct`,:func:`mulSpectrums`,:func:`getOptimalDFTSize` .. index:: inRange @@ -1313,7 +1309,7 @@ In the case of ``DECOMP_SVD`` method, the function returns the inversed conditio Similarly to ``DECOMP_LU`` , the method ``DECOMP_CHOLESKY`` works only with non-singular square matrices. In this case the function stores the inverted matrix in ``dst`` and returns non-zero, otherwise it returns 0. -See also: +See Also: :func:`solve`,:func:`SVD` .. index:: log @@ -1345,7 +1341,7 @@ The maximum relative error is about :math:`10^{-10}` for double-precision input. Special values (NaN, :math:`\pm \infty` ) are not handled. -See also: +See Also: :func:`exp`,:func:`cartToPolar`,:func:`polarToCart`,:func:`phase`,:func:`pow`,:func:`sqrt`,:func:`magnitude` .. index:: LUT @@ -1377,7 +1373,7 @@ where d = \fork{0}{if \texttt{src} has depth \texttt{CV\_8U}}{128}{if \texttt{src} has depth \texttt{CV\_8S}} -See also: +See Also: :func:`convertScaleAbs`,``Mat::convertTo`` .. index:: magnitude @@ -1403,7 +1399,7 @@ The function ``magnitude`` calculates magnitude of 2D vectors formed from the co \texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2} -See also: +See Also: :func:`cartToPolar`,:func:`polarToCart`,:func:`phase`,:func:`sqrt` .. index:: Mahalanobis @@ -1481,7 +1477,7 @@ In the second variant, when the source array is multi-channel, each channel is c The first 3 variants of the function listed above are actually a part of :ref:`MatrixExpressions` , they return the expression object that can be further transformed, or assigned to a matrix, or passed to a function etc. -See also: +See Also: :func:`min`,:func:`compare`,:func:`inRange`,:func:`minMaxLoc`,:ref:`MatrixExpressions` .. index:: mean @@ -1513,7 +1509,7 @@ The functions ``mean`` compute mean value ``M`` of array elements, independently When all the mask elements are 0's, the functions return ``Scalar::all(0)`` . -See also: +See Also: :func:`countNonZero`,:func:`meanStdDev`,:func:`norm`,:func:`minMaxLoc` .. index:: meanStdDev @@ -1549,7 +1545,7 @@ Note that the computed standard deviation is only the diagonal of the complete n :math:`M*N \times \texttt{mtx.channels}()` (only possible when the matrix is continuous) and then pass the matrix to :func:`calcCovarMatrix` . -See also: +See Also: :func:`countNonZero`,:func:`mean`,:func:`norm`,:func:`minMaxLoc`,:func:`calcCovarMatrix` .. index:: merge @@ -1583,7 +1579,7 @@ The functions ``merge`` merge several single-channel arrays (or rather interleav The function :func:`split` does the reverse operation and if you need to merge several multi-channel images or shuffle channels in some other advanced way, use -:func:`mixChannels` See also: +:func:`mixChannels` See Also: :func:`mixChannels`,:func:`split`,:func:`reshape` .. index:: min @@ -1634,7 +1630,7 @@ In the second variant, when the source array is multi-channel, each channel is c The first 3 variants of the function listed above are actually a part of :ref:`MatrixExpressions` , they return the expression object that can be further transformed, or assigned to a matrix, or passed to a function etc. -See also: +See Also: :func:`max`,:func:`compare`,:func:`inRange`,:func:`minMaxLoc`,:ref:`MatrixExpressions` .. index:: minMaxLoc @@ -1680,7 +1676,7 @@ The functions do not work with multi-channel arrays. If you need to find minimum in the case of a sparse matrix the minimum is found among non-zero elements only. -See also: +See Also: :func:`max`,:func:`min`,:func:`compare`,:func:`inRange`,:func:`extractImageCOI`,:func:`mixChannels`,:func:`split`,:func:`reshape` . .. index:: mixChannels @@ -1736,7 +1732,7 @@ BGR (i.e. with R and B channels swapped) and separate alpha channel image: :: Note that, unlike many other new-style C++ functions in OpenCV (see the introduction section and :func:`Mat::create` ), ``mixChannels`` requires the destination arrays be pre-allocated before calling the function. -See also: +See Also: :func:`split`,:func:`merge`,:func:`cvtColor` .. index:: mulSpectrums @@ -1801,7 +1797,7 @@ There is also If you are looking for a matrix product, not per-element product, see :func:`gemm` . -See also: +See Also: :func:`add`,:func:`substract`,:func:`divide`,:ref:`MatrixExpressions`,:func:`scaleAdd`,:func:`addWeighted`,:func:`accumulate`,:func:`accumulateProduct`,:func:`accumulateSquare`,:func:`Mat::convertTo` .. index:: mulTransposed @@ -1843,7 +1839,7 @@ otherwise. The function is used to compute covariance matrix and with zero delta :math:`A*B` when :math:`B=A^T` . -See also: +See Also: :func:`calcCovarMatrix`,:func:`gemm`,:func:`repeat`,:func:`reduce` .. index:: norm @@ -1958,7 +1954,7 @@ The optional mask specifies the sub-array to be normalize, that is, the norm or in the case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed, since it can shift the zero level. -See also: +See Also: :func:`norm`,:func:`Mat::convertScale`,:func:`MatND::convertScale`,:func:`SparseMat::convertScale` .. index:: PCA @@ -2036,7 +2032,7 @@ The following sample is the function that takes two matrices. The first one stor } -See also: +See Also: :func:`calcCovarMatrix`,:func:`mulTransposed`,:func:`SVD`,:func:`dft`,:func:`dct` .. index:: PCA::PCA @@ -2173,7 +2169,7 @@ Note that the function transforms a sparse set of 2D or 3D vectors. If you want :func:`getPerspectiveTransform` or :func:`findHomography` . -See also: +See Also: :func:`transform`,:func:`warpPerspective`,:func:`getPerspectiveTransform`,:func:`findHomography` .. index:: phase @@ -2205,7 +2201,7 @@ The angle estimation accuracy is :math:`\sim\,0.3^\circ` , when ``x(I)=y(I)=0`` , the corresponding ``angle`` (I) is set to :math:`0` . -See also: +See Also: .. index:: polarToCart @@ -2237,7 +2233,7 @@ The function ``polarToCart`` computes the cartesian coordinates of each 2D vecto The relative accuracy of the estimated coordinates is :math:`\sim\,10^{-6}` . -See also: +See Also: :func:`cartToPolar`,:func:`magnitude`,:func:`phase`,:func:`exp`,:func:`log`,:func:`pow`,:func:`sqrt` .. index:: pow @@ -2274,7 +2270,7 @@ That is, for a non-integer power exponent the absolute values of input array ele For some values of ``p`` , such as integer values, 0.5, and -0.5, specialized faster algorithms are used. -See also: +See Also: :func:`sqrt`,:func:`exp`,:func:`log`,:func:`cartToPolar`,:func:`polarToCart` .. index:: RNG @@ -2510,7 +2506,7 @@ The second non-template variant of the function fills the matrix ``mtx`` with un \texttt{low} _c \leq \texttt{mtx} (I)_c < \texttt{high} _c -See also: +See Also: :func:`RNG`,:func:`randn`,:func:`theRNG` . .. index:: randn @@ -2533,7 +2529,7 @@ randn The function ``randn`` fills the matrix ``mtx`` with normally distributed random numbers with the specified mean and standard deviation. is applied to the generated numbers (i.e. the values are clipped) -See also: +See Also: :func:`RNG`,:func:`randu` .. index:: randShuffle @@ -2553,7 +2549,7 @@ randShuffle :param rng: The optional random number generator used for shuffling. If it is zero, :func:`theRNG` () is used instead -The function ``randShuffle`` shuffles the specified 1D array by randomly choosing pairs of elements and swapping them. The number of such swap operations will be ``mtx.rows*mtx.cols*iterFactor`` See also: +The function ``randShuffle`` shuffles the specified 1D array by randomly choosing pairs of elements and swapping them. The number of such swap operations will be ``mtx.rows*mtx.cols*iterFactor`` See Also: :func:`RNG`,:func:`sort` .. index:: reduce @@ -2587,7 +2583,7 @@ reduce The function ``reduce`` reduces matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of an raster image. In the case of ``CV_REDUCE_SUM`` and ``CV_REDUCE_AVG`` the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes. -See also: :func:`repeat` +See Also: :func:`repeat` .. index:: repeat @@ -2618,7 +2614,7 @@ The functions \texttt{dst} _{ij}= \texttt{src} _{i \mod \texttt{src.rows} , \; j \mod \texttt{src.cols} } The second variant of the function is more convenient to use with -:ref:`MatrixExpressions` See also: +:ref:`MatrixExpressions` See Also: :func:`reduce`,:ref:`MatrixExpressions` .. index:: saturate_cast @@ -2660,7 +2656,7 @@ When the parameter is floating-point value and the target type is an integer (8- This operation is used in most simple or complex image processing functions in OpenCV. -See also: +See Also: :func:`add`,:func:`subtract`,:func:`multiply`,:func:`divide`,:func:`Mat::convertTo` .. index:: scaleAdd @@ -2697,7 +2693,7 @@ The function can also be emulated with a matrix expression, for example: :: A.row(0) = A.row(1)*2 + A.row(2); -See also: +See Also: :func:`add`,:func:`addWeighted`,:func:`subtract`,:func:`Mat::dot`,:func:`Mat::convertTo`,:ref:`MatrixExpressions` .. index:: setIdentity @@ -2728,7 +2724,7 @@ The function can also be emulated using the matrix initializers and the matrix e // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]] -See also: +See Also: :func:`Mat::zeros`,:func:`Mat::ones`,:ref:`MatrixExpressions`,:func:`Mat::setTo`,:func:`Mat::operator=` .. index:: solve @@ -2775,7 +2771,7 @@ Note that if you want to find unity-norm solution of an under-defined singular s :math:`\texttt{src1}\cdot\texttt{dst}=0` , the function ``solve`` will not do the work. Use :func:`SVD::solveZ` instead. -See also: +See Also: :func:`invert`,:func:`SVD`,:func:`eigen` .. index:: solveCubic @@ -2860,7 +2856,7 @@ sort The function ``sort`` sorts each matrix row or each matrix column in ascending or descending order. If you want to sort matrix rows or columns lexicographically, you can use STL ``std::sort`` generic function with the proper comparison predicate. -See also: +See Also: :func:`sortIdx`,:func:`randShuffle` .. index:: sortIdx @@ -2897,7 +2893,7 @@ The function ``sortIdx`` sorts each matrix row or each matrix column in ascendin // [[1, 2, 0], [0, 2, 1], [0, 1, 2]] -See also: +See Also: :func:`sort`,:func:`randShuffle` .. index:: split @@ -2928,7 +2924,7 @@ The functions ``split`` split multi-channel array into separate single-channel a \texttt{mv} [c](I) = \texttt{mtx} (I)_c If you need to extract a single-channel or do some other sophisticated channel permutation, use -:func:`mixChannels` See also: +:func:`mixChannels` See Also: :func:`merge`,:func:`mixChannels`,:func:`cvtColor` .. index:: sqrt @@ -2950,7 +2946,7 @@ sqrt The functions ``sqrt`` calculate square root of each source array element. in the case of multi-channel arrays each channel is processed independently. The accuracy is approximately the same as of the built-in ``std::sqrt`` . -See also: +See Also: :func:`pow`,:func:`magnitude` .. index:: subtract @@ -3019,7 +3015,7 @@ The first function in the above list can be replaced with matrix expressions: :: dst -= src2; // equivalent to subtract(dst, src2, dst); -See also: +See Also: :func:`add`,:func:`addWeighted`,:func:`scaleAdd`,:func:`convertScale`,:ref:`MatrixExpressions`,. .. index:: SVD @@ -3060,7 +3056,7 @@ Class for computing Singular Value Decomposition :: The class ``SVD`` is used to compute Singular Value Decomposition of a floating-point matrix and then use it to solve least-square problems, under-determined linear systems, invert matrices, compute condition numbers etc. For a bit faster operation you can pass ``flags=SVD::MODIFY_A|...`` to modify the decomposed matrix when it is not necessarily to preserve it. If you want to compute condition number of a matrix or absolute value of its determinant - you do not need ``u`` and ``vt`` , so you can pass ``flags=SVD::NO_UV|...`` . Another flag ``FULL_UV`` indicates that full-size ``u`` and ``vt`` must be computed, which is not necessary most of the time. -See also: +See Also: :func:`invert`,:func:`solve`,:func:`eigen`,:func:`determinant` .. index:: SVD::SVD @@ -3178,7 +3174,7 @@ sum The functions ``sum`` calculate and return the sum of array elements, independently for each channel. -See also: +See Also: :func:`countNonZero`,:func:`mean`,:func:`meanStdDev`,:func:`norm`,:func:`minMaxLoc`,:func:`reduce` .. index:: theRNG @@ -3194,7 +3190,7 @@ The function ``theRNG`` returns the default random number generator. For each th :func:`randu` or :func:`randn` instead. But if you are going to generate many random numbers inside a loop, it will be much faster to use this function to retrieve the generator and then use ``RNG::operator _Tp()`` . -See also: +See Also: :func:`RNG`,:func:`randu`,:func:`randn` .. index:: trace @@ -3259,7 +3255,7 @@ The function may be used for geometrical transformation of points, arbitrary linear color space transformation (such as various kinds of RGB :math:`\rightarrow` YUV transforms), shuffling the image channels and so forth. -See also: +See Also: :func:`perspectiveTransform`,:func:`getAffineTransform`,:func:`estimateRigidTransform`,:func:`warpAffine`,:func:`warpPerspective` .. index:: transpose