(coords, mode=1)
return np.array(coords_new, dtype=np.float32)
:param coords: shape [-1, 5]
    :param mode: -1 convert coords range to [-90, 90), 1 convert coords range to [-90, 0)
    :return: shape [-1, 5]
:param coords: shape [-1, 5]
    :param mode: -1 convert coords range to [-90, 90), 1 convert coords range to [-90, 0)
    :return: shape [-1, 5]
: param coords : shape [ - 1 5 ] : param mode : - 1 convert coords range to [ - 90 90 ) 1 convert coords range to [ - 90 0 ) : return : shape [ - 1 5 ]
def coordinate_present_convert(coords, mode=1):
    """
    :param coords: shape [-1, 5]
    :param mode: -1 convert coords range to [-90, 90), 1 convert coords range to [-90, 0)
    :return: shape [-1, 5]
    """
    # angle range from [-90, 0) to [-180, 0)
    if mode == -1:
        w, h = coords[:, 2], coords[:, 3]

        remain_mask = np.greater(w, h)
        convert_mask = np.logical_not(remain_mask).astype(np.int32)
        remain_mask = remain_mask.astype(np.int32)

        remain_coords = coords * np.reshape(remain_mask, [-1, 1])

        coords[:, [2, 3]] = coords[:, [3, 2]]
        coords[:, 4] += 90

        convert_coords = coords * np.reshape(convert_mask, [-1, 1])

        coords_new = remain_coords + convert_coords

        coords_new[:, 4] -= 90

    # angle range from [-180, 0) to [-90, 0)
    elif mode == 1:
        coords[:, 4] += 90

        # theta = coords[:, 4]
        # remain_mask = np.logical_and(np.greater_equal(theta, -90), np.less(theta, 0))
        # convert_mask = np.logical_not(remain_mask)
        #
        # remain_coords = coords * np.reshape(remain_mask, [-1, 1])
        #
        # coords[:, [2, 3]] = coords[:, [3, 2]]
        # coords[:, 4] -= 90
        #
        # convert_coords = coords * np.reshape(convert_mask, [-1, 1])
        #
        # coords_new = remain_coords + convert_coords

        xlt, ylt = -1 * coords[:, 2] / 2.0, coords[:, 3] / 2.0
        xld, yld = -1 * coords[:, 2] / 2.0, -1 * coords[:, 3] / 2.0
        xrd, yrd = coords[:, 2] / 2.0, -1 * coords[:, 3] / 2.0
        xrt, yrt = coords[:, 2] / 2.0, coords[:, 3] / 2.0

        theta = -coords[:, -1] / 180 * np.pi

        xlt_ = np.cos(theta) * xlt + np.sin(theta) * ylt + coords[:, 0]
        ylt_ = -np.sin(theta) * xlt + np.cos(theta) * ylt + coords[:, 1]

        xrt_ = np.cos(theta) * xrt + np.sin(theta) * yrt + coords[:, 0]
        yrt_ = -np.sin(theta) * xrt + np.cos(theta) * yrt + coords[:, 1]

        xld_ = np.cos(theta) * xld + np.sin(theta) * yld + coords[:, 0]
        yld_ = -np.sin(theta) * xld + np.cos(theta) * yld + coords[:, 1]

        xrd_ = np.cos(theta) * xrd + np.sin(theta) * yrd + coords[:, 0]
        yrd_ = -np.sin(theta) * xrd + np.cos(theta) * yrd + coords[:, 1]

        convert_box = np.transpose(np.stack([xlt_, ylt_, xrt_, yrt_, xrd_, yrd_, xld_, yld_], axis=0))

        coords_new = backward_convert(convert_box, False)


    else:
        raise Exception('mode error!')

    return np.array(coords_new, dtype=np.float32)
def coordinate_present_convert ( coords , mode = 1 ) : # angle range from [-90, 0) to [-180, 0) if mode == - 1 : w , h = coords [ : , 2 ] , coords [ : , 3 ] remain_mask = np . greater ( w , h ) convert_mask = np . logical_not ( remain_mask ) . astype ( np . int32 ) remain_mask = remain_mask . astype ( np . int32 ) remain_coords = coords * np . reshape ( remain_mask , [ - 1 , 1 ] ) coords [ : , [ 2 , 3 ] ] = coords [ : , [ 3 , 2 ] ] coords [ : , 4 ] += 90 convert_coords = coords * np . reshape ( convert_mask , [ - 1 , 1 ] ) coords_new = remain_coords + convert_coords coords_new [ : , 4 ] -= 90 # angle range from [-180, 0) to [-90, 0) elif mode == 1 : coords [ : , 4 ] += 90 # theta = coords[:, 4] # remain_mask = np.logical_and(np.greater_equal(theta, -90), np.less(theta, 0)) # convert_mask = np.logical_not(remain_mask) # # remain_coords = coords * np.reshape(remain_mask, [-1, 1]) # # coords[:, [2, 3]] = coords[:, [3, 2]] # coords[:, 4] -= 90 # # convert_coords = coords * np.reshape(convert_mask, [-1, 1]) # # coords_new = remain_coords + convert_coords xlt , ylt = - 1 * coords [ : , 2 ] / 2.0 , coords [ : , 3 ] / 2.0 xld , yld = - 1 * coords [ : , 2 ] / 2.0 , - 1 * coords [ : , 3 ] / 2.0 xrd , yrd = coords [ : , 2 ] / 2.0 , - 1 * coords [ : , 3 ] / 2.0 xrt , yrt = coords [ : , 2 ] / 2.0 , coords [ : , 3 ] / 2.0 theta = - coords [ : , - 1 ] / 180 * np . pi xlt_ = np . cos ( theta ) * xlt + np . sin ( theta ) * ylt + coords [ : , 0 ] ylt_ = - np . sin ( theta ) * xlt + np . cos ( theta ) * ylt + coords [ : , 1 ] xrt_ = np . cos ( theta ) * xrt + np . sin ( theta ) * yrt + coords [ : , 0 ] yrt_ = - np . sin ( theta ) * xrt + np . cos ( theta ) * yrt + coords [ : , 1 ] xld_ = np . cos ( theta ) * xld + np . sin ( theta ) * yld + coords [ : , 0 ] yld_ = - np . sin ( theta ) * xld + np . cos ( theta ) * yld + coords [ : , 1 ] xrd_ = np . cos ( theta ) * xrd + np . sin ( theta ) * yrd + coords [ : , 0 ] yrd_ = - np . sin ( theta ) * xrd + np . cos ( theta ) * yrd + coords [ : , 1 ] convert_box = np . transpose ( np . stack ( [ xlt_ , ylt_ , xrt_ , yrt_ , xrd_ , yrd_ , xld_ , yld_ ] , axis = 0 ) ) coords_new = backward_convert ( convert_box , False ) else : raise Exception ( 'mode error!' ) return np . array ( coords_new , dtype = np . float32 )