OpenCV Mat 四则运算符实现矩阵运算
Mat 数据类型可以直接利用某些数学四则运算符进行矩阵的运算.
如下解释:
OpenCV referance manual P461
Matrix Expressions
This is a list of implemented matrix operations that can be combined in arbitrary complex expressions
(here A, B stand for matrices (Mat), s for a scalar (Scalar),
for a real-valued scalar
(double)):
addition, subtraction, negation: A B; A s; s A; A
scaling: A*
, A/
per-element multiplication and division: A.mul(B), A/B, α/A
matrix multiplication: A*B
transposition: A.t() At
matrix inversion and pseudo-inversion, solving linear systems and least-squares problems:
A.inv([method]) A1, A.inv([method])*B X : AX = B
comparison: A T B; A 6= B; A T
; A 6=
. 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.
bitwise logical operations: A & B, A & s, A | B, A | s, A ˆB, A ˆs, ˜A
element-wise minimum and maximum: min(A, B), min(A,
), max(A, B), max(A,
)
element-wise absolute value: abs(A)
cross-product, dot-product: A.cross(B), A.dot(B)
any function of matrix or matrices and scalars that returns a matrix or a scalar, such as
cv::norm, cv::mean, cv::sum, cv::countNonZero, cv::trace, cv::determinant, cv::repeat
etc.
matrix initializers (eye(), zeros(), ones()), matrix comma-separated initializers, matrix
constructors and operators that extract sub-matrices (see Mat description).§
Mat_<destination_type>() 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_<T>() constuctor calls to resolve possible ambiguity.