pyclipper的多边形操作(转载)
等距离缩放多边形:
参考博客:https://blog.csdn.net/jizhidexiaoming/article/details/134435885
文本检测DBnet中对标签的预处理里面需要用到这个操作:将文本标注框等距离缩放用于生成标签二值图像和阈值图像,如下所示:
备注:上图出自Dbnet论文
原来python有个库pyclipper自带这种操作,代码如下:
polygon_shape = Polygon(polygon)
distance = polygon_shape.area * \
(1 - np.power(self.shrink_ratio, 2)) / polygon_shape.length
subject = [tuple(l) for l in polygon]
padding = pyclipper.PyclipperOffset()
padding.AddPath(subject, pyclipper.JT_ROUND,
pyclipper.ET_CLOSEDPOLYGON)
padded_polygon = np.array(padding.Execute(distance)[0])
以上代码来自DBnet源码,distance是缩放的距离参数,负的是shrink,正的是dilate