数据集是 seq 文件的处理办法
2017-03-17
最近下了一个数据集,是 seq 格式的,第一次处理这种数据。使用了官方提供的 matlab 工具包:https://pdollar.github.io/toolbox/index.html
先下载咯:
然后,添加工具包的路径:
1 Simply unzip, then add all directories to the Matlab path:
2 >> addpath(genpath('path/to/toolbox/')); savepath;
3
4 If needed, run the compile script for the mex files:
5 >> toolboxCompile;
6 Note: 64 bit Windows/Linux/Mac binaries are already included.
然后,进入这个工具包中 video 那个文件夹。可以发现:
利用提供的 seqio.m 文件,就可以完成相应的功能了。这里需要写一个脚本,来调用这个函数。因为不想一个个的处理seq文件:
%% load seq files
clc; close all;
path = 'F:\dataset\Muliti_Spectal_cvpr2015\视频数据\';
files = dir(path);
for i =3:size(files, 1)
videoName = files(i).name;
videoPath = [path, videoName, '\'];
files2 = dir([videoPath, '*.seq']);
for j = 1:size(files2, 1)
videoname = files2(j).name;
seqfile = [videoPath, videoname];
videoname2 = strtok(videoname, '.');
imgSavePath = [videoPath, videoname2 ,'\'];
if ~exist(imgSavePath)
mkdir(imgSavePath);
end
Is = seqIo( seqfile, 'toImgs', imgSavePath);
end
end
其中,最重要的就是 Is = seqio(seqfile, 'toImgs', imgSavePath) 这个命令咯,即:将输入的seq文件 seqfile,转换为 image,保存到 imgSavePath 文件夹当中。
运行后,就可以看到相应的图像生成了,文件也就转换成功了。恭喜!
另外一个问题就是:如何将 label 信息从对应的文件中也提取出来?
写一个脚本,先把自己的文件夹都一层一层的找到,然后调用 vbb 文件,读取,并且存为 txt 文件。
1 %% functions for load vbb files and saved as txt file.
2 function read_vbb()
3 % load vbb files and change it into txt file.
4 clc; clear all; close all;
5 path = 'F:\dataset\Muliti_Spectal_cvpr2015\label_files\';
6 savePath = 'F:\dataset\Muliti_Spectal_cvpr2015\BBox_annotation\';
7 files = dir(path);
8 for i = 3:size(files, 1)
9 filename = files(i).name;
10 newpath = [path, filename, '\'];
11
12 vbbfiles = dir([newpath, '*.vbb']);
13 for j = 3:size(vbbfiles, 1)
14 vbbName = vbbfiles(j).name;
15 vbbPath = [newpath, vbbName];
16 disp(vbbPath);
17 A = vbb('vbbLoad',vbbPath);
18
19 txttmp = strtok(vbbName, '.');
20 txtFileName = [txttmp, '.txt'];
21 savePath2 = [savePath, filename, '\'];
22 if ~exist(savePath2)
23 mkdir(savePath2);
24 end
25 fid = fopen([savePath2, txtFileName], 'w');
26
27 for k = 1:A.nFrame
28 iframe = A.objLists(1,k);
29 iframe_data = iframe{
1,1};
30 n1length = length(iframe_data);
31 for kk = 1:n1length
32 iframe_dataj = iframe_data(kk);
33 if iframe_dataj.pos(1) ~= 0 %pos posv
34 fprintf(fid,'%d %f %f %f %f\n', k, iframe_dataj.pos(1),...
35 iframe_dataj.pos(2),iframe_dataj.pos(3),iframe_dataj.pos(4));
36 end
37 end
38
39 end
40
41 end
42
43 end
44
45 end
需要下面的 关于 vbb 的函数:
1 function varargout = vbb( action, varargin )
2 % Data structure for video bounding box (vbb) annotations.
3 %
4 % A video bounding box (vbb) annotation stores bounding boxes (bbs) for
5 % objects of interest. The primary difference from a static annotation is
6 % that each object can exist for multiple frames, ie, a vbb annotation not
7 % only provides the locations of objects but also tracking information. A
8 % vbb annotation A is simply a Matlab struct. It contains data per object
9 % (such as a string label) and data per object per frame (such as a bb).
10 % Each object is identified with a unique integer id.
11 %
12 % Data per object (indexed by integer id) includes the following fields:
13 % init - 0/1 value indicating whether object w given id exists
14 % lbl - a string label describing object type (eg: 'pedestrian')
15 % str - the first frame in which object appears (1 indexed)
16 % end - the last frame in which object appears (1 indexed)
17 % hide - 0/1 value indicating object is 'hidden' (used during labeling)
18 %
19 % Data per object per frame (indexed by frame and id) includes:
20 % pos - [l t w h]: bb indicating predicted object extent
21 % posv - [l t w h]: bb indicating visible region (may be [0 0 0 0])
22 % occl - 0/1 value indicating if bb is occluded
23 % lock - 0/1 value indicating bb is 'locked' (used during labeling)
24 %
25 % vbb contains a number of utility functions for working with an
26 % annotation A, making it generally unnecessary to access the fields of A
27 % directly. The format for accessing the various utility functions is:
28 % outputs = vbb( 'action', inputs );
29 % Below is a list of utility functions, broken up into 3 categories.
30 % Occasionally more help is available via a call to help "vbb>action".
31 %
32 % %%% init and save/load annotation to/from disk
33 % Create new annotation for given length video
34 % A = vbb( 'init', nFrame, maxObj )
35 % Generate annotation filename (add .vbb and optionally time stamp)
36 % [fName,ext] = vbb( 'vbbName', fName, [timeStmp], [ext] )
37 % Save annotation A to fName with optional time stamp (F by default)
38 % vbb('vbbSave', A, fName, [timeStmp] )
39 % Load annotation from disk:
40 % A = vbb('vbbLoad', fName )
41 % Save annotation A to fName (in .txt format):
42 % vbb('vbbSaveTxt', A, fName, timeStmp )
43 % Load annotation from disk (in .txt format):
44 % A = vbb('vbbLoadTxt', fName )
45 % Export single frame annotations to tarDir/*.txt
46 % vbb( 'vbbToFiles', A, tarDir, [fs], [skip], [f0], [f1] )
47 % Combine single frame annotations from srcDir/*.txt
48 % [A,fs] = vbb( 'vbbFrFiles', srcDir, [fs] )