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


Python pyclipper.JT_ROUND属性代码示例

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


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

示例1: shrink

# 需要导入模块: import pyclipper [as 别名]
# 或者: from pyclipper import JT_ROUND [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

示例2: shrink

# 需要导入模块: import pyclipper [as 别名]
# 或者: from pyclipper import JT_ROUND [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

示例3: generate_rbox

# 需要导入模块: import pyclipper [as 别名]
# 或者: from pyclipper import JT_ROUND [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 JT_ROUND [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 JT_ROUND [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 JT_ROUND [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 JT_ROUND [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.JT_ROUND属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。