数据集是 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 forthe 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 astxt 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 end25         fid = fopen([savePath2, txtFileName], 'w');26
27         for k = 1:A.nFrame28             iframe = A.objLists(1,k);29             iframe_data = iframe{1,1};30             n1length =length(iframe_data);31             for kk = 1:n1length32                 iframe_dataj =iframe_data(kk);33                 if iframe_dataj.pos(1) ~= 0  %pos  posv34                     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 end37 end38
39 end40
41 end42
43 end44
45 end

需要下面的 关于 vbb 的函数:

1 function varargout =vbb( action, varargin )2 % Data structure forvideo 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 formultiple frames, ie, a vbb annotation not7 %only provides the locations of objects but also tracking information. A8 % 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 asa bb).10 % Each object isidentified 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 objectw given id exists14 %  lbl  - a string label describing object type (eg: 'pedestrian')15 %  str  - the first frame in which object appears (1indexed)16 %  end  - the last frame in which object appears (1indexed)17 %  hide - 0/1 value indicating object is 'hidden'(used during labeling)18 %
19 % Data per objectper frame (indexed by frame and id) includes:20 %  pos  - [l t w h]: bb indicating predicted objectextent21 %  posv - [l t w h]: bb indicating visible region (may be [0 0 0 0])22 %  occl - 0/1 value indicating if bb isoccluded23 %  lock - 0/1 value indicating bb is 'locked'(used during labeling)24 %
25 % vbb contains a number of utility functions forworking with an26 %annotation A, making it generally unnecessary to access the fields of A27 % 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 3categories.30 % Occasionally more help is available via a call to help "vbb>action".31 %
32 % %%% init and save/load annotation to/fromdisk33 % Create new annotation forgiven length video34 %   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 fromdisk: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/*.txt46 %   vbb( 'vbbToFiles', A, tarDir, [fs], [skip], [f0], [f1] )47 % Combine single frame annotations from srcDir/*.txt48 %   [A,fs] = vbb( 'vbbFrFiles', srcDir, [fs] )49 %50 % %%% inspect / alter annotation51 % Get number of unique objects in annotation52 %   n = vbb( 'numObj', A )53 % Get an unused object id (for adding a new object)54 %   [A,id] = vbb( 'newId', A )55 % Create a new, empty object (not added to A)56 %   [A,obj] = vbb( 'emptyObj', A, [frame] )57 % Get struct with all data from frames s-e for given object58 %   obj = vbb( 'get', A, id, [s], [e] )59 % Add object to annotation60 %   A = vbb( 'add', A, obj )61 % Remove object from annotation62 %   A = vbb( 'del', A, id )63 % Crop or extend object temporally64 %   A = vbb( 'setRng', A, id, s, e )65 % Get object information, see above for valid properties66 %   v = vbb( 'getVal', A, id, name, [frmS], [frmE] )67 % Set object information, see above for valid properties68 %   A = vbb( 'setVal', A, id, name, v, [frmS], [frmE] )69 %70 % %%% other functions71 % Visulatization: draw annotation on top of current image72 %   hs = vbb( 'drawToFrame', A, frame )73 % Uses seqPlayer to display seq file with overlayed annotations.74 %   vbb( 'vbbPlayer', A, srcName )75 % Visulatization: create seq file w annotation superimposed.76 %   vbb( 'drawToVideo', A, srcName, tarName )77 % Shift entire annotation by del frames. (useful for synchronizing w video)78 %   A = vbb( 'timeShift', A, del )79 % Ensure posv is fully contained in pos80 %   A = vbb( 'swapPosv', A, validate, swap, hide )81 % Stats: get stats about annotation82 %   [stats,stats1,logDur] = vbb( 'getStats', A );83 % Returns the ground truth bbs for a single frame.84 %   [gt,posv,lbls] = vbb( 'frameAnn', A, frame, lbls, test )85 %86 % USAGE87 %  varargout = vbb( action, varargin );88 %89 % INPUTS90 %  action     - string specifying action91 %  varargin   - depends on action, see above92 %93 % OUTPUTS94 %  varargout  - depends on action, see above95 %96 % EXAMPLE97 %98 % See also BBAPPLY99 %100 % Caltech Pedestrian Dataset     Version 3.2.1101 % Copyright 2014 Piotr Dollar.  [pdollar-at-gmail.com]102 % Licensed under the Simplified BSD License [see external/bsd.txt]103
104 %#ok<*DEFNU>105 varargout = cell(1,nargout);106 [varargout{:}] = eval([action '(varargin{:});']);107 end108
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%110 % init / save / load111
112 function A = init( nFrame, maxObj )113
114 if( nargin<2 || isempty(maxObj) ), maxObj=16; end115
116 A.nFrame   = nFrame;117 A.objLists = cell(1,nFrame);118 A.maxObj   = maxObj;119 A.objInit  = zeros(1,A.maxObj);120 A.objLbl   = cell(1,A.maxObj);121 A.objStr   = -ones(1,A.maxObj);122 A.objEnd   = -ones(1,A.maxObj);123 A.objHide  = zeros(1,A.maxObj);124
125 A.altered  = false;126 A.log      = 0;127 A.logLen   = 0;128 end129
130 function [fName,ext] = vbbName( fName, timeStmp, ext )131 if(nargin<2), timeStmp=false; end; if(nargin<3), ext=''; end132 [d,f,ext1]=fileparts(fName); if(isempty(ext)), ext=ext1; end133 if(isempty(ext)), ext='.vbb'; end134 if(timeStmp), f=[f '-' regexprep(datestr(now), ':| ', '-')]; end135 if(isempty(d)), d='.'; end; fName=[d '/' f ext];136 end137
138 function vbbSave( A, fName, timeStmp )139 if(nargin<3), timeStmp=false; end; vers=1.4; %#ok<NASGU>140 [fName,ext]=vbbName(fName,timeStmp);141 if(strcmp(ext,'.txt')), vbbSaveTxt(A,fName,timeStmp); return; end142 A=cleanup(A); save(fName,'A','vers','-v6'); %#ok<NASGU>143 end144
145 function A = vbbLoad( fName )146 [fName,ext]=vbbName(fName); vers=1.4;147 if(strcmp(ext,'.txt')), A=vbbLoadTxt(fName); return; end148 L = load( '-mat', fName );149 if( ~isfield(L,'A') || ~isfield(L,'vers') );150 error('Not a valid video annoation file.');151 end;152 A = L.A;153 % .06 -> 1.0 conversion (add log/logLen)154 if( L.vers==.06 )155 L.vers=1.0; A.log=0; A.logLen=0;156 end157 % 1.0 -> 1.1 conversion (add trnc field)158 if( L.vers==1.0 )159 L.vers=1.1;160 for f=1:A.nFrame161 if(isempty(A.objLists{f})); A.objLists{f}=[]; end162 for j=1:length(A.objLists{f}); A.objLists{f}(j).trnc=0; end163 end164 end165 % 1.1 -> 1.2 conversion (add hide/posv fields)166 if( L.vers==1.1 )167 L.vers=1.2;168 for f=1:A.nFrame169 if(isempty(A.objLists{f})); A.objLists{f}=[]; end170 for j=1:length(A.objLists{f}); A.objLists{f}(j).posv=[0 0 0 0]; end171 end172 A.objHide = zeros(1,A.maxObj);173 end174 % 1.2 -> 1.3 conversion (remove trnc field)175 if( L.vers==1.2 )176 L.vers=1.3;177 for f=1:A.nFrame178 if(isempty(A.objLists{f})); A.objLists{f}=[]; else179 A.objLists{f} = rmfield(A.objLists{f},'trnc');180 end181 end182 end183 % 1.3 -> 1.4 conversion (remove objAr field)184 if( L.vers==1.3 )185 L.vers=1.4; A = rmfield(A,'objAr');186 end187 % check version188 if( L.vers~=vers )189 er = [num2str(L.vers) ' (current: ' num2str(vers) ')'];190 error(['Incompatible versions: ' er]);191 end192 % order fields193 order={'nFrame','objLists','maxObj','objInit','objLbl','objStr',...194 'objEnd','objHide','altered','log','logLen'};195 A = orderfields(A,order);196 A.altered = false;197 end198
199 function vbbSaveTxt( A, fName, timeStmp )200 if(nargin<3), timeStmp=false; end; vers=1.4;201 fName=vbbName(fName,timeStmp,'.txt');202 A=cleanup(A,0); n=numObj(A); nFrame=A.nFrame;203 fid=fopen(fName,'w'); assert(fid>0);204 % write header info to text205 fp=@(varargin) fprintf(fid,varargin{:});206 fp('%% vbb version=%f\n',vers); fp('nFrame=%i n=%i\n',nFrame,n);207 fp('log=['); fp('%f ',A.log); fp(']\n');208 % write each object to text209 for id=1:n, o=get(A,id);210 fp('\n-----------------------------------\n');211 fp('lbl=''%s'' str=%i end=%i hide=%i\n',o.lbl,o.str,o.end,o.hide);212 fp('pos =['); fp('%f %f %f %f; ',o.pos'); fp(']\n');213 fp('posv=['); fp('%f %f %f %f; ',o.posv'); fp(']\n');214 fp('occl=['); fp('%i ',o.occl); fp(']\n');215 fp('lock=['); fp('%i ',o.lock); fp(']\n');216 end217 fclose(fid);218 end219
220 function A = vbbLoadTxt( fName )221 fName=vbbName(fName,0,'.txt'); vers=1.4;222 if(~exist(fName,'file')), error([fName ' not found']); end223 try224 % read in header and create A225 f=fopen(fName,'r'); s=fgetl(f); v=sscanf(s,'%% vbb version=%f');226 if(v~=vers), error('Incompatible versions: %f (current=%f)',v,vers); end227 s=fgetl(f); r=sscanf(s,'nFrame=%d n=%d'); nFrame=r(1); n=r(2);228 s=fgetl(f); assert(strcmp(s(1:5),'log=[')); assert(s(end)==']');229 log=sscanf(s(6:end-1),'%f ')'; A=init(nFrame,n);230 % read in each object in turn231 for id=1:n232 s=fgetl(f); assert(isempty(s));233 s=fgetl(f); assert(strcmp(s,'-----------------------------------'));234 s=fgetl(f); r=textscan(s,'lbl=%s str=%d end=%d hide=%d');235 [A,o]=emptyObj(A,0); o.lbl=r{1}{1}(2:end-1);236 o.str=r{2}; o.end=r{3}; o.hide=r{4};237 s=fgetl(f); assert(strcmp(s(1:6),'pos =[')); assert(s(end)==']');238 pos=sscanf(s(7:end-1),'%f %f %f %f;'); o.pos=reshape(pos,4,[])';239 s=fgetl(f); assert(strcmp(s(1:6),'posv=[')); assert(s(end)==']');240 posv=sscanf(s(7:end-1),'%f %f %f %f;'); o.posv=reshape(posv,4,[])';241 s=fgetl(f); assert(strcmp(s(1:6),'occl=[')); assert(s(end)==']');242 o.occl=sscanf(s(7:end-1),'%d ');243 s=fgetl(f); assert(strcmp(s(1:6),'lock=[')); assert(s(end)==']');244 o.lock=sscanf(s(7:end-1),'%d ');245 A=add(A,o);246 end247 if(isempty(log)), A.log=0; A.logLen=0; else248 A.log=log; A.logLen=length(log); end249 A.altered=false; fclose(f);250 catch e, fclose(f); throw(e);251 end252 end253
254 function vbbToFiles( A, tarDir, fs, skip, f0, f1 )255 % export single frame annotations to tarDir/*.txt256 nFrm=A.nFrame; fName=@(f) ['I' int2str2(f-1,5) '.txt'];257 if(nargin<3 || isempty(fs)), for f=1:nFrm, fs{f}=fName(f); end; end258 if(nargin<4 || isempty(skip)), skip=1; end259 if(nargin<5 || isempty(f0)), f0=1; end260 if(nargin<6 || isempty(f1)), f1=nFrm; end261 if(~exist(tarDir,'dir')), mkdir(tarDir); end262 for f=f0:skip:f1263 nObj=length(A.objLists{f}); objs=bbGt('create',nObj);264 for j=1:nObj265 o=A.objLists{f}(j); objs(j).lbl=A.objLbl{o.id}; objs(j).occ=o.occl;266 objs(j).bb=round(o.pos); objs(j).bbv=round(o.posv);267 end268 bbGt('bbSave',objs,[tarDir '/' fs{f}]);269 end270 end271
272 function [A,fs] = vbbFrFiles( srcDir, fs )273 % combine single frame annotations from srcDir/*.txt274 if(nargin<2 || isempty(fs)), fs=dir([srcDir '/*.txt']); fs={fs.name}; end275 nFrm=length(fs); A=init(nFrm);276 for f=1:nFrm277 objs = bbGt('bbLoad',[srcDir '/' fs{f}]);278 for j=1:length(objs)279 [A,obj]=emptyObj(A,f); o=objs(j); obj.lbl=o.lbl;280 obj.pos=o.bb; obj.occl=o.occ; obj.posv=o.bbv; A=add(A,obj);281 end282 end283 end284
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%286 % inspect / alter annotation287
288 function n = numObj( A )289 n = sum( A.objInit );290 end291
292 function [A,id] = newId( A )293 [val,id] = min( A.objInit );294 if( isempty(val) || val~=0 );295 A = doubleLen( A );296 [val,id] = min( A.objInit );297 end298 assert(val==0);299 end300
301 function [A,obj] = emptyObj( A, frame )302 [A,id] = newId( A );303 obj.id   = id;304 obj.lbl  = '';305 obj.hide = 0;306 if(nargin<2)307 obj.str  = -1;308 obj.end  = -1;309 len = 0;310 else311 obj.str  = frame;312 obj.end  = frame;313 len = 1;314 end315 obj.pos  = zeros(len,4);316 obj.posv = zeros(len,4);317 obj.occl = zeros(len,1);318 obj.lock = ones(len,1);319 end320
321 function obj = get( A, id, s, e )322
323 assert( 0<id && id<=A.maxObj );324 assert( A.objInit(id)==1 );325
326 if(nargin<3); s=A.objStr(id); else assert(s>=A.objStr(id)); end;327 if(nargin<4); e=A.objEnd(id); else assert(e<=A.objEnd(id)); end;328
329 % get general object info330 obj.id   = id;331 obj.lbl  = A.objLbl{id};332 obj.str  = s;333 obj.end  = e;334 obj.hide = A.objHide(id);335
336 % get per-frame object info337 len = obj.end-obj.str+1;338 obj.pos  = zeros(len,4);339 obj.posv = zeros(len,4);340 obj.occl = zeros(len,1);341 obj.lock = zeros(len,1);342 for i=1:len343 f = obj.str+i-1;344 objList = A.objLists{f};345 obj1 = objList([objList.id]==id);346 obj.pos(i,:)  = obj1.pos;347 obj.posv(i,:) = obj1.posv;348 obj.occl(i)   = obj1.occl;349 obj.lock(i)   = obj1.lock;350 end351
352 end353
354 function A = add( A, obj )355
356 % check id or get new id357 id = obj.id;358 if( id==-1 )359 [A,id] = newId( A );360 else361 assert( 0<id && id<=A.maxObj );362 assert( A.objInit(id)==0 );363 end364
365 % save general object info366 A.objInit(id) = 1;367 A.objLbl{id}  = obj.lbl;368 A.objStr(id)  = obj.str;369 A.objEnd(id)  = obj.end;370 A.objHide(id) = obj.hide;371
372 % save per-frame object info373 len = obj.end - obj.str + 1;374 assert( size(obj.pos,1)==len );375 assert( size(obj.posv,1)==len );376 assert( size(obj.occl,1)==len );377 assert( size(obj.lock,1)==len );378 for i = 1:len379 obj1.id   = id;380 obj1.pos  = obj.pos(i,:);381 obj1.posv = obj.posv(i,:);382 obj1.occl = obj.occl(i);383 obj1.lock = obj.lock(i);384 f = obj.str+i-1;385 A.objLists{f}=[A.objLists{f} obj1];386 end387
388 A = altered( A );389 end390
391 function A = del( A, id )392
393 assert( 0<id && id<=A.maxObj );394 assert( A.objInit(id)==1 );395
396 % delete per-frame object info397 objStr = A.objStr(id);398 objEnd = A.objEnd(id);399 len = objEnd-objStr+1;400 for i=1:len401 f = objStr+i-1;402 objList = A.objLists{f};403 objList([objList.id]==id) = [];404 A.objLists{f} = objList;405 end406
407 % delete general object info408 A.objInit(id) = 0;409 A.objLbl{id}  = [];410 A.objStr(id)  = -1;411 A.objEnd(id)  = -1;412 A.objHide(id) = 0;413
414 A = altered( A );415 end416
417 function A = setRng( A, id, s, e )418
419 assert( s>=1 && e<=A.nFrame && s<=e && A.objInit(id)==1 );420 s0=A.objStr(id); e0=A.objEnd(id); assert( e>=s0 && e0>=s );421 if(s==s0 && e==e0), return; end; A.objStr(id)=s; A.objEnd(id)=e;422
423 if( s0>s )424 objs=A.objLists{s0}; obj=objs([objs.id]==id); obj.occl=0; obj.lock=0;425 for f=s:s0-1, A.objLists{f}=[A.objLists{f} obj]; end426 elseif( s0<s )427 for f=s0:s-1, os=A.objLists{f}; os([os.id]==id)=[]; A.objLists{f}=os; end428 end429
430 if( e>e0 )431 objs=A.objLists{e0}; obj=objs([objs.id]==id); obj.occl=0; obj.lock=0;432 for f=e0+1:e, A.objLists{f}=[A.objLists{f} obj]; end433 elseif( e<e0 )434 for f=e+1:e0, os=A.objLists{f}; os([os.id]==id)=[]; A.objLists{f}=os; end435 end436
437 A = altered( A );438 end439
440 function v = getVal( A, id, name, frmS, frmE )441
442 if(nargin<4); frmS=[]; end;443 if(nargin<5); frmE=frmS; end;444 assert(strcmp(name,'init') || A.objInit(id)==1);445 switch name446 case 'lbl'447 assert( isempty(frmS) );448 v = A.objLbl{id};449 case {'init','str','end','hide'}450 assert( isempty(frmS) );451 name = ['obj' upper(name(1)) name(2:end)];452 v = A.(name)(id);453 case {'pos','posv','occl','lock'}454 assert( ~isempty(frmS) );455 assert( A.objStr(id)<=frmS && frmE<=A.objEnd(id) );456 frms = frmS:frmE; len=length(frms);457 for f=1:len458 objList = A.objLists{frms(f)};459 v1 = objList([objList.id]==id).(name);460 if( f==1 ); v=repmat(v1,[len 1]); else v(f,:) = v1; end461 end462 otherwise463 error( ['invalid field: ' name] );464 end465
466 end467
468 function A = setVal( A, id, name, v, frmS, frmE )469
470 if(nargin<5); frmS=[]; end;471 if(nargin<6); frmE=frmS; end;472 assert( A.objInit(id)==1 );473 switch name474 case 'lbl'475 assert( isempty(frmS) );476 A.objLbl{id} = v;477 case {'hide'}478 assert( isempty(frmS) );479 name = ['obj' upper(name(1)) name(2:end)];480 A.(name)(id) = v;481 case {'pos','posv','occl','lock'}482 assert( ~isempty(frmS) );483 assert( A.objStr(id)<=frmS && frmE<=A.objEnd(id) );484 frms = frmS:frmE; len=length(frms);485 for f=1:len486 objList = A.objLists{frms(f)};487 objList([objList.id]==id).(name) = v(f,:);488 A.objLists{frms(f)} = objList;489 end490 otherwise491 error( ['invalid/unalterable field: ' name] );492 end493
494 A = altered( A );495 end496
497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%498 % other functions499
500 function hs = drawToFrame( A, frame )501 hs=[];502 for o=A.objLists{frame}503 hr = bbApply('draw', o.pos, 'g', 2, '-' );504 if(all(o.posv)==0), hrv=[]; else505 hrv = bbApply('draw', o.posv, 'y', 2, '--' );506 end507 label = [A.objLbl{o.id} ' [' int2str(o.id) ']'];508 ht = text( o.pos(1), o.pos(2)-10, label );509 set( ht, 'color', 'w', 'FontSize', 10, 'FontWeight', 'bold' );510 hs = [hs hr ht hrv]; %#ok<AGROW>511 end512 end513
514 function vbbPlayer( A, srcName )515 dispFunc=@(f) vbb('drawToFrame',A,f+1);516 seqPlayer(srcName,dispFunc);517 end518
519 function drawToVideo( A, srcName, tarName )520 % open video to read and make video to write521 assert( ~strcmp(srcName,tarName) );522 sr=seqIo(srcName,'r'); info=sr.getinfo();523 nFrame=info.numFrames; w=info.width; h=info.height;524 assert(A.nFrame==nFrame); sw=seqIo(tarName,'w',info);525 % display and write each frame526 ticId=ticStatus; hf=figure; hAx=axes('parent',hf);527 hIm=imshow(zeros(h,w,3,'uint8'),'parent',hAx); truesize;528
529 for i=1:nFrame530 I=sr.getnext(); set(hIm,'CData',I); hs=drawToFrame(A,i);531 I=getframe; I=I.cdata; I=I(1:h,1:w,:);532 sw.addframe(I); delete(hs); tocStatus( ticId, i/nFrame );533 end534 sr.close(); sw.close(); close(hf);535 end536
537 function A = timeShift( A, del )538 % shift entire annotation by del frames539 nFrame=A.nFrame; locs=logical(A.objInit);540 if(del>0), is=locs & A.objStr==1; A.objStr(is)=A.objStr(is)-del; end541 A.objStr(locs)=min(max(A.objStr(locs)+del,1),nFrame);542 A.objEnd(locs)=min(max(A.objEnd(locs)+del,1),nFrame);543 if( del>0 ) % replicate annotation for first frame del times544 A.objLists=[A.objLists(ones(1,del)) A.objLists(1:end-del)];545 else % no annotations for last del frames546 A.objLists=[A.objLists(1-del:end) cell(1,-del)];547 end548 end549
550 function A = swapPosv( A, validate, swap, hide )551 % Swap pos/posv and ensure pos/posv consistent.552 %553 % The visible region of an object (posv) should be a subset of the554 % predicted region (pos). If the object is not occluded, then posv is the555 % same as pos (posv=[0 0 0 0] by default and indicates posv not set).556 % Swapping is used to swap pos and posv, and validating is used to ensure557 % pos contains posv. In two cases no swapping/validating occurs. If occl==0558 % for a given bb, posv is set to [0 0 0 0]. If occl==1 and posv=[0 0 0 0],559 % posv is set to pos. In either case there is no need to swap or validate.560 %561 % The validate flag:562 %  validate==-1:  posv = intersect(pos,posv)563 %  validate== 0:  no validation564 %  validate==+1:  pos = union(pos,posv)565 % If posv is shrunk to 0, it is set to a small bb inside pos.566 %567 % The swap flag:568 %  swap==-1:  pos and posv are swapped before validating569 %  swap== 0:  no swapping570 %  swap==+1:  pos and posv are swapped after validating571 %572 % The hide flag:573 %  hide==0:  set hide attribute to 0 for all objects574 %  hide==1:  set hide attribute to 1 iff object is at some point occluded575 %576 % Suppose a user has labeled pos in a given video using some annotation577 % tool. At this point can swap pos and posv and use the same tool in the578 % same manner to label posv (which is stored in pos). Afterwards, can swap579 % pos/posv again, and ensure they are consistent, and both end up labeled.580 % Additionally, in the second labeling phase, we may want to hide any581 % object that is never occluded. The command to setup labeling of posv is:582 %  A=vbb('swapPosv',A,-1,1,1); % validate (trust pos) THEN swap583 % Afterwards, to swap back, would use:584 %  A=vbb('swapPosv',A,1,-1,0); % swap THEN validate (trust posv)585 % While labeling posv only frames where occl is already set should be586 % altered (the occl flag itself shouldn't be altered).587 %588 % USAGE589 %  A = vbb( 'swapPosv', A, validate, swap, hide )590 %591 % INPUTS592 %  A        - annotation structure593 %  validate - see above594 %  swap     - see above595 %  hide     - see above596 %597 % OUTPUTS598 %  A        - updated annotation599 %600 % EXAMPLE601 %602 % see also vbb603
604 for f=1:A.nFrame605 for i=1:length(A.objLists{f})606 o=A.objLists{f}(i); p=o.pos; v=o.posv; vt=[];607 % v is trivial - either [0 0 0 0] or same as p, continue608 if(o.occl==0), vt=[0 0 0 0]; elseif(all(v)==0), vt=p; end609 if(~isempty(vt)), A.objLists{f}(i).posv=vt; continue; end610 % optionally swap before validating611 if(swap==-1), t=p; p=v; v=t; end612 % validate613 if( validate==-1 )614 v = bbApply('intersect',v,p);615 if(all(v==0)), v=[p(1:2)+p(3:4)/2 1 1]; end616 elseif( validate==1 )617 p = bbApply('union',v,p);618 end619 % optionally swap after validating620 if(swap==1), t=p; p=v; v=t; end621 % store results622 o.pos=p; o.posv=v; A.objLists{f}(i)=o;623 end624 end625
626 if(~hide), A.objHide(:)=0; else627 for id=find( A.objInit )628 occl=vbb('getVal',A,id,'occl',A.objStr(id),A.objEnd(id));629 A.objHide(id) = all(occl==0);630 end631 end632
633 end634
635 function [stats,stats1,logDur] = getStats( A )636
637 % get stats of many annotations simultaneously by first merging638 if(length(A)>1), A=merge(A); end639
640 % log activity (allows up to .25h of inactivity)641 nObj0=numObj(A); if(nObj0==0), stats=struct(); return; end642 log = A.log / 1.1574e-005 / 60 / 60;643 locs = find( (log(2:end)-log(1:end-1)) > .25 );644 logS=log([1 locs+1]); logE=log([locs A.logLen]);645 logDur = sum(logE-logS);646
647 % getStats1 on entire annotation648 stats = getStats1( A );649
650 % getStats1 separately for each label651 lbl0=unique(A.objLbl); nLbl0=length(lbl0);652 stats1=repmat(getStats1(subset(A,lbl0(1))),1,nLbl0);653 for i0=2:nLbl0, stats1(i0)=getStats1(subset(A,lbl0(i0))); end654
655 function stats = getStats1( A )656 % unique labels and label counts657 lbl=unique(A.objLbl); nLbl=length(lbl); lblCnts=zeros(1,nLbl);658 for i=1:nLbl, lblCnts(i)=sum(strcmp(A.objLbl,lbl{i})); end659 stats.labels=lbl; stats.labelCnts=lblCnts;660 % get object lengths661 nObj=numObj(A); stats.nObj=nObj;662 len=A.objEnd-A.objStr+1; stats.len=len;663 % get all per frame info in one flat array ordered by object id664 nPerFrm=cellfun(@length,A.objLists); stats.nPerFrm=nPerFrm;665 ols=A.objLists(nPerFrm>0); ols=[ols{:}];666 ids=[ols.id]; [ids,order]=sort(ids); ols=ols(order); stats.ids=ids;667 inds=[0 cumsum(len)]; stats.inds=inds;668 % get all pos/posv and centers, also first/last frame for each obj669 pos=reshape([ols.pos],4,[])'; posv=reshape([ols.posv],4,[])';670 posS=pos(inds(1:end-1)+1,:); posE=pos(inds(2:end),:);671 stats.pos=pos; stats.posv=posv; stats.posS=posS; stats.posE=posE;672 % get object centers and per frame deltas673 cen=bbApply('getCenter',pos); stats.cen=cen;674 del=cen(2:end,:)-cen(1:end-1,:); del(inds(2:end),:)=-1; stats.del=del;675 % get occlusion information676 occl=(sum(posv,2)>0)'; %occl=[ols.occl]; <--slow677 occFrac=1-posv(:,3).*posv(:,4)./pos(:,3)./pos(:,4); occFrac(occl==0)=0;678 occTime=zeros(1,nObj); for i=1:nObj, occTime(i)=mean(occl(ids==i)); end679 stats.occl=occl; stats.occFrac=occFrac'; stats.occTime=occTime;680 end681
682 function A = subset( A, lbls )683 % find elements to keep684 nObj=numObj(A); keep=false(1,nObj);685 for i=1:length(lbls), keep=keep | strcmp(A.objLbl,lbls{i}); end686 % clean up objLists by dropping elements687 frms=find(cellfun('isempty',A.objLists)==0); ols=A.objLists;688 for f=frms, ols{f}=ols{f}(keep([ols{f}.id])); end, A.objLists=ols;689 % run cleanup to reorder/drop elements690 A.objInit=keep; A=cleanup(A,0);691 end692
693 function A = merge( AS )694 nFrm=0; nObj=0;695 for i=1:numel(AS)696 Ai=cleanup(AS(i),0);697 for f=1:Ai.nFrame698 for j=1:length(Ai.objLists{f}),699 Ai.objLists{f}(j).id=Ai.objLists{f}(j).id+nObj;700 end701 end702 Ai.objStr=Ai.objStr+nFrm; Ai.objEnd=Ai.objEnd+nFrm;703 nFrm=Ai.nFrame+nFrm; Ai.nFrame=nFrm;704 nObj=nObj+numObj(Ai); AS(i)=Ai;705 end706 A.nFrame   = nFrm;707 A.objLists = [AS.objLists];708 A.maxObj   = sum([AS.maxObj]);709 A.objInit  = [AS.objInit];710 A.objLbl   = [AS.objLbl];711 A.objStr   = [AS.objStr];712 A.objEnd   = [AS.objEnd];713 A.objHide  = [AS.objHide];714 A.altered  = false;715 A.log      = sort([AS.log]);716 A.logLen   = sum([AS.logLen]);717 end718 end719
720 function [gt,posv,lbls1] = frameAnn( A, frame, lbls, test )721 % Returns the ground truth bbs for a single frame.722 %723 % Returns bbs for all object with lbl in lbls. The result is an [nx5] array724 % where each row is of the form [x y w h ignore]. [x y w h] is the bb and725 % ignore is a 0/1 flag that indicates regions to be ignored. For each726 % returned object, the ignore flag is set to 0 if test(lbl,pos,posv)=1 for727 % the given object. For example, using lbls={'person','people'}, and728 % test=@(lbl,bb,bbv) bb(4)>100, returns bbs for all 'person' and 'people'729 % in given frame, and for any objects under 100 pixels tall ignore=1.730 %731 % USAGE732 %  [gt,posv,lbls] = vbb( 'frameAnn', A, frame, lbls, [test] )733 %734 % INPUTS735 %  A        - annotation structure736 %  frame    - the frame index737 %  lbls     - cell array of string labels738 %  test     - [] ignore = ~test(lbl,pos,posv)739 %740 % OUTPUTS741 %  gt       - [n x 5] array containg ground truth for frame742 %  posv     - [n x 4] bbs of visible regions743 %  lbls     - [n x 1] list of object labels744 %745 % EXAMPLE746 %  lbls={'person','people'}; test=@(lbl,bb,bbv) bb(4)>100;747 %  [gt,lbls] = vbb( 'frameAnn', A, 200, lbls, test )748
749 if( nargin<4 ), test=[]; end; assert(frame<=A.nFrame);750 ng=length(A.objLists{frame}); ignore=0;751 gt=zeros(ng,5); posv=zeros(ng,4); lbls1=cell(1,ng); keep=true(1,ng);752 for g=1:ng753 o=A.objLists{frame}(g); lbl=A.objLbl{o.id};754 if(~any(strcmp(lbl,lbls))), keep(g)=0; continue; end755 if(~isempty(test)), ignore=~test(lbl,o.pos,o.posv); end756 gt(g,:)=[o.pos ignore]; lbls1{g}=lbl; posv(g,:)=o.posv;757 end758 gt=gt(keep,:); lbls1=lbls1(keep); posv=posv(keep,:);759 end760
761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%762 % helper functions763
764 function A = doubleLen( A )765 maxObj    = max(1,A.maxObj);766 A.objInit = [A.objInit zeros(1,maxObj)];767 A.objLbl  = [A.objLbl   cell(1,maxObj)];768 A.objStr  = [A.objStr  -ones(1,maxObj)];769 A.objEnd  = [A.objEnd  -ones(1,maxObj)];770 A.objHide = [A.objHide zeros(1,maxObj)];771 A.maxObj  = max(1,A.maxObj * 2);772
773 A = altered( A );774 end775
776 function A = altered( A )777 A.altered = true;778 if( length(A.log)==A.logLen )779 A.log = [A.log zeros(1,A.logLen)];780 end781 T = now;  sec=1.1574e-005;782 if( A.logLen>0 && (T-A.log(A.logLen))/sec<1 )783 A.log(A.logLen) = T;784 else785 A.logLen = A.logLen+1;786 A.log(A.logLen) = T;787 end788 end789
790 function A = cleanup( A, minn )791 % cleanup() Removes placeholder entries from A792 if( A.maxObj==0 ), return; end793 if( nargin<2 || isempty(minn) ), minn=1; end794 % reorder so all initialized objects are first795 while( 1 )796 % find first 0 entry in objInit797 [val,id0] = min(A.objInit);798 if( val==1 || id0==A.maxObj ), break; end799 % find last 1 entry past 0 entry800 [val,id1]=max(fliplr(A.objInit(id0+1:end))); id1=A.maxObj-id1+1;801 if(val==0), break; end802 % swap these two locations803 A = swap( A, id0, id1 );804 end805 % now discard all uninitialized objects (keep at least minn though)806 [val,n] = min(A.objInit); n=max(minn,n-1);807 if( val==0 )808 A.maxObj  = n;809 A.objInit = A.objInit(1:n);810 A.objLbl  = A.objLbl(1:n);811 A.objStr  = A.objStr(1:n);812 A.objEnd  = A.objEnd(1:n);813 A.objHide = A.objHide(1:n);814 end815 % discard useless elements in log816 A.log = A.log(1:A.logLen);817 end818
819 function A = swap( A, id1, id2 )820
821 A0=A;822
823 if(A0.objInit(id1)), fs=A0.objStr(id1):A0.objEnd(id1); else fs=[]; end824 for f=fs, ol=A0.objLists{f}; ol([ol.id]==id1).id=id2; A.objLists{f}=ol; end825
826 if(A0.objInit(id2)), fs=A0.objStr(id2):A0.objEnd(id2); else fs=[]; end827 for f=fs, ol=A0.objLists{f}; ol([ol.id]==id2).id=id1; A.objLists{f}=ol; end828
829 A.objInit(id1) = A0.objInit(id2);  A.objInit(id2) = A0.objInit(id1);830 A.objLbl(id1)  = A0.objLbl(id2);   A.objLbl(id2)  = A0.objLbl(id1);831 A.objStr(id1)  = A0.objStr(id2);   A.objStr(id2)  = A0.objStr(id1);832 A.objEnd(id1)  = A0.objEnd(id2);   A.objEnd(id2)  = A0.objEnd(id1);833 A.objHide(id1) = A0.objHide(id2);  A.objHide(id2) = A0.objHide(id1);834
835 end

View Code

执行后,就可以了。如图所示:

转载于:https://www.cnblogs.com/wangxiaocvpr/p/6564376.html

数据集是 seq 文件的处理办法相关推荐

  1. “只有DBA才能导入由其他DBA导出的文件”各种解决办法

    "只有DBA才能导入由其他DBA导出的文件"各种解决办法 当oracle导入的时候出现"只有 DBA 才能导入由其他 DBA 导出的文件"的时候通常有以下几种解 ...

  2. oracle dba导入,“只有DBA才能导入由其他DBA导出的文件”各种解决办法

    "只有DBA才能导入由其他DBA导出的文件"各种解决办法 类别:Oracle数据库   作者:码皇   来源:互联网   点击: 只有DBA才能导入由其他DBA导出的文件各种解决办 ...

  3. CCS编译出错:缺少头文件的解决办法

    问题: "../Source/DSP2833x_SysCtrl.c", line 16: fatal error #5: could not open source file &q ...

  4. Vivado无法双击打开xpr工程文件的解决办法

    Vivado无法双击打开xpr工程文件的解决办法 之前安装的Vivado 2018.3,最近装了Vivado 2020.2,然后就没法双击打开xpr工程文件了,提示如下: Cannot locate ...

  5. vsftp虚拟用户无法上传文件,解决办法

    vsftp虚拟用户无法上传文件,解决办法 1.打开/etc/vsftpd 目录中的vsftpd.conf文件,查找:guest_username=xxx,这里指的是vsftpd虚拟用户对应的实 际系统 ...

  6. linux ftp 登录慢,linux中vsftpd登录,上传下载文件慢解决办法linux操作系统 -电脑资料...

    vsftpd登录慢主要是nameserver #定义DNS服务器的IP地址没有设置了,这样我们只要设置或更新一下nameserver即可解决了, 在使用vsftpd的过程中,一直以来都有一个问题就是在 ...

  7. Java面试poi中excel版本大小_java 中 poi解析Excel文件版本问题解决办法

    java 中 poi解析Excel文件版本问题解决办法 发布时间:2020-10-02 03:46:15 来源:脚本之家 阅读:91 作者:程诺 poi解析Excel文件版本问题解决办法 poi解析E ...

  8. C盘不能新建文件的问题解决办法

    C盘不能新建文件的问题解决办法 主要症状: 1.C 盘文件不能修改 2.C 盘不能新建文件 3.总之就是只能读取不能,写入和修改 这样对于平时操作造成了极其的不方便~~~ 复制文件到C 盘会提示:错误 ...

  9. word不能插入压缩包等文件的解决办法

    word不能插入压缩文件的解决办法 插入压缩文件时提示错误,如下图提示 解决办法: 看看 C:\WINDOWS\system32\ 文件夹下有没有packager.exe 如果没有把这个文件复制到该文 ...

最新文章

  1. 高性能网络编程7--tcp连接的内存使用
  2. JSP作业1--5!
  3. 【机器学习】XGBoost集成算法——(理论+图解+python代码比较其他算法使用天池蒸汽数据)
  4. 现代软件工程 学生阅读和调查作业
  5. 面试官:使用SpringBoot如何开发邮件发送系统?
  6. 一文读懂Python web框架和web服务器之间的关系
  7. 《数据分析实战:基于EXCEL和SPSS系列工具的实践》一3.4 数据量太大了怎么办
  8. 虚拟环境mkvirtualenv
  9. 美国网站服务器有哪些,可以搭建什么网站?
  10. Linux搭建局域网邮箱服务器,菜鸟搭建开源的局域网邮件服务器-windows linux均适用...
  11. Android性能测试工具(一) 之Emmagee[转载]
  12. vulnhub靶机渗透 | It's October
  13. 盘点:视频监控行业的潜在商机
  14. ElasticSearch之 ik分词器详解
  15. dhcp服务器日志文件,dhcp服务器日志
  16. python kivy 控件(小部件)的属性集合
  17. Linux下安装mysql完整教程
  18. ES Module和CommonJS的区别
  19. ubuntu系统(七):工控机连接手机热点
  20. redmi ax6s刷机体验和救砖

热门文章

  1. 微信小程序如何开发可以直击客户痛点?
  2. [附源码]计算机毕业设计校园二手交易平台Springboot程序
  3. APT级全面免杀拿Shell
  4. LCD屏有几种类型?
  5. input[type=”password”] 输入框阻止chrome浏览器弹出用户名密码下拉框提示
  6. HP打印機维护怎么找官方资料
  7. 用html实现一个注册网站,实现跳转
  8. C语言符号的意思 一
  9. 【AutoSAR】【BootLoader】自我刷新
  10. 2023超全整理——116道网络安全工程师面试真题(附答案),建议收藏