fastAtan2函数解密
2015-04-20 20:44
615 查看
转载地址:http://www.csdn123.com/html/mycsdn20140110/18/1810e12f67a1c70147b5d668e8aeb935.html
--------------------------------------------------
高中数学中各种正弦函数,余弦函数总是把人搞得头大,但是具体应用时你会发现,其实你只需要搞清楚一个2π空间内函数分布即可。下面分析OpenCV中fastAtan2函数是怎么处理的方向问题。
fastAtan2函数在OpenCV中用户非常广,比如在SIFT描述子求取过程中需要计算特征点的方向,此时OpenCV的源码中就是使用的fastAtan2函数,fastAtan2函数原型如下:
y—向量的y坐标
输入一个2维向量,计算这个向量的方向,以度为单位(范围是0度---360度),精度是0.3度。
函数声明路径:/opencv-2.4.5/modules/core/include/opencv2/core/core.hpp
函数定义路径:/opencv-2.4.5/modules/core/src/mathfuncs.cpp
----------------------------------------------------------------------------------------------------------------------------------------------------------------
下图是OpenCV中fastAtan2函数的求解过程:
----------------------------------------------------------------------------------------------------------------------------------------------------------------
源码以及分析如下:
综上所述,fastAtan2函数得出的角度是以X轴正方向为0°方向,然后角度确定按照逆时针方向,以360°为终点,角度范围0°- 360°,即:
----
atan2该函数的值域为
,可以通过对负数结果加
的方法,将函数的结果映射到
范围内。
atan2值域示意图,上下都是以x轴正方向为基点
--------------------------------------------------
高中数学中各种正弦函数,余弦函数总是把人搞得头大,但是具体应用时你会发现,其实你只需要搞清楚一个2π空间内函数分布即可。下面分析OpenCV中fastAtan2函数是怎么处理的方向问题。
fastAtan2函数在OpenCV中用户非常广,比如在SIFT描述子求取过程中需要计算特征点的方向,此时OpenCV的源码中就是使用的fastAtan2函数,fastAtan2函数原型如下:
float fastAtan2(float y,float x)x—向量的x坐标
y—向量的y坐标
输入一个2维向量,计算这个向量的方向,以度为单位(范围是0度---360度),精度是0.3度。
函数声明路径:/opencv-2.4.5/modules/core/include/opencv2/core/core.hpp
函数定义路径:/opencv-2.4.5/modules/core/src/mathfuncs.cpp
----------------------------------------------------------------------------------------------------------------------------------------------------------------
下图是OpenCV中fastAtan2函数的求解过程:
----------------------------------------------------------------------------------------------------------------------------------------------------------------
源码以及分析如下:
static const float atan2_p1 = 0.9997878412794807f*(float)(180/CV_PI); static const float atan2_p3 = -0.3258083974640975f*(float)(180/CV_PI); static const float atan2_p5 = 0.1555786518463281f*(float)(180/CV_PI); static const float atan2_p7 = -0.04432655554792128f*(float)(180/CV_PI); float fastAtan2( float y, float x ) { float ax = std::abs(x), ay = std::abs(y);//首先不分象限,求得一个锐角角度 float a, c, c2; if( ax >= ay ) { c = ay/(ax + (float)DBL_EPSILON); c2 = c*c; a = (((atan2_p7*c2 + atan2_p5)*c2 + atan2_p3)*c2 + atan2_p1)*c; } else { c = ax/(ay + (float)DBL_EPSILON); c2 = c*c; a = 90.f - (((atan2_p7*c2 + atan2_p5)*c2 + atan2_p3)*c2 + atan2_p1)*c; } if( x < 0 )//锐角求出后,根据x和y的正负性确定向量的方向,即角度。 a = 180.f - a; if( y < 0 ) a = 360.f - a; return a; }
综上所述,fastAtan2函数得出的角度是以X轴正方向为0°方向,然后角度确定按照逆时针方向,以360°为终点,角度范围0°- 360°,即:
----
atan2该函数的值域为
,可以通过对负数结果加
的方法,将函数的结果映射到
范围内。
atan2值域示意图,上下都是以x轴正方向为基点
相关文章推荐
- OpenCV学习:fastAtan2函数解密
- OpenCV学习:fastAtan2函数解密
- fastjson工具函数json和java对象相互转化
- 函数调用方法: _cdecl _stdcall PASCAL _fastcall _thiscall
- PHP&nbsp;url 加密解密函数
- javascript(js)使用eval方法加密过的函数解密方法
- 函数调用方式__stdecl _stdcall _fastcall __thiscall介绍
- PHP url 加密解密函数代码
- 函数调用约定 stdcall cdecl fastcall thiscall naked call
- 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal, __thiscall)
- c# 加密 解密函数, 加密 解密 算法,自定义密钥
- ASP 下 能作为json输出后js能解密的 escape 函数
- 一段加密解密函数
- PHP加密函数 Javascript/Js 解密函数
- C# 现成能用的字符串加密、解密函数
- C/C++中函数调用规则(约定)__cdecl __stdcall __thiscall __vectorcall __fastcall __clrcall
- PHP加密函数 Javascript/Js 解密函数
- 一个异或加密解密函数
- WEB开发常用的几个函数(获取IP,MD5加密解密,HTML转义字符)
- 2个比较经典的PHP加密解密函数分享