opencv 判断点相对于轮廓的位置关系

时间:2021-08-18 10:41:57

网上说的好多都错了,opencv里的pointPolygonTest()函数确实可以判断点相对于轮廓的位置关系,

但关于参数measureDist的作用却说错了,官方文档解释如下:

Performs a point-in-contour test.

The function determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively. Otherwise, the return value is a signed distance between the point and the nearest contour edge.

翻译过来就是:

measureDist为false时才能判断位置关系,返回值+1(在轮廓里面)、-1(在轮廓外面)、0(在轮廓上)

官方文档说是Test的函数,可能是说判断结果不太准确,慎用。