imageutil.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:nuts-ml 作者: maet3608 项目源码 文件源码
def annotation2pltpatch(annotation, **kwargs):
    """
    Convert geometric annotation to matplotlib geometric objects (=patches)

    For details regarding matplotlib patches see:
    http://matplotlib.org/api/patches_api.html
    For annotation formats see:
    imageutil.annotation2coords

    :param annotation annotation: Annotation of an image region such as
      point, circle, rect or polyline
    :return: matplotlib.patches
    :rtype: generator over matplotlib patches
    """
    if not annotation or isnan(annotation):
        return
    kind, geometries = annotation
    for geo in geometries:
        if kind == 'point':
            pltpatch = plp.CirclePolygon((geo[0], geo[1]), 1, **kwargs)
        elif kind == 'circle':
            pltpatch = plp.Circle((geo[0], geo[1]), geo[2], **kwargs)
        elif kind == 'rect':
            x, y, w, h = geo
            pltpatch = plp.Rectangle((x, y), w, h, **kwargs)
        elif kind == 'polyline':
            pltpatch = plp.Polygon(geo, closed=False, **kwargs)
        else:
            raise ValueError('Invalid kind of annotation: ' + kind)
        yield pltpatch
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号