-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPASreadrectxt.m
More file actions
99 lines (88 loc) · 3.1 KB
/
Copy pathPASreadrectxt.m
File metadata and controls
99 lines (88 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function record=PASreadrectxt(filename)
[fd,syserrmsg]=fopen(filename,'rt');
if (fd==-1),
PASmsg=sprintf('Could not open %s for reading',filename);
PASerrmsg(PASmsg,syserrmsg);
end;
matchstrs=initstrings;
record=PASemptyrecord;
notEOF=1;
while (notEOF),
line=fgetl(fd);
notEOF=ischar(line);
if (notEOF),
matchnum=match(line,matchstrs);
switch matchnum,
case 1, [imgname]=strread(line,matchstrs(matchnum).str);
record.imgname=char(imgname);
case 2, [x,y,c]=strread(line,matchstrs(matchnum).str);
record.imgsize=[x y c];
case 3, [database]=strread(line,matchstrs(matchnum).str);
record.database=char(database);
case 4, [obj,lbl,xmin,ymin,xmax,ymax]=strread(line,matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).bbox=[min(xmin,xmax),min(ymin,ymax),max(xmin,xmax),max(ymin,ymax)];
case 5, tmp=findstr(line,' : ');
[obj,lbl]=strread(line(1:tmp),matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).polygon=sscanf(line(tmp+3:end),'(%d, %d) ')';
case 6, [obj,lbl,mask]=strread(line,matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).mask=char(mask);
case 7, [obj,lbl,orglbl]=strread(line,matchstrs(matchnum).str);
lbl=char(lbl);
record.objects(obj).label=lbl;
record.objects(obj).orglabel=char(orglbl);
if strcmp(lbl(max(end-8,1):end),'Difficult')
record.objects(obj).difficult=true;
lbl(end-8:end)=[];
else
record.objects(obj).difficult=false;
end
if strcmp(lbl(max(end-4,1):end),'Trunc')
record.objects(obj).truncated=true;
lbl(end-4:end)=[];
else
record.objects(obj).truncated=false;
end
t=find(lbl>='A'&lbl<='Z');
t=t(t>=4);
if ~isempty(t)
record.objects(obj).view=lbl(t(1):end);
lbl(t(1):end)=[];
else
record.objects(obj).view='';
end
record.objects(obj).class=lbl(4:end);
otherwise, %fprintf('Skipping: %s\n',line);
end;
end;
end;
fclose(fd);
return
function matchnum=match(line,matchstrs)
for i=1:length(matchstrs),
matched(i)=strncmp(line,matchstrs(i).str,matchstrs(i).matchlen);
end;
matchnum=find(matched);
if isempty(matchnum), matchnum=0; end;
if (length(matchnum)~=1),
PASerrmsg('Multiple matches while parsing','');
end;
return
function s=initstrings
s(1).matchlen=14;
s(1).str='Image filename : %q';
s(2).matchlen=10;
s(2).str='Image size (X x Y x C) : %d x %d x %d';
s(3).matchlen=8;
s(3).str='Database : %q';
s(4).matchlen=8;
s(4).str='Bounding box for object %d %q (Xmin, Ymin) - (Xmax, Ymax) : (%d, %d) - (%d, %d)';
s(5).matchlen=7;
s(5).str='Polygon for object %d %q (X, Y)';
s(6).matchlen=5;
s(6).str='Pixel mask for object %d %q : %q';
s(7).matchlen=8;
s(7).str='Original label for object %d %q : %q';
return