FDDB数据集标注文件:椭圆转换矩形

FDDB数据集提供的人脸bbox是椭圆形,所以要通过求做小外接矩阵来转换矩形的人脸bbox。

def calculate_rectangle(A, B, C, F):
    '''
    椭圆上下外接点的纵坐标值
    '''
    y = np.sqrt(4*A*F / (B**2 - 4*A*C))
    y1, y2 = -np.abs(y), np.abs(y)
    
    '''
    椭圆左右外接点的横坐标值
    '''
    x = np.sqrt(4*C*F / (B**2 - 4*C*A))
    x1, x2 = -np.abs(x), np.abs(x)
    
    return (x1, y1), (x2, y2)

def get_rectangle(major_radius, minor_radius, angle, center_x, center_y):
    A, B, C, F = get_ellipse_param(major_radius, minor_radius, angle)
    p1, p2 = calculate_rectangle(A, B, C, F)
    return center_x+p1[0], center_y+p1[1], center_x+p2[0], center_y+p2[1]

label_path='D:/program/vs_code/retinaface/FDDBlabel.txt'
with open(label_path,'r') as label:
    with open('D:/program/vs_code/retinaface/newFDDBlabel.txt','w') as newlabel:
        labels=label.readlines()
        for j,i in enumerate(labels):
            print(i)
            if '/' in i:
                name=i.replace('\n','').replace('big/','').replace('/','_');
                nums=labels[j+1]
                image_path = 'D:/program/vs_code/retinaface/FDDB/'+name+'.jpg'
                newlabel.write(image_path)
            else:
                if len(i)<5:
                    newlabel.write('\n'+i)
                else:
                    locals=i.split(' ')
                    print(type(locals[0]),i)
                    x1,y1,x2,y2=get_rectangle(int(float(locals[0])), int(float(locals[1])),int(float(locals[2])),int(float(locals[3])), int(float(locals[4])))
                    temp=str(x1)+' '+str(y1)+' '+str(x2)+' '+str(y2)+'\n'
                    newlabel.write(temp)

转换成的txt文件第一行是文件名,第二行是标注的人脸个数,余下的几行是人脸坐标,分别是左上角和右下角的坐标

2002/08/11/big/img_591
1
123.583300 85.549500 1.265839 269.693400 161.781200 1
2002/08/26/big/img_265
3
67.363819 44.511485 -1.476417 105.249970 87.209036 1
41.936870 27.064477 1.471906 184.070915 129.345601 1
70.993052 43.355200 1.370217 340.894300 117.498951 1

猜你喜欢

转载自blog.csdn.net/qq_41950533/article/details/127348208