-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgetSVTStruct.m
117 lines (107 loc) · 4.63 KB
/
getSVTStruct.m
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
% Code written by Tao Wang (http://cs.stanford.edu/people/twangcat/)
% get SVT ground truth struct
function [trainStruct, testStruct] = getSVTStruct(drawBbox)
if ~exist('drawBbox', 'var')
drawBbox = false;
end
addpath('svt1');
if ~exist('structs/svtWholeTestStruct.mat','file')
svt_test_struct = parseXML('svt1/test.xml');
jj = 1;
for i = 2:2:498
imgname = svt_test_struct.Children(i).Children(2).Children.Data;
lex = textscan( svt_test_struct.Children(i).Children(6).Children.Data, '%s', 'Delimiter', ',');
testStruct(jj).lex = lex{1};
testStruct(jj).imgname = imgname;
for kk = 2:2:length(svt_test_struct.Children(i).Children(10).Children)-1
bb = kk/2;
testStruct(jj).bbox(bb).trueTag = char(svt_test_struct.Children(i).Children(10).Children(kk).Children(2).Children.Data);
h = str2double(svt_test_struct.Children(i).Children(10).Children(kk).Attributes(1).Value);
w = str2double(svt_test_struct.Children(i).Children(10).Children(kk).Attributes(2).Value);
x = str2double(svt_test_struct.Children(i).Children(10).Children(kk).Attributes(3).Value);
y = str2double(svt_test_struct.Children(i).Children(10).Children(kk).Attributes(4).Value);
testStruct(jj).bbox(bb).h = h;
testStruct(jj).bbox(bb).w = w;
testStruct(jj).bbox(bb).x = x;
testStruct(jj).bbox(bb).y = y;
end
jj=jj+1;
end
save('structs/svtWholeTestStruct.mat', 'testStruct','-v7.3');
else
load structs/svtWholeTestStruct.mat;
end
if ~exist('structs/svtWholeTrainStruct.mat','file')
svt_train_struct = parseXML('train.xml');
jj = 1;
for i = 2:2:200
imgname = svt_train_struct.Children(i).Children(2).Children.Data;
lex = textscan( svt_train_struct.Children(i).Children(6).Children.Data, '%s', 'Delimiter', ',');
trainStruct(jj).lex = lex{1};
trainStruct(jj).imgname = imgname;
for kk = 2:2:length(svt_train_struct.Children(i).Children(10).Children)-1
bb = kk/2;
trainStruct(jj).bbox(bb).trueTag = char(svt_train_struct.Children(i).Children(10).Children(kk).Children(2).Children.Data);
h = str2double(svt_train_struct.Children(i).Children(10).Children(kk).Attributes(1).Value);
w = str2double(svt_train_struct.Children(i).Children(10).Children(kk).Attributes(2).Value);
x = str2double(svt_train_struct.Children(i).Children(10).Children(kk).Attributes(3).Value);
y = str2double(svt_train_struct.Children(i).Children(10).Children(kk).Attributes(4).Value);
trainStruct(jj).bbox(bb).h = h;
trainStruct(jj).bbox(bb).w = w;
trainStruct(jj).bbox(bb).x = x;
trainStruct(jj).bbox(bb).y = y;
end
jj=jj+1;
end
save('structs/svtWholeTrainStruct.mat', 'trainStruct','-v7.3');
else
load svtWholeTrainStruct.mat;
end
if drawBbox
for i = 1:length(trainStruct)
im = imread(trainStruct(i).imgname);
%draw bounding boxes
% aa---------------bb
% | |
% | |
% | |
% cc--------------dd
[height, width, depth] = size(im);
for j = 1:length(trainStruct(i).bbox)
h = trainStruct(i).bbox(j).h;
w = trainStruct(i).bbox(j).w;
x = trainStruct(i).bbox(j).x;
y = trainStruct(i).bbox(j).y;
aa = [max(y,1),max(x,1)];
bb = [max(y,1), min(x+w-1, width)];
cc = [min(y+h-1, height), max(x,1)];
dd = [min(y+h-1, height), min(x+w-1, width)];
im(aa(1):cc(1), aa(2), 1) = 255;
im(bb(1):dd(1), bb(2), 1) = 255;
im(aa(1), aa(2):bb(2), 1) = 255;
im(cc(1), cc(2):dd(2), 1) = 255;
end
imshow(im);
pause;
end
for i = 1:length(testStruct)
im = imread(testStruct(i).imgname);
[height, width, depth] = size(im);
for j = 1:length(testStruct(i).bbox)
h = testStruct(i).bbox(j).h;
w = testStruct(i).bbox(j).w;
x = testStruct(i).bbox(j).x;
y = testStruct(i).bbox(j).y;
aa = [max(y,1),max(x,1)];
bb = [max(y,1), min(x+w-1, width)];
cc = [min(y+h-1, height), max(x,1)];
dd = [min(y+h-1, height), min(x+w-1, width)];
im(aa(1):cc(1), aa(2), 1) = 255;
im(bb(1):dd(1), bb(2), 1) = 255;
im(aa(1), aa(2):bb(2), 1) = 255;
im(cc(1), cc(2):dd(2), 1) = 255;
end
imshow(im);
pause;
end
end