當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。