| function [D, XML] = LMdatabase(varargin) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| Folder = []; |
|
|
| |
| Narg = nargin; |
| HOMEANNOTATIONS = varargin{1}; |
| if Narg==3 |
| HOMEIMAGES = varargin{2}; |
| else |
| HOMEIMAGES = ''; |
| end |
|
|
| if iscell(varargin{Narg}) |
| if Narg == 2 |
| Folder = varargin{2}; |
| Nfolders = length(Folder); |
| end |
| if Narg == 3 |
| Folder = varargin{3}; |
| Nfolders = length(Folder); |
| end |
| if Narg == 4 |
| Folder = varargin{3}; |
| Images = varargin{4}; |
| Nfolders = length(Folder); |
| end |
| else |
| if Narg==2 |
| HOMEIMAGES = varargin{2}; |
| end |
| if ~strcmp(HOMEANNOTATIONS(1:5), 'http:'); |
| Folder = folderlist(HOMEANNOTATIONS); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Nfolders = length(Folder); |
| else |
| files = urldir(HOMEANNOTATIONS); |
| Folder = {files(2:end).name}; |
| Nfolders = length(Folder); |
| |
| |
| |
| end |
| end |
|
|
| |
| Hfig = plotbar; |
|
|
| |
| D = []; n = 0; nPolygons = 0; |
| if nargout == 2; XML = ['<database>']; end |
| for f = 1:Nfolders |
| folder = Folder{f}; |
| disp(sprintf('%d/%d, %s', f, Nfolders, folder)) |
| |
| |
| if Narg<4 |
| filesImages = []; |
| if ~strcmp(HOMEANNOTATIONS(1:5), 'http:'); |
| filesAnnotations = dir(fullfile(HOMEANNOTATIONS, folder, '*.xml')); |
| if ~isempty(HOMEIMAGES) |
| filesImages = dir(fullfile(HOMEIMAGES, folder, '*.jpg')); |
| end |
| else |
| filesAnnotations = urlxmldir(fullfile(HOMEANNOTATIONS, folder)); |
| if ~isempty(HOMEIMAGES) |
| filesImages = urldir(fullfile(HOMEIMAGES, folder), 'img'); |
| end |
| end |
| else |
| filesAnnotations(1).name = strrep(Images{f}, '.jpg', '.xml'); |
| filesAnnotations(1).bytes = 1; |
| filesImages(1).name = strrep(Images{f}, '.xml', '.jpg'); |
| end |
|
|
| if ~isempty(HOMEIMAGES) |
| N = length(filesImages); |
| else |
| N = length(filesAnnotations); |
| end |
| |
| |
| emptyAnnotationFiles = 0; |
| labeledImages = 0; |
| for i = 1:N |
| clear v |
|
|
| if ~isempty(HOMEIMAGES) |
| filename = fullfile(HOMEIMAGES, folder, filesImages(i).name); |
| filenameanno = strrep(filesImages(i).name, '.jpg', '.xml'); |
| if ~isempty(filesAnnotations) |
| J = strmatch(filenameanno, {filesAnnotations(:).name}); |
| else |
| J = []; |
| end |
| if length(J)==1 |
| if filesAnnotations(J).bytes > 0 |
| [v, xml] = loadXML(fullfile(HOMEANNOTATIONS, folder, filenameanno)); |
| labeledImages = labeledImages+1; |
| else |
| |
| emptyAnnotationFiles = emptyAnnotationFiles+1; |
| v.annotation.folder = folder; |
| v.annotation.filename = filesImages(i).name; |
| end |
| else |
| |
| v.annotation.folder = folder; |
| v.annotation.filename = filesImages(i).name; |
| end |
| else |
| filename = fullfile(HOMEANNOTATIONS, folder, filesAnnotations(i).name); |
| if filesAnnotations(i).bytes > 0 |
| [v, xml] = loadXML(filename); |
| labeledImages = labeledImages+1; |
| else |
| disp(sprintf('file %s is empty', filename)) |
| v.annotation.folder = folder; |
| v.annotation.filename = strrep(filesAnnotations(i).name, '.xml', '.jpg'); |
| end |
| end |
| |
| n = n+1; |
| |
| |
| if isfield(v.annotation, 'folder') |
| v.annotation.folder = strrep(v.annotation.folder, '%20', ' '); |
| v.annotation.filename = strrep(v.annotation.filename, '%20', ' '); |
| |
| |
| if ~isfield(v.annotation, 'scenedescription') |
| v.annotation.scenedescription = [v.annotation.folder ' ' v.annotation.filename]; |
| end |
| end |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if isfield(v.annotation, 'object') |
| |
| Nobjects = length(v.annotation.object); |
| [x,y,foo,t,key] = LMobjectpolygon(v.annotation); |
|
|
| |
| if isfield(v.annotation.object, 'verified') |
| v.annotation.object = rmfield(v.annotation.object, 'verified'); |
| end |
| |
| for m = 1:Nobjects |
| |
| if isfield(v.annotation.object(m), 'name') |
| v.annotation.object(m).name = strtrim(lower(v.annotation.object(m).name)); |
| end |
| |
| |
| if isfield(v.annotation.object(m).polygon, 'pt') |
| v.annotation.object(m).id = m; |
|
|
| |
| v.annotation.object(m).polygon = rmfield(v.annotation.object(m).polygon, 'pt'); |
| |
| pol.x = single(x{m}); |
| pol.y = single(y{m}); |
| pol.t = uint16(t{m}); |
| pol.key = uint8(key{m}); |
| if isfield(v.annotation.object(m).polygon, 'username') |
| pol.username = v.annotation.object(m).polygon.username; |
| end |
| v.annotation.object(m).polygon = pol; |
| else |
| v.annotation.object(m).deleted = '1'; |
| end |
| end |
| end |
| |
| |
| |
| |
| if isfield(v.annotation, 'stabilization') |
| Nframes = length(v.annotation.stabilization.fr); |
| A = zeros([3,3,Nframes]); |
| A(3,3,:)=1; |
| for k = 1:Nframes |
| A(1,1,k) = str2num(v.annotation.stabilization.fr(k).a); |
| A(1,2,k) = str2num(v.annotation.stabilization.fr(k).b); |
| A(1,3,k) = str2num(v.annotation.stabilization.fr(k).c); |
| A(2,1,k) = str2num(v.annotation.stabilization.fr(k).d); |
| A(2,2,k) = str2num(v.annotation.stabilization.fr(k).e); |
| A(2,3,k) = str2num(v.annotation.stabilization.fr(k).f); |
| end |
| v.annotation.stabilization = rmfield(v.annotation.stabilization, 'fr'); |
| v.annotation.stabilization.A = A; |
| end |
| |
| |
| D(n).annotation = v.annotation; |
|
|
| if nargout == 2 |
| XML = [XML xml]; |
| end |
|
|
| if mod(i,10)==1 && Narg<4 |
| plotbar(Hfig,f,Nfolders,i,N); |
| end |
| end |
| disp(sprintf(' Total images:%d, annotation files:%d (with %d empty xml files)', N, labeledImages, emptyAnnotationFiles)) |
| end |
|
|
| if nargout == 2; XML = [XML '</database>']; end |
|
|
| |
| |
| D = LMvalidobjects(D); |
|
|
| |
| D = addviewpoint(D); |
|
|
| |
| |
| |
|
|
|
|
|
|
| |
| |
|
|
| |
| |
| |
| |
| disp(sprintf('LabelMe Database summary:\n Total of %d annotated images.', length(D))) |
| |
| |
| close(Hfig) |
|
|
| |
| function fig = plotbar(fig,nf,Nf,ni,Ni) |
|
|
| if nargin > 0 |
| clf(fig) |
| ha = subplot(2,1,1, 'parent', fig); cla(ha) |
| p = patch([0 1 1 0],[0 0 1 1],'w','EraseMode','none', 'parent', ha); |
| p = patch([0 1 1 0]*nf/Nf,[0 0 1 1],'g','EdgeColor','k','EraseMode','none', 'parent', ha); |
| axis(ha,'off') |
| title(sprintf('folders (%d/%d)',nf,Nf), 'parent', ha) |
| ha = subplot(2,1,2, 'parent', fig); cla(ha) |
| p = patch([0 1 1 0],[0 0 1 1],'w','EraseMode','none', 'parent', ha); |
| p = patch([0 1 1 0]*ni/Ni,[0 0 1 1],'r','EdgeColor','k','EraseMode','none', 'parent', ha); |
| axis(ha,'off') |
| title(sprintf('files (%d/%d)',ni,Ni), 'parent', ha) |
| drawnow |
| else |
| |
| screenSize = get(0,'ScreenSize'); |
| pointsPerPixel = 72/get(0,'ScreenPixelsPerInch'); |
| width = 360 * pointsPerPixel; |
| height = 2*75 * pointsPerPixel; |
| pos = [screenSize(3)/2-width/2 screenSize(4)/2-height/2 width height]; |
| fig = figure('Units', 'points', ... |
| 'NumberTitle','off', ... |
| 'IntegerHandle','off', ... |
| 'MenuBar', 'none', ... |
| 'Visible','on',... |
| 'position', pos,... |
| 'BackingStore','off',... |
| 'DoubleBuffer','on'); |
| end |
|
|
| |
| function files = urlxmldir(page) |
|
|
| files = []; Folder = []; |
| page = strrep(page, '\', '/'); |
| |
| %page |
| |
| [folders,status] = urlread(page); |
| if status |
| folders = folders(1:length(folders)); |
| j1 = findstr(lower(folders), '<a href="'); |
| j2 = findstr(lower(folders), '</a>'); |
| Nfolders = length(j1); |
| |
| fn = 0; |
| for f = 1:Nfolders |
| tmp = folders(j1(f)+9:j2(f)-1); |
| fin = findstr(tmp, '"'); |
| if length(findstr(tmp(1:fin(end)-1), 'xml'))>0 |
| fn = fn+1; |
| Folder{fn} = tmp(1:fin(end)-1); |
| end |
| end |
| |
| for f = 1:length(Folder) |
| files(f).name = Folder{f}; |
| files(f).bytes = 1; |
| end |
| end |