OpenCV函数解析之convexHull()

convexHull函数

C++:void convexHull(InputArray points, OutputArray hull, bool clockwise=false, bool returnPoints=true);

OpenCV源码中关于convexHull函数的文档注释如下:

/** @brief Finds the convex hull of a point set.

The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82
that has *O(N logN)* complexity in the current implementation.

@param points Input 2D point set, stored in std::vector or Mat.
@param hull Output convex hull. It is either an integer vector of indices or vector of points. In the first case, the hull elements are 0-based indices of the convex hull points in the original array (since the set of convex hull points is a subset of the original point set). In the second case, hull elements are the convex hull points themselves.
@param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise.Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing to the right, and its Y axis pointing upwards.
@param returnPoints Operation flag. In case of a matrix, when the flag is true, the function returns convex hull points. Otherwise, it returns indices of the convex hull points. When the output array is std::vector, the flag is ignored, and the output depends on the type of the vector: std::vector\<int\> implies returnPoints=false, std::vector\<Point\> implies
returnPoints=true.

@note `points` and `hull` should be different arrays, inplace processing isn't supported.
 */

有道翻译如下(勉强看吧....):

/ * * @example convexhull.cpp
一个使用convexHull功能的示例
* /

/** @brief找到一个点集的凸包。

函数cv::convexHull::利用Sklansky算法@cite Sklansky82找到2D点集的凸包
它在当前实现中具有*O(N logN)*复杂度。

@param输入2D点集,存储在std::vector或Mat中。
@param船体输出凸船体。它要么是指数的整数向量,要么是点的向量。在在第一种情况下,船体单元是最初凸船体点的基于0的指标数组(因为凸壳点集是原始点集的子集)。在第二个壳体元素是壳体本身的凸点。
@param顺时针方向标志。如果是,输出凸壳是顺时针方向。否则,它是逆时针方向的。假设坐标系有它的X轴指向
向右,Y轴向上。
@param返回点操作标志。对于矩阵,当标志为真时,函数返回凸壳点。否则,它返回凸壳点的索引。当输出数组为std::vector,该标志被忽略,并且输出取决于该标志的类型向量:std::vector\<int\>表示ReturnPoints=false, std::向量\<Point\>表示returnPoints = true。

@note ' points '和' hull '应该是不同的数组,不支持inplace处理。
* /

然后进行概括一下源码注释的意思:

第一个参数:输入的点集,可以是Mat型矩阵,也可以是std::vector<point>的点容器

第二个参数:可以为vector<int>,此时返回的是每个凸包点在原轮廓点容器中的索引,也可以为vector<Point>,此时存放的是凸包点的位置,即点(x,y)坐标。

第三个参数:bool变量,表示输出的凸包是顺时针方向还是逆时针方向,true是顺时针方向,false为逆时针方向,默认值是true,即顺时针方向输出凸包。

第四个参数:bool型变量returnPoints,表示第二个参数的输出类型,默认为true,即返回凸包的各个点,设置为false时,表示返回凸包各个点的索引。当第二个参数类型为std::vector,则该标志位被忽略,就是以第二个参数为准,即为vector<int>,此时返回的是每个凸包点在原轮廓点容器中的索引,为vector<Point>时,此时存放的是凸包点的位置,即点(x,y)坐标。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值