當前位置: 首頁>>代碼示例>>Python>>正文


Python pyclipper.PyclipperOffset方法代碼示例

本文整理匯總了Python中pyclipper.PyclipperOffset方法的典型用法代碼示例。如果您正苦於以下問題:Python pyclipper.PyclipperOffset方法的具體用法?Python pyclipper.PyclipperOffset怎麽用?Python pyclipper.PyclipperOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyclipper的用法示例。


在下文中一共展示了pyclipper.PyclipperOffset方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: shrink

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def shrink(bboxes, rate, max_shr=20):
    rate = rate * rate
    shrinked_bboxes = []
    for bbox in bboxes:
        area = plg.Polygon(bbox).area()
        peri = perimeter(bbox)

        pco = pyclipper.PyclipperOffset()
        pco.AddPath(bbox, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
        offset = min((int)(area * (1 - rate) / (peri + 0.001) + 0.5), max_shr)
        
        shrinked_bbox = pco.Execute(-offset)
        if len(shrinked_bbox) == 0:
            shrinked_bboxes.append(bbox)
            continue
        
        shrinked_bbox = np.array(shrinked_bbox[0])
        if shrinked_bbox.shape[0] <= 2:
            shrinked_bboxes.append(bbox)
            continue
        
        shrinked_bboxes.append(shrinked_bbox)
    
    return np.array(shrinked_bboxes) 
開發者ID:rahzaazhar,項目名稱:PAN-PSEnet,代碼行數:26,代碼來源:ctw1500_loader.py

示例2: shrink

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def shrink(bboxes, rate, max_shr=20):
    rate = rate * rate
    shrinked_bboxes = []
    for bbox in bboxes:
        area = plg.Polygon(bbox).area()
        peri = perimeter(bbox)

        pco = pyclipper.PyclipperOffset()
        pco.AddPath(bbox, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
        offset = min((int)(area * (1 - rate) / (peri + 0.001) + 0.5), max_shr)
        
        shrinked_bbox = pco.Execute(-offset)
        if len(shrinked_bbox) == 0:
            shrinked_bboxes.append(bbox)
            continue
        
        shrinked_bbox = np.array(shrinked_bbox)[0]
        if shrinked_bbox.shape[0] <= 2:
            shrinked_bboxes.append(bbox)
            continue
        
        shrinked_bboxes.append(shrinked_bbox)
    
    return np.array(shrinked_bboxes) 
開發者ID:rahzaazhar,項目名稱:PAN-PSEnet,代碼行數:26,代碼來源:icdar2015_loader.py

示例3: generate_rbox

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def generate_rbox(im_size, text_polys, text_tags, training_mask, shrink_ratio):
    """
    生成mask圖,白色部分是文本,黑色是北京
    :param im_size: 圖像的h,w
    :param text_polys: 框的坐標
    :param text_tags: 標注文本框是否參與訓練
    :param training_mask: 忽略標注為 DO NOT CARE 的矩陣
    :return: 生成的mask圖
    """
    h, w = im_size
    G_s = np.zeros((h, w), dtype=np.float32)
    G_d = np.zeros((h, w), dtype=np.float32)
    for i, (poly, tag) in enumerate(zip(text_polys, text_tags)):
        try:
            poly = poly.astype(np.int)
            # D = cv2.contourArea(poly) * (1 - shrink_ratio * shrink_ratio) / cv2.arcLength(poly, True)
            D = cv2.contourArea(poly) * (1 - shrink_ratio) / cv2.arcLength(poly, True) + 0.5
            pco = pyclipper.PyclipperOffset()
            pco.AddPath(poly, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
            shrinked_poly = np.array(pco.Execute(-D))
            # dilated_poly = np.array(pco.Execute(D))
            dilated_poly = np.array(pco.Execute(0))
            cv2.fillPoly(G_s, shrinked_poly, 1)
            cv2.fillPoly(G_d, dilated_poly, 1)
            if not tag:
                cv2.fillPoly(training_mask, shrinked_poly, 0)
        except:
            print(poly)
    # return score_map, training_mask
    return G_s, G_d, training_mask 
開發者ID:SURFZJY,項目名稱:Real-time-Text-Detection,代碼行數:32,代碼來源:data_utils.py

示例4: unclip

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def unclip(self, box, unclip_ratio=1.5):
        poly = Polygon(box)
        distance = poly.area * unclip_ratio / poly.length
        offset = pyclipper.PyclipperOffset()
        offset.AddPath(box, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
        expanded = np.array(offset.Execute(distance))
        return expanded 
開發者ID:WenmuZhou,項目名稱:DBNet.pytorch,代碼行數:9,代碼來源:seg_detector_representer.py

示例5: shrink_polygon_pyclipper

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def shrink_polygon_pyclipper(polygon, shrink_ratio):
    from shapely.geometry import Polygon
    import pyclipper
    polygon_shape = Polygon(polygon)
    distance = polygon_shape.area * (1 - np.power(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)
    shrinked = padding.Execute(-distance)
    if shrinked == []:
        shrinked = np.array(shrinked)
    else:
        shrinked = np.array(shrinked[0]).reshape(-1, 2)
    return shrinked 
開發者ID:WenmuZhou,項目名稱:DBNet.pytorch,代碼行數:16,代碼來源:make_shrink_map.py

示例6: expandPathsToPolygons

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def expandPathsToPolygons(pathList, offset):
    import pyclipper
    # Use PyclipperOffset to generate polygons that surround the original
    # paths with a constant offset all around
    co = pyclipper.PyclipperOffset()
    for path in pathList: co.AddPath(path, pyclipper.JT_ROUND, pyclipper.ET_OPENROUND)
    return co.Execute(offset)

# A small pyclipper wrapper to trim parts of a polygon using another polygon 
開發者ID:easyw,項目名稱:RF-tools-KiCAD,代碼行數:11,代碼來源:viafence.py

示例7: draw_border_map

# 需要導入模塊: import pyclipper [as 別名]
# 或者: from pyclipper import PyclipperOffset [as 別名]
def draw_border_map(self, polygon, canvas, mask):
        polygon = np.array(polygon)
        assert polygon.ndim == 2
        assert polygon.shape[1] == 2

        polygon_shape = Polygon(polygon)
        if polygon_shape.area <= 0:
            return
        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])
        cv2.fillPoly(mask, [padded_polygon.astype(np.int32)], 1.0)

        xmin = padded_polygon[:, 0].min()
        xmax = padded_polygon[:, 0].max()
        ymin = padded_polygon[:, 1].min()
        ymax = padded_polygon[:, 1].max()
        width = xmax - xmin + 1
        height = ymax - ymin + 1

        polygon[:, 0] = polygon[:, 0] - xmin
        polygon[:, 1] = polygon[:, 1] - ymin

        xs = np.broadcast_to(
            np.linspace(0, width - 1, num=width).reshape(1, width), (height, width))
        ys = np.broadcast_to(
            np.linspace(0, height - 1, num=height).reshape(height, 1), (height, width))

        distance_map = np.zeros(
            (polygon.shape[0], height, width), dtype=np.float32)
        for i in range(polygon.shape[0]):
            j = (i + 1) % polygon.shape[0]
            absolute_distance = self.distance(xs, ys, polygon[i], polygon[j])
            distance_map[i] = np.clip(absolute_distance / distance, 0, 1)
        distance_map = distance_map.min(axis=0)

        xmin_valid = min(max(0, xmin), canvas.shape[1] - 1)
        xmax_valid = min(max(0, xmax), canvas.shape[1] - 1)
        ymin_valid = min(max(0, ymin), canvas.shape[0] - 1)
        ymax_valid = min(max(0, ymax), canvas.shape[0] - 1)
        canvas[ymin_valid:ymax_valid + 1, xmin_valid:xmax_valid + 1] = np.fmax(
            1 - distance_map[
                ymin_valid - ymin:ymax_valid - ymax + height,
                xmin_valid - xmin:xmax_valid - xmax + width],
            canvas[ymin_valid:ymax_valid + 1, xmin_valid:xmax_valid + 1]) 
開發者ID:WenmuZhou,項目名稱:DBNet.pytorch,代碼行數:51,代碼來源:make_border_map.py


注:本文中的pyclipper.PyclipperOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。