1. Product of matrix and Value
When an array is multiplied by a constant, the Mul function in the mat class is used.
//! per-element matrix multiplication by means of matrix expressionsMatExpr mul(InputArray m, double scale=1) const;
After use, the data is found to be abnormal, so every calculated value is printed,
It turns out that this function is used to multiply the matrix element in m by a quadratic operation and then a scale operation.
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale=1, int dtype=-1);
Set
Mat src2 = Mat::ones(src1.rows, src1.cols, src1.type());
Then multiply src1 and scale:
multiply(src1, src2, IResult, scale);
2. Product of matrix and Matrix
C (M * K) = A (M * n) * B (n * K)
You cannot use
<pre name="code" class="cpp">multiply(src1, src2, IResult, scale);
This function is used to calculate, because this function is only applicable to the calculation of the product of the corresponding points of two matrices of the same size.
Therefore, the gemm () function is used for calculation:
//! implements generalized matrix product algorithm GEMM from BLASCV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, int flags=0);
Note the meaning of flags during use: the default value is 0, indicating that all input matrices are not transposed.
DST = Alpha * src1 * src2 + gamma * src3
To transpose an input matrix, perform the following settings:
Flags-
Operation flags:
Gemm_1_t transposes src1.
Gemm_2_t transposes src2.
Gemm_3_t transposes src3.