当前位置: 首页>>代码示例>>Python>>正文


Python mask.merge方法代码示例

本文整理汇总了Python中pycocotools.mask.merge方法的典型用法代码示例。如果您正苦于以下问题:Python mask.merge方法的具体用法?Python mask.merge怎么用?Python mask.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycocotools.mask的用法示例。


在下文中一共展示了mask.merge方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __get_annotation__

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def __get_annotation__(self, mask, image=None):

        _, contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

        segmentation = []
        for contour in contours:
            # Valid polygons have >= 6 coordinates (3 points)
            if contour.size >= 6:
                segmentation.append(contour.flatten().tolist())
        RLEs = cocomask.frPyObjects(segmentation, mask.shape[0], mask.shape[1])
        RLE = cocomask.merge(RLEs)
        # RLE = cocomask.encode(np.asfortranarray(mask))
        area = cocomask.area(RLE)
        [x, y, w, h] = cv2.boundingRect(mask)

        if image is not None:
            image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            cv2.drawContours(image, contours, -1, (0,255,0), 1)
            cv2.rectangle(image,(x,y),(x+w,y+h), (255,0,0), 2)
            cv2.imshow("", image)
            cv2.waitKey(1)

        return segmentation, [x, y, w, h], area 
开发者ID:hazirbas,项目名称:coco-json-converter,代码行数:25,代码来源:generate_coco_json.py

示例2: annToRLE

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def annToRLE(self, ann, height, width):
        """
        Convert annotation which can be polygons, uncompressed RLE to RLE.
        :return: binary mask (numpy 2D array)
        """
        segm = ann['segmentation']
        if isinstance(segm, list):
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = maskUtils.frPyObjects(segm, height, width)
            rle = maskUtils.merge(rles)
        elif isinstance(segm['counts'], list):
            # uncompressed RLE
            rle = maskUtils.frPyObjects(segm, height, width)
        else:
            # rle
            rle = ann['segmentation']
        return rle 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:20,代码来源:coco.py

示例3: to_mask

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def to_mask(polys, size):
    """Convert list of polygons to full size binary mask

    Parameters
    ----------
    polys : list of numpy.ndarray
        Numpy.ndarray with shape (N, 2) where N is the number of bounding boxes.
        The second axis represents points of the polygons.
        Specifically, these are :math:`(x, y)`.
    size : tuple
        Tuple of length 2: (width, height).

    Returns
    -------
    numpy.ndarray
        Full size binary mask of shape (height, width)
    """
    try_import_pycocotools()
    import pycocotools.mask as cocomask
    width, height = size
    polys = [p.flatten().tolist() for p in polys]
    rles = cocomask.frPyObjects(polys, height, width)
    rle = cocomask.merge(rles)
    return cocomask.decode(rle) 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:26,代码来源:mask.py

示例4: annToRLE

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def annToRLE(ann, h, w):
    """
    Convert annotation which can be polygons, uncompressed RLE to RLE.
    :return: binary mask (numpy 2D array)
    """
    segm = ann['segmentation']
    if type(segm) == list:
        # polygon -- a single object might consist of multiple parts
        # we merge all parts into one mask rle code
        rles = maskUtils.frPyObjects(segm, h, w)
        rle = maskUtils.merge(rles)
    elif type(segm['counts']) == list:
        # uncompressed RLE
        rle = maskUtils.frPyObjects(segm, h, w)
    else:
        # rle
        rle = ann['segmentation']
    return rle 
开发者ID:alicranck,项目名称:coco2voc,代码行数:20,代码来源:coco2voc_aux.py

示例5: annToRLE

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def annToRLE(self, ann):
        """
        Convert annotation which can be polygons, uncompressed RLE to RLE.
        :return: binary mask (numpy 2D array)
        """
        t = self.imgs[ann['image_id']]
        h, w = t['height'], t['width']
        segm = ann['segmentation']
        if type(segm) == list:
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = maskUtils.frPyObjects(segm, h, w)
            rle = maskUtils.merge(rles)
        elif type(segm['counts']) == list:
            # uncompressed RLE
            rle = maskUtils.frPyObjects(segm, h, w)
        else:
            # rle
            rle = ann['segmentation']
        return rle 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:22,代码来源:coco.py

示例6: annToRLE

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def annToRLE(self, ann, height, width):
        """
        Convert annotation which can be polygons, uncompressed RLE to RLE.
        :return: binary mask (numpy 2D array)
        """
        segm = ann['segmentation']
        if isinstance(segm, list):
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = mask.frPyObjects(segm, height, width)
            rle = mask.merge(rles)
        elif isinstance(segm['counts'], list):
            # uncompressed RLE
            rle = mask.frPyObjects(segm, height, width)
        else:
            # rle
            rle = ann['segmentation']
        return rle 
开发者ID:nearthlab,项目名称:image-segmentation,代码行数:20,代码来源:coco_dataset.py

示例7: polygons_to_mask

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def polygons_to_mask(polys, height, width):
    """
    Convert polygons to binary masks.

    Args:
        polys: a list of nx2 float array. Each array contains many (x, y) coordinates.

    Returns:
        a binary matrix of (height, width)
    """
    polys = [p.flatten().tolist() for p in polys]
    assert len(polys) > 0, "Polygons are empty!"

    import pycocotools.mask as cocomask
    rles = cocomask.frPyObjects(polys, height, width)
    rle = cocomask.merge(rles)
    return cocomask.decode(rle) 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:19,代码来源:common.py

示例8: _poly2mask

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def _poly2mask(self, mask_ann, img_h, img_w):
        """Private function to convert masks represented with polygon to
        bitmaps.

        Args:
            mask_ann (list | dict): Polygon mask annotation input.
            img_h (int): The height of output mask.
            img_w (int): The width of output mask.

        Returns:
            numpy.ndarray: The decode bitmap mask of shape (img_h, img_w).
        """

        if isinstance(mask_ann, list):
            # polygon -- a single object might consist of multiple parts
            # we merge all parts into one mask rle code
            rles = maskUtils.frPyObjects(mask_ann, img_h, img_w)
            rle = maskUtils.merge(rles)
        elif isinstance(mask_ann['counts'], list):
            # uncompressed RLE
            rle = maskUtils.frPyObjects(mask_ann, img_h, img_w)
        else:
            # rle
            rle = mask_ann
        mask = maskUtils.decode(rle)
        return mask 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:28,代码来源:loading.py

示例9: polygon_to_bitmap

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def polygon_to_bitmap(polygons, height, width):
    """Convert masks from the form of polygons to bitmaps.

    Args:
        polygons (list[ndarray]): masks in polygon representation
        height (int): mask height
        width (int): mask width

    Return:
        ndarray: the converted masks in bitmap representation
    """
    rles = maskUtils.frPyObjects(polygons, height, width)
    rle = maskUtils.merge(rles)
    bitmap_mask = maskUtils.decode(rle).astype(np.bool)
    return bitmap_mask 
开发者ID:open-mmlab,项目名称:mmdetection,代码行数:17,代码来源:structures.py

示例10: convert

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def convert(self, mode):
        width, height = self.size
        if mode == "mask":
            rles = mask_utils.frPyObjects(
                [p.numpy() for p in self.polygons], height, width
            )
            rle = mask_utils.merge(rles)
            mask = mask_utils.decode(rle)
            mask = torch.from_numpy(mask)
            # TODO add squeeze?
            return mask 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:13,代码来源:segmentation_mask.py

示例11: convert_to_binarymask

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import merge [as 别名]
def convert_to_binarymask(self):
        width, height = self.size
        # formatting for COCO PythonAPI
        polygons = [p.numpy() for p in self.polygons]
        rles = mask_utils.frPyObjects(polygons, height, width)
        rle = mask_utils.merge(rles)
        mask = mask_utils.decode(rle)
        mask = torch.from_numpy(mask)
        return mask 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:11,代码来源:segmentation_mask.py


注:本文中的pycocotools.mask.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。