CrowdHuman数据集odgt标注文件转换txt

odgt文件类似json,一个实体有多种属性,可以用键值id和属性来调用具体数据。
CrowdHuman中主要属性名和实际意义如下:
id:图片名
hbox:head头位置,分别为xywh
fbox:full全身位置,分别为xywh

import os
import json
def load_func(fpath):
    assert os.path.exists(fpath)
    with open(fpath, 'r') as fid:
        lines = fid.readlines()
    records = [json.loads(line.strip('\n')) for line in lines]
    return records
 
fpath='xx.odgt'
bbox = load_func(fpath)
#print(bbox)
with open('crowdhuman.txt','a+')as f:
    for i in bbox:
        ID = 'Images/'+i['ID']+'.jpg'
        num = str(len(i['gtboxes']))
        f.write(ID)
        f.write('\n')
        f.write(num)
        f.write('\n')
        for j in i['gtboxes']:
            #print(i['gtboxes'])
            j['hbox'][2]=j['hbox'][0]+j['hbox'][2]
            j['hbox'][3]=j['hbox'][1]+j['hbox'][3]
            strtmp=list(map(str,j['hbox']))
            strtmp=strtmp[0]+' '+strtmp[1]+' '+strtmp[2]+' '+strtmp[3]
            f.write(strtmp)
            f.write('\n')

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

Images/273271,c9db000d5146c15.jpg
6
171 208 233 291
268 183 328 266
363 219 417 290
455 190 508 268
537 187 592 260
602 186 673 279

猜你喜欢

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