-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathevaluateDetectionSystem.m
More file actions
299 lines (270 loc) · 11.4 KB
/
Copy pathevaluateDetectionSystem.m
File metadata and controls
299 lines (270 loc) · 11.4 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
function [] = evaluateDetectionSystem(img)
%performanceEvaluator Evaluates the performance of key functions in the
%Embedded Vision System.
% Starts First by Testing the Speed of the MATLAB function and the
% proceeds to the MEX version and then the OpenCL enabled version. Then
% displays result and plots performance graph afterwards.
%Created on: 17th August, 2017
%Author: Oluwole Oyetoke Jnr
%Using MATLAB 2016
%INPUT VALIDATION AND IMAGE PREPARATION
%--------------------------------------------------------------------------
if nargin ~= 1
error('performanceEvaluator:Input_Argument_Error','This function works with 1 input argument -img- ')
end
[xDim, yDim, zDim] = size(img);
%Check if image is coloured
if (zDim<3)
error('performanceEvaluator:Image_Format_Error','This function works with coloured images')
end
img = imresize(img, [500 500]); %But standard definition is 640x480)
[xDim, yDim, zDim] = size(img);
N = maxNumCompThreads;
maxNumCompThreads(N); %Make sure code runs on maximum number of threads
clc
%--------------------------------------------------------------------------
%GET REGION OF INTEREST THROUGH COLOUR SEGMENTATION
%--------------------------------------------------------------------------
windowSize = 20;
stepSize=10;
%if 1/20th of the region or more is bright, indicate as possible region
beacon = ceil((windowSize*windowSize)/20);
[detectedRegion regionAvailable ROI regionShed] = getROI(img, windowSize, stepSize,beacon, 1);
%--------------------------------------------------------------------------
%IF REGION IS DETECTED, TEST FURTHER (SHAPE ANALYSIS)
%--------------------------------------------------------------------------
if regionAvailable~=0
grayDetectedRegion = getGrayScale( detectedRegion );
ITT = 100; %Specifies the number of itterations for multiple tests
%CONNECTED COMPONENT ANALYSIS PERFORMANCE ANALYSIS-----------------------------------
fprintf('Testing Connected Component Analysis Performance (MATLAB)\n')
%1. One time test
tic
[x, y, width, height] = CCA( xDim, yDim, zDim, stepSize, beacon, windowSize, regionShed );
oneTimeCCADurationMATLAB = toc;
%2. Multiple time test
multipleTimeCCADurationMATLAB=0;
for i=1:ITT
tic
[x, y, width, height] = CCA( xDim, yDim, zDim, stepSize, beacon, windowSize, regionShed );
temp = toc;
multipleTimeCCADurationMATLAB =multipleTimeCCADurationMATLAB+temp;
end
averageCCADurationMATLAB = multipleTimeCCADurationMATLAB/ITT; %Get average duration for the itterated process
fprintf('Testing Connected Component Analysis Performance (MEX)\n')
transpose = regionShed';
regionShed1D = transpose(:)';
%1. One time test
tic
[output] = CCAmex(uint32(regionShed1D));
oneTimeCCADurationMEX = toc;
%2. Multiple time test
multipleTimeCCADurationMEX=0;
for i=1:ITT
tic
[output] = CCAmex(uint32(regionShed1D));
temp = toc;
multipleTimeCCADurationMEX =multipleTimeCCADurationMEX+temp;
end
averageCCADurationMEX = multipleTimeCCADurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
%EDGE DETECTION PERFORMANCE TEST-------------------------------------------
fprintf('Testing Edge Detection Performance (MATLAB)\n')
%1. One time test
tic
edgedRegion = detectEdge(grayDetectedRegion);
oneTimeEdgeDurationMATLAB = toc;
%2. Multiple time test
multipleTimeEdgeDurationMATLAB=0;
for i=1:ITT
tic
edgedRegion = detectEdge(grayDetectedRegion);
temp = toc;
multipleTimeEdgeDurationMATLAB =multipleTimeEdgeDurationMATLAB+temp;
end
averageEdgeDurationMATLAB = multipleTimeEdgeDurationMATLAB/ITT; %Get average duration for the itterated process
fprintf('Testing Edge Detection Performance (MEX)\n')
%1. One time test
tic
edgedRegion = detectEdge_mex(grayDetectedRegion);
oneTimeEdgeDurationMEX = toc;
%2. Multiple time test
multipleTimeEdgeDurationMEX=0;
for i=1:ITT
tic
edgedRegion = detectEdge_mex(grayDetectedRegion);
temp = toc;
multipleTimeEdgeDurationMEX =multipleTimeEdgeDurationMEX+temp;
end
averageEdgeDurationMEX = multipleTimeEdgeDurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
%CORNER DETECTION PERFORMANCE TEST-----------------------------------------
fprintf('Testing Corner Detection Performance (MATLAB)\n')
%1. One time test
tic
[x y] = detectCorner(grayDetectedRegion); %MATLAB
oneTimeCornerDurationMATLAB = toc;
%2. Multiple time test
multipleTimeCornerDurationMATLAB=0;
for i=1:ITT
tic
[x y] = detectCorner(grayDetectedRegion); %MATLAB
temp = toc;
multipleTimeCornerDurationMATLAB =multipleTimeCornerDurationMATLAB+temp;
end
averageCornerDurationMATLAB = multipleTimeCornerDurationMATLAB/ITT; %Get average duration for the itterated process
fprintf('Testing Corner Detection Performance (MEX)\n')
%1. One time test
tic
[x y] = detectCorner_mex(grayDetectedRegion); %C++
oneTimeCornerDurationMEX = toc;
%2. Multiple time test
multipleTimeCornerDurationMEX=0;
for i=1:ITT
tic
[x y] = detectCorner_mex(grayDetectedRegion); %C++
temp = toc;
multipleTimeCornerDurationMEX =multipleTimeCornerDurationMEX+temp;
end
averageCornerDurationMEX = multipleTimeCornerDurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
%CIRCLE DETECTION PERFORMANCE TEST----------------------------------------------------------
fprintf('Testing Circle Detection Performance (MATLAB)\n')
%1. One time test
tic
[circleAvailable circleStrength] = detectCircle(detectedRegion);
oneTimeCircleDurationMATLAB = toc;
%2. Multiple time test
multipleTimeCircleDurationMATLAB=0;
for i=1:ITT
tic
[circleAvailable circleStrength] = detectCircle(detectedRegion);
temp = toc;
multipleTimeCircleDurationMATLAB =multipleTimeCircleDurationMATLAB+temp;
end
averageCircleDurationMATLAB = multipleTimeCircleDurationMATLAB/ITT; %Get average duration for the itterated process
fprintf('Testing Circle Detection Performance (MEX)\n')
%1. One time test
tic
[circleAvailable circleStrength] = detectCircle_mex(grayDetectedRegion);
oneTimeCircleDurationMEX = toc;
%2. Multiple time test
multipleTimeCircleDurationMEX=0;
for i=1:ITT
tic
[circleAvailable circleStrength] = detectCircle_mex(grayDetectedRegion);
temp = toc;
multipleTimeCircleDurationMEX =multipleTimeCircleDurationMEX+temp;
end
averageCircleDurationMEX = multipleTimeCircleDurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
%SHAPE ANALYSER PERFORMANCE TEST-------------------------------------------
fprintf('Testing Shape Analyser Performance (MATLAB)\n')
%1. One time test
tic
[availableShapes] = shapeAnalyser(edgedRegion); %MATLAB
oneTimeShapeAnalyserDurationMATLAB = toc;
%2. Multiple time test
multipleTimeShapeAnalyserDurationMATLAB=0;
for i=1:ITT
tic
[availableShapes] = shapeAnalyser(edgedRegion); %MATLAB
temp = toc;
multipleTimeShapeAnalyserDurationMATLAB =multipleTimeShapeAnalyserDurationMATLAB+temp;
end
averageShapeAnalyserDurationMATLAB = multipleTimeShapeAnalyserDurationMATLAB /ITT; %Get average duration for the itterated process
fprintf('Testing Shape Analyser Performance (MEX)\n')
%1. One time test
tic
[availableShapes] = shapeAnalyser_mex(edgedRegion); %C++
oneTimeShapeAnalyserDurationMEX = toc;
%2. Multiple time test
multipleTimeShapeAnalyserDurationMEX=0;
for i=1:ITT
tic
[availableShapes] = shapeAnalyser_mex(edgedRegion); %C++
temp = toc;
multipleTimeShapeAnalyserDurationMEX =multipleTimeShapeAnalyserDurationMEX+temp;
end
averagesShapeAnalyserDurationMEX = multipleTimeShapeAnalyserDurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
%CRITICAL AREA PERFORMANCE TEST--------------------------------------------
fprintf('Testing Critical Area Analyser Performance (MATLAB)\n')
%1. One time test
tic
[chances, shrinks] = analyseCriticalAreas(edgedRegion, x, y); %MATLAB
oneTimeCriticalAreaAnalyserDurationMATLAB = toc;
%2. Multiple time test
multipleTimeCriticalAreaAnalyserDurationMATLAB=0;
for i=1:ITT
tic
[chances, shrinks] = analyseCriticalAreas(edgedRegion, x, y); %MATLAB
temp = toc;
multipleTimeCriticalAreaAnalyserDurationMATLAB =multipleTimeCriticalAreaAnalyserDurationMATLAB+temp;
end
averageCriticalAreaDurationMATLAB = multipleTimeCriticalAreaAnalyserDurationMATLAB /ITT; %Get average duration for the itterated process
fprintf('Testing Critical Area Analyser Performance (MEX)\n')
%1. One time test
tic
[chances, shrinks] = analyseCriticalAreas_mex(edgedRegion, x, y); %C++
oneTimeCriticalAreaAnalyserDurationMEX = toc;
%2. Multiple time test
multipleTimeCriticalAreaAnalyserDurationMEX=0;
for i=1:ITT
tic
[chances, shrinks] = analyseCriticalAreas_mex(edgedRegion, x, y); %C++
temp = toc;
multipleTimeCriticalAreaAnalyserDurationMEX =multipleTimeCriticalAreaAnalyserDurationMEX+temp;
end
averagesCriticalAreaDurationMEX = multipleTimeCriticalAreaAnalyserDurationMEX/ITT; %Get average duration for the itterated process
%--------------------------------------------------------------------------
fprintf('Analysis completed. Getting ready to plot\n');
else
fprintf('NO REGION OF INTEREST FOUND, THEREFORE NO TEST OPERATION\n')
end %End of if region is found
%Create Bar graph group.
%Each group contains [OnetTimeMATLAB OneTimeMex AverageMATLAB AverageMEX]
graphData = [oneTimeCCADurationMATLAB oneTimeCCADurationMEX averageCCADurationMATLAB averageCCADurationMEX;...
oneTimeEdgeDurationMATLAB oneTimeEdgeDurationMEX averageEdgeDurationMATLAB averageEdgeDurationMEX;...
oneTimeCornerDurationMATLAB oneTimeCornerDurationMEX averageCornerDurationMATLAB averageCornerDurationMEX;...
oneTimeCircleDurationMATLAB oneTimeCircleDurationMEX averageCircleDurationMATLAB averageCircleDurationMEX;...
oneTimeShapeAnalyserDurationMATLAB oneTimeShapeAnalyserDurationMEX averageShapeAnalyserDurationMATLAB averagesShapeAnalyserDurationMEX;...
oneTimeCriticalAreaAnalyserDurationMATLAB oneTimeCriticalAreaAnalyserDurationMEX averageCriticalAreaDurationMATLAB averagesCriticalAreaDurationMEX];
hbar = bar(graphData); %Draw
xAxisLabels = {'CCA Analysis', 'Edge Detection', 'Corner Detection', 'Circle Detection', 'Shape Analysis', 'Critical Area Analysis'};
set(gca,'XTickLabel',xAxisLabels);
tit = title('BAR GRAPH SHOWING DETECTION ALGORITHM PERFORMANCE MATLAB vs C++');
set(tit, 'FontSize', 12);
xlab = sprintf('Vision System Used Detection Algorithms');
xlabel(xlab);
ylabel('Execution Times (seconds)');
str1 = strcat('MATLAB VERSION (AVG. TIME FOR -',num2str(ITT),'- ITTERATION(S))');
str2 = strcat('C++ VERSION (AVG. TIME FOR -',num2str(ITT),'- ITTERATION(S))');
legendData = {'MATLAB VERSION (RUN ONCE)', 'C++ VERSION (RUN ONCE)', str1,str2 };
legend(hbar,legendData);
mx=max(graphData(:));
% Set the axes YLIM (increaed wrt the max data value to have room for the
% label
ylim([0 mx*1.2])
grid minor
% Get the XDATA
XDATA=get(hbar(1),'XData')';
% Define the vertical offset of the labels
ygap=mx*0.1;
% Loop over the bar's group
for i=1:length(hbar)
% Get the YDATA of the i-th bar in each group
YDATA=get(hbar(i),'YData')';
% Loop over the groups
for j=1:length(XDATA)
% Get the XPOS of the j-th bar
xpos=XDATA(j);
% Get the height of the bar and increment it with the offset
ypos=YDATA(j)+ygap;
% Define the labels
[labels]=num2str(YDATA(j),3);
% Add the labels
t = text(xpos+hbar(i).XOffset,ypos,labels,'Color','k','HorizontalAlignment','center','Rotation',90);
end
end
end %End of function