forked from egeyosunkaya/ImageAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.m
64 lines (57 loc) · 1.7 KB
/
evaluate.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
function [precision,recall] = evaluate(NAME,boundingBoxes, threshold)
tmpName = extractBefore(NAME,'.jpg');
PATH_REAL = "Data/" + tmpName + ".txt";
fileID = fopen(PATH_REAL{1},'r');
formatSpec = ' %d ';
BoundingData = fscanf(fileID,formatSpec);
[realObjectCount,~] = size(BoundingData);
realObjectCount = (realObjectCount - 1)/4;
correctObjects = 0;
[~,detectedCount] = size(boundingBoxes);
for i=1:detectedCount
ourBox = boundingBoxes{1,i};
topX = ourBox(1,1);
topY = ourBox(1,2);
lowX = ourBox(1,3);
lowY = ourBox(1,4);
for b=1:realObjectCount
rtopX = BoundingData(1 + (4*(b-1)),1);
rtopY = BoundingData(2 + (4*(b-1)),1);
rlowX = BoundingData(3 + (4*(b-1)),1);
rlowY = BoundingData(4 + (4*(b-1)),1);
width = 0;
if lowX > topX
width = lowX-topX;
else
width = topX-lowX;
end
height = 0;
if lowY > topY
height = lowY-topY ;
else
height = topY-lowY;
end
realWidth = 0;
if rlowX > rtopX
realWidth = rlowX-rtopX;
else
realWidth = rtopX-rlowX;
end
realHeight = 0;
if rlowY > rtopY
realHeight = rlowY-rtopY ;
else
realHeight = rtopY-rlowY;
end
ourBox = [ topX, topY, width ,height ];
realBox = [ rtopX, rtopY,realWidth ,realHeight];
overlapRatio = bboxOverlapRatio(ourBox,realBox);
if overlapRatio > threshold
correctObjects = correctObjects + 1;
break;
end
end
end
recall = correctObjects /realObjectCount ;
precision = correctObjects /detectedCount ;
end