Product of opencv calculation matrix and value, product of matrix and Matrix

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.