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