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:虚部值

简单用例:

#include <stdio.h>
#include "opencv2/opencv.hpp"using namespace cv;
using namespace std;void main()
{Complexf cf1;Complexf cf2(12.1, 3124.23);Complexf cf3(5454.3432);cout << "cf1 = " << cf1 << endl;cout << "cf2 = " << cf2 << endl;cout << "cf3 = " << cf3 << endl;cf1.re = 3297;cf1.im = 3534.2343;cout << "cf1 = " << cf1 << endl;cout << "cf1.conj() = " << cf1.conj()<< endl;
}

结果:

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)

用例:

#include <stdio.h>
#include "opencv2/opencv.hpp"using namespace cv;
using namespace std;void main()
{Complexf cf1;Complexf cf2(12.1, 3124.23);cf1.re = 3297;cf1.im = 3534.2343;cout << "cf1 = " << cf1 << endl;cout << "cf2 = " << cf2<< endl;cout << "(cf1+cf2) = " << (cf1 + cf2) << endl;cf2 += cf1;cout << "cf2 += cf1 = " << cf2 << endl;cout << "(cf2 - cf1) = " << (cf2 - cf1) << endl;cout << "cf1 *2 = " << cf1 *(float)2.0 << endl;cout << "cf1 *cf2 = " << cf1 *cf2 << endl;cout << "cf1 /cf2 = " << cf1 /cf2 << endl;
}

运行结果:

OpenCV中基本数据结构(8)_Complex相关推荐

  1. OPENCV中图像数据结构及其转化

    OPENCV中图像数据结构及其转化 1. IplImage 它是openCV库中表示图像的结构体. 初始化: cvLoadImage(),cvCreateImage() 访问元素:[行指针] b = ...

  2. OPENCV中的数据结构总结

    最近在写自己的算法,其实就是对一些传统算法的改进.传统算法可以参考opecv的源代码.在阅读源代码的过程中,我慢慢领会到了opencv的强大之处,并不是因为它实现了各种算法,而是在于它对于基本数据结构 ...

  3. OpenCV中的数据结构

    首先介绍2维点对Point_,它的是一个模板类.我们可以直接访问数据成员x,y.它不仅定了+.-.==.!=这4个基本的操作,还定义了点乘.叉乘等操作.特别的这个类还提供了inside函数来判断一个点 ...

  4. OpenCV中基本数据结构(4)_Rect

    Rect数据结构经常是在OpenCV中被用来表示为一个矩形尺寸,其成员包括x,y, width,height,其中x和y分别表示矩形框的左上角的起始点坐标,width和height分别表示宽和高. R ...

  5. OpenCV中基本数据结构(1)_Point

    为了便于对一些常见的数据进行操作,OpenCV定义了一些常见的数据结构(Point ,Scalar等),以方便后续对数据算法的实现,主要分为basic data type.helper objects ...

  6. OpenCV中基本数据结构(6)_Matx

    Matx为OpenCV轻量级的矩阵,被称为fixed matrix classes,意思是每个矩阵的大小都是固定的,主要是应对矩阵数据比较小的场景,最新的版本4.0不超过6*6大小的矩阵,旧版本一般不 ...

  7. OpenCV中基本数据结构(7)_Vec

    Vec系列数据结构是Matx的一个派生类,其矩阵的行的大小永远固定为一行,列大小从1到6不等,可以认为类似与C++ vector,但与C++ 的vector又有很大不同,,以下不同来自于一段技术博客, ...

  8. OpenCV中基本数据结构(5)_RotatedRect

    RotatedRect也是表示一个矩形框,但是与Rect不同的是,RotatedRect可以带倾斜角的矩形,如下图所示: RotatedRect结构中包括三个变量: Point2f center:为矩 ...

  9. OpenCV中Mat数据结构使用举例

    #include "stdafx.h" #include <string> #include <iostream> #include <opencv2 ...

最新文章

  1. 华为魔术手机拆机图解_华为P40 Pro上手体验
  2. JAVA中return与finally的先后关系
  3. 使用NPOI和委托做EXCEL导出
  4. jslint4java_JSLint检测javascript的错误提示
  5. python 分类 投票_LightGBM——提升机器算法(图解+理论+安装方法+python代码)
  6. Maven 国内镜像很慢解决的方法
  7. 理解vue中的组件(二)
  8. java线程基础(一些常见多线程用法)
  9. [已送完]赠送Google Wave 邀请码
  10. 使用 IntraWeb (2) - Hello IntraWeb
  11. OpenERP __sql_constrants doesn't work.
  12. 苹果手机itunes显示无法连接服务器,苹果手机无法连接到iTunes Store怎么办 连接失败解决方法...
  13. Android Studio制作.9图片,看这一篇就够了
  14. GITEE提交代码时出现“文本是相同的,但文件不匹配“问题解决方法
  15. 带你了解什么是产品经理,产品经理究竟做什么的【产品入门】
  16. NVML编译官方用例报错
  17. 智能家居Homekit系列一智能插座
  18. linux 用户磁盘限额quota
  19. 野蛮删除腾讯电脑管家
  20. 2012淘宝校园招聘笔试

热门文章

  1. 基于百度地图API的微信周边搜索
  2. Spring MVC 实践 - Component
  3. gcc学习(一)[第二版]
  4. angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  5. php 与 memcache 笔记
  6. Swift解决【闭包引起的循环强引用】
  7. android获取系统当前年月日时分秒的时间
  8. object-c中对文件和url操作
  9. 备注:centos加永久路由
  10. 信息学奥赛一本通 2031:【例4.17】四位完全平方数