1. 程式人生 > >opencv學習日常之Mat的代數運算

opencv學習日常之Mat的代數運算

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 //m
ethod 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)