OpenCV中基本数据结构(8)_Complex

Complex为OpenCV中的复数表示类,与STL 中的complex类似但是不一样,两者可以互换,与STL的complex最大的不同是,STL中获取到实部和虚部的值 分别使用real()和image(),而OpenCV是直接使用类中的成员变量re和im获取,相比STL 使用更加高效方便。

下面来自以《learning Opencv3》一段说明,(书中重要的原句,给没时间阅读原著的开发者,直接列出来,方便阅读):

The most substantial difference between the OpenCV and STL complex number classes is in member access.In the STL classes, the real and imaginary parts are accessed through the member functions real() and imag(), while in the OpenCV  class, they are directly accessible as (public) member variables re and im.

Complex类支持的预定义数据类型

Complex类支持的预定于数据类型为float 和 double,如下:

typedef Complex<float> Complexf;
        typedef Complex<double> Complexd;

Complex类

Complex类相对比较简单,原代码定义如下:

 Complex类使用总结:

Method Description
Complex() 默认构造函数
Complex( _Tp _re, _Tp _im = 0 )

带参数构造函数

re: 实部

im: 虚部

template<typename T2> operator Complex<T2>() 强制类型转换
Complex conj() 该复数的共轭
_Tp re, im;

re:实部值

im:虚部值

Complex类 operator重构

Complex类通过operator重构支持的运算符

operator Medthod
== template<typename _Tp> static inline
bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b)
!= template<typename _Tp> static inline
bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b)
+ template<typename _Tp> static inline
Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b)
template<typename _Tp> static inline
Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a)
+= template<typename _Tp> static inline
Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b)
- template<typename _Tp> static inline
Complex<_Tp> operator - (const Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp> operator - (const Complex<_Tp>& a)
template<typename _Tp> static inline
Complex<_Tp> operator - (const Complex<_Tp>& a, _Tp b)
template<typename _Tp> static inline
Complex<_Tp> operator - (_Tp b, const Complex<_Tp>& a)
-= template<typename _Tp> static inline
Complex<_Tp>& operator -= (Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp>& operator -= (Complex<_Tp>& a, _Tp b)
* template<typename _Tp> static inline
Complex<_Tp> operator * (const Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp> operator * (const Complex<_Tp>& a, _Tp b)
template<typename _Tp> static inline
Complex<_Tp> operator * (_Tp b, const Complex<_Tp>& a)
*= template<typename _Tp> static inline
Complex<_Tp>& operator *= (Complex<_Tp>& a, _Tp b)
abs template<typename _Tp> static inline
double abs(const Complex<_Tp>& a)
/ template<typename _Tp> static inline
Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline
Complex<_Tp> operator / (const Complex<_Tp>& a, _Tp b)
template<typename _Tp> static inline
Complex<_Tp> operator / (_Tp b, const Complex<_Tp>& a)
/= template<typename _Tp> static inline
Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b)
template<typename _Tp> static inline Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b)