Rotation-RetinaNet-PyTorch icon indicating copy to clipboard operation
Rotation-RetinaNet-PyTorch copied to clipboard

对poly2obb_np_oc注释的疑问

Open ztysdu opened this issue 2 years ago • 0 comments

您好,感谢您的代码.我在自己的机器上跑通了您的代码,并且效果很好.学习您的代码过程中,我有一个小问题. 您的代码中poly2obb_np_oc是这样写的


def poly2obb_np_oc(poly):
    """ Modified !!
    Convert polygons to oriented bounding boxes.
    Args:
        polys (ndarray): [x0,y0,x1,y1,x2,y2,x3,y3]
    Returns:
        obbs (ndarray): [x_ctr,y_ctr,w,h,angle] modified -> [x_ctr, y_ctr, h, w, angle(radian)]
    """
    bboxps = np.array(poly).reshape((4, 2))
    rbbox = cv2.minAreaRect(bboxps)
    x, y, h, w, a = rbbox[0][0], rbbox[0][1], rbbox[1][0], rbbox[1][1], rbbox[2]
    # assert 0 < a <= 90, f'error from poly2obb_np_oc function.'
    if w < 2 or h < 2:
        return
    while not 0 < a <= 90:
        if a == -90:
            a += 180
        else:
            a += 90
            w, h = h, w
    a = a / 180 * np.pi
    assert 0 < a <= np.pi / 2
    return x, y, h, w, a

在cv2.__version__为4.5.5的环境中,我进行了测试.我认为 x, y, h, w, a = rbbox[0][0], rbbox[0][1], rbbox[1][0], rbbox[1][1], rbbox[2] 应该为 x, y, w, h, a = rbbox[0][0], rbbox[0][1], rbbox[1][0], rbbox[1][1], rbbox[2] 即w应该为rbbox[1][0],h应该为rbbox[1][1].并且,我在mmrotate上找到同样的函数


def poly2obb_np_oc(poly):
    """Convert polygons to oriented bounding boxes.
    Args:
        polys (ndarray): [x0,y0,x1,y1,x2,y2,x3,y3]
    Returns:
        obbs (ndarray): [x_ctr,y_ctr,w,h,angle]
    """
    bboxps = np.array(poly).reshape((4, 2))
    rbbox = cv2.minAreaRect(bboxps)
    x, y, w, h, a = rbbox[0][0], rbbox[0][1], rbbox[1][0], rbbox[1][1], rbbox[
        2]
    if w < 2 or h < 2:
        return
    while not 0 < a <= 90:
        if a == -90:
            a += 180
        else:
            a += 90
            w, h = h, w
    a = a / 180 * np.pi
    assert 0 < a <= np.pi / 2
    return x, y, w, h, a

mmrotate该函数实现 所以我很困惑您注释中的
obbs (ndarray): [x_ctr,y_ctr,w,h,angle] modified -> [x_ctr, y_ctr, h, w, angle(radian)].

ztysdu avatar Apr 16 '23 07:04 ztysdu