forked from mcv-m1-project/icv-m1-2016
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TrafficSignDetection.m
160 lines (124 loc) · 6.43 KB
/
TrafficSignDetection.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%
% Template example for using on the validation set.
%
function TrafficSignDetection(directory, pixel_method, window_method, decision_method)
% TrafficSignDetection
% Perform detection of Traffic signs on images. Detection is performed first at the pixel level
% using a color segmentation. Then, using the color segmentation as a basis, the most likely window
% candidates to contain a traffic sign are selected using basic features (form factor, filling factor).
% Finally, a decision is taken on these windows using geometric heuristics (Hough) or template matching.
%
% Parameter name Value
% -------------- -----
% 'directory' directory where the test images to analize (.jpg) reside
% 'pixel_method' Name of the color space: 'opp', 'normrgb', 'lab', 'hsv', etc. (Weeks 2-5)
% 'window_method' 'SegmentationCCL' or 'SlidingWindow' (Weeks 3-5)
% 'decision_method' 'GeometricHeuristics' or 'TemplateMatching' (Weeks 4-5)
global CANONICAL_W; CANONICAL_W = 64;
global CANONICAL_H; CANONICAL_H = 64;
global SW_STRIDEX; SW_STRIDEX = 8;
global SW_STRIDEY; SW_STRIDEY = 8;
global SW_CANONICALW; SW_CANONICALW = 32;
global SW_ASPECTRATIO; SW_ASPECTRATIO = 1;
global SW_MINS; SW_MINS = 1;
global SW_MAXS; SW_MAXS = 2.5;
global SW_STRIDES; SW_STRIDES = 1.2;
% Load models
%global circleTemplate;
%global givewayTemplate;
%global stopTemplate;
%global rectangleTemplate;
%global triangleTemplate;
%
%if strcmp(decision_method, 'TemplateMatching')
% circleTemplate = load('TemplateCircles.mat');
% givewayTemplate = load('TemplateGiveways.mat');
% stopTemplate = load('TemplateStops.mat');
% rectangleTemplate = load('TemplateRectangles.mat');
% triangleTemplate = load('TemplateTriangles.mat');
%end
% windowTP=0; windowFN=0; windowFP=0; % (Needed after Week 3)
pixelTP=0; pixelFN=0; pixelFP=0; pixelTN=0;
files = ListFiles(directory);
for i=1:size(files,1),
i
% Read file
im = imread(strcat(directory,'/',files(i).name));
% Candidate Generation (pixel) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pixelCandidates = CandidateGenerationPixel_Color(im, pixel_method);
% Candidate Generation (window)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% windowCandidates = CandidateGenerationWindow_Example(im, pixelCandidates, window_method); %%'SegmentationCCL' or 'SlidingWindow' (Needed after Week 3)
% Accumulate pixel performance of the current image %%%%%%%%%%%%%%%%%
pixelAnnotation = imread(strcat(directory, '/mask/mask.', files(i).name(1:size(files(i).name,2)-3), 'png'))>0;
[localPixelTP, localPixelFP, localPixelFN, localPixelTN] = PerformanceAccumulationPixel(pixelCandidates, pixelAnnotation);
pixelTP = pixelTP + localPixelTP;
pixelFP = pixelFP + localPixelFP;
pixelFN = pixelFN + localPixelFN;
pixelTN = pixelTN + localPixelTN;
% Accumulate object performance of the current image %%%%%%%%%%%%%%%% (Needed after Week 3)
% windowAnnotations = LoadAnnotations(strcat(directory, '/gt/gt.', files(i).name(1:size(files(i).name,2)-3), 'txt'));
% [localWindowTP, localWindowFN, localWindowFP] = PerformanceAccumulationWindow(windowCandidates, windowAnnotations);
% windowTP = windowTP + localWindowTP;
% windowFN = windowFN + localWindowFN;
% windowFP = windowFP + localWindowFP;
end
% Plot performance evaluation
[pixelPrecision, pixelAccuracy, pixelSpecificity, pixelSensitivity] = PerformanceEvaluationPixel(pixelTP, pixelFP, pixelFN, pixelTN);
% [windowPrecision, windowAccuracy] = PerformanceEvaluationWindow(windowTP, windowFN, windowFP); % (Needed after Week 3)
[pixelPrecision, pixelAccuracy, pixelSpecificity, pixelSensitivity]
% [windowPrecision, windowAccuracy]
%profile report
%profile off
toc
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CandidateGeneration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [pixelCandidates] = CandidateGenerationPixel_Color(im, space)
im=double(im);
switch space
case 'normrgb'
pixelCandidates = im(:,:,1)>100;
otherwise
error('Incorrect color space defined');
return
end
end
function [windowCandidates] = CandidateGenerationWindow_Example(im, pixelCandidates, window_method)
windowCandidates = [ struct('x',double(12),'y',double(17),'w',double(32),'h',double(32)) ];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Performance Evaluation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function PerformanceEvaluationROC(scores, labels, thresholdRange)
% PerformanceEvaluationROC
% ROC Curve with precision and accuracy
roc = [];
for t=thresholdRange,
TP=0;
FP=0;
for i=1:size(scores,1),
if scores(i) > t % scored positive
if labels(i)==1 % labeled positive
TP=TP+1;
else % labeled negative
FP=FP+1;
end
else % scored negative
if labels(i)==1 % labeled positive
FN = FN+1;
else % labeled negative
TN = TN+1;
end
end
end
precision = TP / (TP+FP+FN+TN);
accuracy = TP / (TP+FN+FP);
roc = [roc ; precision accuracy];
end
plot(roc);
end