0

我试图用更快的 rcnn 检测定向边界框很长一段时间,但我无法做到这一点。我的目标是检测 DOTA 数据集中的对象。我在 pytorch 中使用了内置的更快的 rcnn 模型,但意识到它不支持 OBB。然后我找到了另一个构建在 pytorch 框架上的名为detectron2 的库。detectron2 中内置的更快的 rcnn 网络实际上与 OBB 兼容,但我无法使该模型与 DOTA 一起使用。因为我无法将 DOTA 框注释转换为(cx, cy, w, h, a). 在 DOTA 中,对象由 4 个角的坐标标注,它们是(x1,y1,x2,y2,x3,y3,x4,y4).

我想不出将这 4 个坐标转换为 的解决方案(cx, cy, w, h, a),其中 cx 和 cy 是 OBB 的中心点,w、h 和 a 分别是宽度、高度和角度。

有什么建议吗?

4

1 回答 1

1

如果您将框放在Nx8张量/数组中,则可以(cx, cy, w, h, a)通过以下方式将它们转换为(假设第一个点是左上角,第二个点是左下角,然后是右下角,然后是右上角......):

def DOTA_2_OBB(boxes):
    #calculate the angle of the box using arctan (degrees here)
    angle = (torch.atan((boxes[:,7] - boxes[:,5])/(boxes[:,6] - boxes[:,4]))*180/np.pi).float()
    #centrepoint is the mean of adjacent points
    cx = boxes[:,[4,0]].mean(1)
    cy = boxes[:,[7,3]].mean(1)
    #calculate w and h based on the distance between adjacent points
    w = ((boxes[:,7] - boxes[:,1])**2+(boxes[:,6] - boxes[:,0])**2)**0.5
    h = ((boxes[:,1] - boxes[:,3])**2+(boxes[:,0] - boxes[:,2])**2)**0.5
    return torch.stack([cx,cy,w,h,angle]).T   

然后给这个测试...

In [40]: boxes = torch.tensor([[0,2,1,0,2,2,1,3],[4,12,8,2,12,12,8,22]]).float()    
    
In [43]: DOTA_2_OBB(boxes)                                                                                            
Out[43]: 
tensor([[  1.0000,   1.5000,   1.4142,   2.2361, -45.0000],
        [  8.0000,  12.0000,  10.7703,  10.7703, -68.1986]])
        
于 2021-11-17T03:08:38.383 回答