opencv学习日常之Mat的代数运算

来源:互联网 发布:淘宝网店助理 编辑:程序博客网 时间:2024/05/23 20:17

opencv 矩阵的代数运算,

注意点:
Mat m0,m1,m2;
m2 = m1 和 m2 = m0 +m1;

  1. m2 = m1 : 两个矩阵的data指针指向同一块数据域
  2. m2 = m0+m1: 首先 m0 和m1对应的位置相加,然后为m2重新开辟数据域存储新的数据

Mat的代数运算如下列表:

**m0 + m1, m0 – m1;**   // Addition or subtraction of matrices**m0 + s; m0 – s; s + m0, s – m1**; //Addition or subtraction     //between a matrix and a singleton**-m0**; //Negation of a matrix**s * m0; m0 * s;** // Scaling of a matrix by a singleton**m0.mul( m1 ); m0/m1;**// Per element multiplication of m0 and m1,//per-element division of m0 by m1,(对应元素相乘和相除)**m0 * m1;** //Matrix multiplication of m0 and m1 矩阵乘法**m0.inv( method );** //Matrix inversion of m0 (default value of   //method is DECOMP_LU) 逆矩阵**m0>m1; m0>=m1; m0==m1; m0<=m1; m0<m1;** //Per element comparison, //returns uchar matrix with elements 0 or 255**m0&m1; m0|m1; m0^m1; ~m0;****m0&s; s&m0; m0|s; s|m0; m0^s; s^m0;**//Bitwise logical operators //between matrices or matrix and a singleton**min(m0,m1); max(m0,m1); min(m0,s);****min(s,m0); max(m0,s); max(s,m0);**//Per element minimum and //maximum between two matrices or a matrix and a singleton**cv::abs( m0 );**// Per element absolute value of m0**m0.cross( m1 ); m0.dot( m1 );**//Vector cross and dot product //(vector cross product is only defined for 3-by-1 matrices)**cv::Mat::eye( Nr, Nc, type );** //Class static matrix //initializers that return

其中有个小数学知识需要回顾下:

向量的叉乘和点乘

向量 a = (a1,b1,c1) b = (a2,b2,c2);
点乘: a.b = ( a1a2+b1b2+c1c2)
叉乘:
axb =
i, j , k
a1, b1 , c1
a2, b2 , c2
= (b1c2-b2c1,c1a2-a1c2,a1b2-a2b1)

0 0