1
1
from BoundingBox import *
2
2
from utils import *
3
3
4
- class BoundingBoxes :
5
4
5
+ class BoundingBoxes :
6
6
def __init__ (self ):
7
7
self ._boundingBoxes = []
8
8
@@ -11,20 +11,20 @@ def addBoundingBox(self, bb):
11
11
12
12
def removeBoundingBox (self , _boundingBox ):
13
13
for d in self ._boundingBoxes :
14
- if BoundingBox .compare (d ,_boundingBox ):
14
+ if BoundingBox .compare (d , _boundingBox ):
15
15
del self ._boundingBoxes [d ]
16
16
return
17
-
17
+
18
18
def removeAllBoundingBoxes (self ):
19
19
self ._boundingBoxes = []
20
-
20
+
21
21
def getBoundingBoxes (self ):
22
22
return self ._boundingBoxes
23
23
24
24
def getBoundingBoxByClass (self , classId ):
25
25
boundingBoxes = []
26
26
for d in self ._boundingBoxes :
27
- if d .getClassId () == classId : # get only specified bounding box type
27
+ if d .getClassId () == classId : # get only specified bounding box type
28
28
boundingBoxes .append (d )
29
29
return boundingBoxes
30
30
@@ -38,21 +38,21 @@ def getClasses(self):
38
38
39
39
def getBoundingBoxesByType (self , bbType ):
40
40
# get only specified bb type
41
- return [d for d in self ._boundingBoxes if d .getBBType () == bbType ]
41
+ return [d for d in self ._boundingBoxes if d .getBBType () == bbType ]
42
42
43
43
def getBoundingBoxesByImageName (self , imageName ):
44
44
# get only specified bb type
45
- return [d for d in self ._boundingBoxes if d .getImageName () == imageName ]
45
+ return [d for d in self ._boundingBoxes if d .getImageName () == imageName ]
46
46
47
47
def count (self , bbType = None ):
48
- if bbType == None : # Return all bounding boxes
48
+ if bbType is None : # Return all bounding boxes
49
49
return len (self ._boundingBoxes )
50
50
count = 0
51
51
for d in self ._boundingBoxes :
52
- if d .getBBType () == bbType : # get only specified bb type
52
+ if d .getBBType () == bbType : # get only specified bb type
53
53
count += 1
54
54
return count
55
-
55
+
56
56
def clone (self ):
57
57
newBoundingBoxes = BoundingBoxes ()
58
58
for d in self ._boundingBoxes :
@@ -63,116 +63,15 @@ def clone(self):
63
63
def drawAllBoundingBoxes (self , image , imageName ):
64
64
bbxes = self .getBoundingBoxesByImageName (imageName )
65
65
for bb in bbxes :
66
- if bb .getBBType () == BBType .GroundTruth : # if ground truth
67
- image = add_bb_into_image (image , bb , color = (0 ,255 ,0 )) # green
68
- else : # if detection
69
- image = add_bb_into_image (image , bb , color = (255 ,0 , 0 )) # red
70
- return image
66
+ if bb .getBBType () == BBType .GroundTruth : # if ground truth
67
+ image = add_bb_into_image (image , bb , color = (0 , 255 , 0 )) # green
68
+ else : # if detection
69
+ image = add_bb_into_image (image , bb , color = (255 , 0 , 0 )) # red
70
+ return image
71
71
72
72
# def drawAllBoundingBoxes(self, image):
73
73
# for gt in self.getBoundingBoxesByType(BBType.GroundTruth):
74
74
# image = add_bb_into_image(image, gt ,color=(0,255,0))
75
75
# for det in self.getBoundingBoxesByType(BBType.Detected):
76
76
# image = add_bb_into_image(image, det ,color=(255,0,0))
77
- # return image
78
-
79
- # @staticmethod
80
- # def evaluateDetections(gtDetection, evalDetection, minIoUTruePos=0.0):
81
- # #####################################################################
82
- # # Evaluate Intersection over Union (IoU):
83
- # #
84
- # # - Only detected objects that are overlapped with the same class
85
- # # groundtruth objects will be taken into account (e.g. a "cat"
86
- # # can only be compared to another "cat").
87
- # # - Among multiple detections for a unique groundtruth bounding box,
88
- # # only the one with the highest IoU will be taken into consid-
89
- # # eration.
90
- # # - As the highest IoU is taken into consideration, the bounding box
91
- # # pair that is considered a match (one from groundtruth and the
92
- # # other is the detected one), is removed. This way these bound-
93
- # # ing boxes won't be considered in further checking for this
94
- # # image. Then only maximum IoU will be added to IoU_sum for
95
- # # the image.
96
- # # - The IoU of an image pair is the average of its IoU.
97
- # # - IoU of the image = IoU_sum / (True_positives + False_positives) which
98
- # # is the same as average(IoU_sum)
99
- # #
100
- # #####################################################################
101
- # # Evaluate True Positive (TP) and False Positive (FP):
102
- # #
103
- # # - If detected "cat" isn't overlaped with "cat" (or overlaped with "dog"),
104
- # # then this is false_positive and its IoU = 0
105
- # # - All non-maximum IoUs = 0 and they are false_positives.
106
- # # - If a detected "cat" is somehow overlapped with a "cat", then it is
107
- # # accounted as a True Positive and no other detection will be
108
- # # considered for those bounding boxes.
109
- # #####################################################################
110
- # IoUs = []
111
- # # Initiate True Positives and False Positive counts
112
- # TP = 0
113
- # FP = 0
114
- # FN = 0
115
- # # Detections.Teste(gtDetection, evalDetection)
116
- # dets = Detections.SeparateClasses(gtDetection, evalDetection)
117
-
118
-
119
- # # Multiple detections of the same object in an image are considered
120
- # # false detections e.g. 5 detections of a single object is counted as 1 correct detec-
121
- # # tion and 4 false detections – it is the responsibility of the participant’s system
122
- # # to filter multiple detections from its output
123
-
124
- # # For each class, get its GTs and detections
125
- # for d in dets:
126
- # gtDetections = d[1]
127
- # evalDetections = d[2]
128
-
129
- # # for each evalDetection, find the best (lowest IOU) gtDetection
130
- # # note: the eval detection must be the same class
131
- # while len(gtDetections) > 0:
132
- # for detEval in evalDetections:
133
- # bb = detEval.getAbsoluteBoundingBox()
134
- # bestIoU = 0
135
- # bestGT = None
136
- # # find the bb with lowest IOU
137
- # for detGT in gtDetections:
138
- # iou = YOLOHelper.iou(bb, detGT.getAbsoluteBoundingBox())
139
-
140
- # # Show blank image with the bounding boxes
141
- # img = np.zeros((detGT.height_img,detGT.width_img,3), np.uint8)
142
- # aa = detEval.getAbsoluteBoundingBox()
143
- # img = cv2.rectangle(img, (aa[0],aa[1]), (aa[2],aa[3]), (0,0,255), 6)
144
- # for de in evalDetection.detections:
145
- # aaa = de.getAbsoluteBoundingBox()
146
- # img = cv2.rectangle(img, (aaa[0],aaa[1]), (aaa[2],aaa[3]), (0,0,255), 2)
147
- # bbb = detGT.getAbsoluteBoundingBox()
148
- # img = cv2.rectangle(img, (bbb[0],bbb[1]), (bbb[2],bbb[3]), (0,255,0), 6)
149
- # for gt in gtDetection.detections:
150
- # bbb = gt.getAbsoluteBoundingBox()
151
- # img = cv2.rectangle(img, (bbb[0],bbb[1]), (bbb[2],bbb[3]), (0,255,0), 2)
152
- # cv2.imshow("IoU %.2f" % iou,img)
153
- # cv2.waitKey(0)
154
- # cv2.destroyWindow("IoU %.2f" % iou)
155
-
156
- # if iou > 1 or iou < 0:
157
- # raise ValueError('IOU value out of limits: %f' % iou)
158
-
159
- # if iou > bestIoU:
160
- # bestGT = detGT
161
- # bestIoU = iou
162
-
163
- # IoUs.append(bestIoU)
164
- # # Increment False Positives or True Positives
165
- # if bestIoU == 0: # Detection makes no overlap with any object: it is a false positive
166
- # FP = FP + 1
167
- # elif (bestIoU >= minIoUTruePos):
168
- # TP = TP + 1
169
- # else: #bestIoU < minIoUTruePos : The overlapped IOU is below the threshold
170
- # FP = FP + 1 # Detection is a false positive
171
-
172
- # # Now remove this detected BB and go to the next
173
- # evalDetection.detections.remove(detEval)
174
- # continue
175
-
176
- # FN = FN + len(gtDetection.detections)
177
- # # Return average IoU among all detected bounding boxes, True Positives and False Positives
178
- # return FN, TP, FP
77
+ # return image
0 commit comments