Opencv matrix operations (3), opencv matrix operations

Source: Internet
Author: User

Opencv matrix operations (3), opencv matrix operations
Introduction

This article undertakes the previous article and continues to use matrix computing functions under opencv.
Specific Code for Matrix Replication
    printf("mat1:\n");    showMatdate(mat1);     mat3 = Mat(3, 3, CV_64FC1);    src3 = mat3;     cvRepeat(&src1, &src3);    printf("cvRepeat(mat1):\n");    showMatdate(mat3);
Result Display
    
Code for adding matrix proportions
    printf("mat1:\n");    showMatdate(mat1);    printf("mat2:\n");    showMatdate(mat2);     mat3 = Mat(3, 3, CV_64FC1);    src3 = mat3;     tmp.val[0] = 1.5;    cvScaleAdd(&src1, tmp, &src2, &src3);    printf("cvScaleAdd(mat1, tmp, mat2):\n");    showMatdate(mat3);
Note: mat3 = mat1 * tmp + mat2;
Result Display
    
Code for initializing the diagonal element of a Matrix
    printf("mat1:\n");    showMatdate(mat1);     mat3 = Mat(3, 3, CV_64FC1);    src3 = mat3;     tmp.val[0] = 1.5;    cvSetIdentity(&src1, tmp);    printf("cvSetIdentity(mat1, tmp):\n");                                                                                               showMatdate(mat1);
Note: The diagonal element is initially tmp, and the other elements are 0.
Result Display
    
Cubic Curve Equation solid root code
    printf("mat2:\n");    showMatdate(mat2);     mat3 = Mat(1, 3, CV_64FC1);    src3 = mat3;     CvMat tmp1 = mat2;    CvMat tmp2 = mat3;     cvSolveCubic(&tmp1, &tmp2);    printf("cvSolveCubic(mat2):\n");    showMatdate(mat3);
Note: there can be one or three solid roots.
Result Display
    
Code for Matrix Subtraction
    printf("mat1:\n");    showMatdate(mat1);    printf("mat2:\n");    showMatdate(mat2);     mat3 = Mat(3, 3, CV_64FC1);    src3 = mat3;     cvSub(&src1, &src2, &src3);    printf("cvSub(mat1, mat2):\n");                                                                                                      showMatdate(mat3);
Note: 1. You can select mask control at the end of void cvSub (const CvArr * src1, const CvArr * src2, CvArr * dst, and const CvArr * mask = NULL. 2. void cvSubRS (const CvArr * src, CvScalar value, CvArr * dst, const CvArr * mask = NULL) dst = value-src. 3. cvSubS (const CvArr * src, CvScalar value, CvArr * dst, const CvArr * mask = NULL) dst = src-val.
Result Display
    
Code for calculating the sum of Matrix Elements
    printf("mat1:\n");    showMatdate(mat1);     tmp = cvSum(&src1);    printf("cvSum(mat1);%lf\n", tmp.val[0]);
Result Display
    
Code for the sum of diagonal elements
    printf("mat1:\n");    showMatdate(mat1);     tmp = cvTrace(&src1);    printf("cvTrace(mat1);%lf\n", tmp.val[0]);
Result Display
    
Code for converting a computing matrix
    printf("mat1:\n");    showMatdate(mat1);     cvTranspose(&src1, &src3);    printf("cvTranspose(mat1);\n");    showMatdate(mat3);
Result Display
    
Other matrix operations

1. covariance of the calculated vector: calcCovarMatrix

2. Calculate the two-dimensional vector size and angle: cartToPolar

3. Check the invalid value in the input matrix: checkRange

4. convert other matrix formats to Mat: C ++: Mat cvarrToMat (const CvArr * arr, bool copyData = false, bool allowND = true, int coiMode = 0)

5. Perform a one-dimensional or two-dimensional array cosine transformation: C ++: void dct (InputArray src, OutputArray dst, int flags = 0)

6. Execute the forward and inverse Fourier transformation of one-dimensional or two-dimensional arrays: C ++: void dft (InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0)

7. Calculate the feature values and feature vectors of the symmetric matrix: void cvEigenVV (CvArr * mat, CvArr * evects, CvArr * evals, double eps = 0, int lowindex =-1, int highindex =-1)

8. Extract the selected image channel: void extractImageCOI (const CvArr * arr, OutputArray coiimg, int coi =-1)

9. Copy an image channel data to the old channel: void insertImageCOI (InputArray coiimg, CvArr * arr, int coi =-1)

10. Perform generalized matrix multiplication: void cvGEMM (const CvArr * src1, const CvArr * src2, double alpha, const CvArr * src3, double beta, CvArr * dst, int tABC = 0)

11. Return the optimal DFT size of the given vector: C ++: int getOptimalDFTSize (int vecsize)

12. Returns a single pixel Conversion Function: C ++: ConvertData getConvertElem (int fromType, int toType)

13. Calculate the inverse Discrete Cosine transformation of one or two dimensions: C ++: void idct (InputArray src, OutputArray dst, int flags = 0)

14. Calculate one-dimensional or inverse Discrete Fourier Transformation: C ++: void idft (InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0)

15. Check whether the array element is located between other array elements: C ++: void inRange (InputArray src, InputArray lowerb, InputArray upperb, OutputArray dst)

16. Vector perspective matrix transformation void cvPerspectiveTransform (const CvArr * src, CvArr * dst, const CvMat * mat)

17. Solves the least square method of one or more linear systems. Int cvSolve (const CvArr * src1, const CvArr * src2, CvArr * dst, int method = CV_LU)

18. Perform matrix transformation for each array element (which can be used for image rotation ). Void cvTransform (const CvArr * src, CvArr * dst, const CvMat * transmat, const CvMat * shiftvec = NULL)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.