行人检测——Caltech Pedestrian Dataset 数据集的使用

来源:互联网 发布:手机淘宝上买二手 编辑:程序博客网 时间:2024/06/06 09:01

Caltech Pedestrian Dataset 数据集的使用

目的:

最近在做智能交通中的行人检测,需要数据集对分类器进行training,选取的数据集为加理工(caltech)提供的http://www.vision.caltech.edu/Image_Datasets/CaltechPedestrians/,该数据集的一些说明可以从官网中得知。数据集主要包括1. 训练集+测试集:seq格式的数据;2.行人标签数据:vbb(video bounding box)格式的数据,该格式数据主要是数据集1中的行人bounding box。官网上提供toolbox对这些数据的读写等操作,好吧,我很懒就没仔细看toolbox中的代码(主要是本人的matlab水平很菜),由于我们training时需要的主要是图像格式的数据,所以需要将.seq .vbb这两个格式的数据转换为图像。 

1. 数据.seq 转 图像

import os.pathimport fnmatchimport shutil def open_save(file,savepath):    # read .seq file, and save the images into the savepath         f = open(file,'rb')    string = str(f.read())    splitstring = "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46"    # split .seq file into segment with the image prefix    strlist=string.split(splitstring)    f.close()    count = 0    # delete the image folder path if it exists    if os.path.exists(savepath):        shutil.rmtree(savepath)    # create the image folder path    if not os.path.exists(savepath):        os.mkdir(savepath)    # deal with file segment, every segment is an image except the first one    for img in strlist:        filename = str(count)+'.jpg'        filenamewithpath=os.path.join(savepath, filename)        # abandon the first one, which is filled with .seq header        if count > 0:            i=open(filenamewithpath,'wb+')            i.write(splitstring)            i.write(img)            i.close()        count += 1 if __name__=="__main__":    rootdir = "E:\\GPassport\\Work\\Search\\PedestrianDetection\\CaltechDatasets\\set\\set01"    # walk in the rootdir, take down the .seq filename and filepath    for parent, dirnames, filenames in os.walk(rootdir):        for filename in filenames:            # check .seq file with suffix            if fnmatch.fnmatch(filename,'*.seq'):                # take down the filename with path of .seq file                thefilename = os.path.join(parent, filename)                # create the image folder by combining .seq file path with .seq filename                thesavepath = parent+'\\'+filename.split('.')[0]                print "Filename=" + thefilename                print "Savepath=" + thesavepath                open_save(thefilename,thesavepath)
用python写的将.seq 转为.jpg的代码, rootdir为.seq文件的文件夹,结果为每一帧的图像。

2.数据.vbb得到图像bounding boxes

.vbb数据的具体格式我也没仔细看,里面主要就是对应图像的bounding box,如V000.vbb对应的图像为V000.seq,里面为V000.seq每一帧的行人bounding box(如果存在行人的话)。所以想通过.vbb得到行人图像(training data),首先得通过.vbb得到每一帧的bounding box的位置,然后通过该位置再从对应的.seq得到的图像中搜索得到行人图像。
vName='set01/V000';A = vbb( 'vbbLoad', [dbInfo '/annotations/' vName] );path = 'E:\GPassport\Work\Search\PedestrianDetection\CaltechDatasets\annotations\CaltechAnnotationsCode3.2.1';fnm = 'test.txt';c=fopen([path '\' fnm],'w');for i = 1:A.nFrame    iframe = A.objLists(1,i);    iframe_data = iframe{1,1};    n1length = length(iframe_data);    for  j = 1:n1length        iframe_dataj = iframe_data(j);        if iframe_dataj.pos(1) ~= 0  %pos  posv            fprintf(c,'%d %f %f %f %f\n', i, iframe_dataj.pos(1),iframe_dataj.pos(2),iframe_dataj.pos(3),iframe_dataj.pos(4));        end    endendfclose(c);
使用了官方网站上提供的code(Matlab evaluation/labeling code (3.2.1))中的函数得到.vbb中的bounding box。vName为.vbb的路径,path为保存的bounding boxes的目标文件夹,数据格式为[%d %f %f %f %f]分别为帧数 x y width height。其中,帧数为.vbb对应的.seq得到的图像的第%d帧的图像,x y为bounding box的左上角坐标,width和height分别为宽和高。通过以上步骤即可得到图像对应的pedestrian imgs,接下来大家就可以利用数据集来training了。。。

3.结果

结果为set00中的V000得到的。








5 0