seglink.py 文件源码

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

项目:seglink 作者: dengdan 项目源码 文件源码
def bboxes_to_xys(bboxes, image_shape):
    """Convert Seglink bboxes to xys, i.e., eight points
    The `image_shape` is used to to make sure all points return are valid, i.e., within image area
    """
    if len(bboxes) == 0:
        return []

    assert np.ndim(bboxes) == 2 and np.shape(bboxes)[-1] == 5, 'invalid `bboxes` param with shape =  ' + str(np.shape(bboxes))

    h, w = image_shape[0:2]
    def get_valid_x(x):
        if x < 0:
            return 0
        if x >= w:
            return w - 1
        return x

    def get_valid_y(y):
        if y < 0:
            return 0
        if y >= h:
            return h - 1
        return y

    xys = np.zeros((len(bboxes), 8))
    for bbox_idx, bbox in enumerate(bboxes):
        bbox = ((bbox[0], bbox[1]), (bbox[2], bbox[3]), bbox[4])
        points = cv2.cv.BoxPoints(bbox)
        points = np.int0(points)
        for i_xy, (x, y) in enumerate(points):
            x = get_valid_x(x)
            y = get_valid_y(y)
            points[i_xy, :] = [x, y]
        points = np.reshape(points, -1)
        xys[bbox_idx, :] = points
    return xys
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号