Skip to content

Commit 206de05

Browse files
committed
proper code indentation
1 parent 3827a8e commit 206de05

File tree

11 files changed

+539
-385
lines changed

11 files changed

+539
-385
lines changed

_init_paths.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import sys
1212
import os
1313

14+
1415
def add_path(path):
1516
if path not in sys.path:
1617
sys.path.insert(0, path)
1718

19+
1820
currentPath = os.path.dirname(os.path.realpath(__file__))
1921

2022
# Add lib to PYTHONPATH
2123
libPath = os.path.join(currentPath, 'lib')
22-
add_path(libPath)
24+
add_path(libPath)

lib/BoundingBox.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self,
5353
self._format = format
5454

5555
# If relative coordinates, convert to absolute values
56+
# For relative coords: (x,y,w,h)=(X_center/img_width , Y_center/img_height)
5657
if (typeCoordinates == CoordinatesType.Relative):
5758
(self._x, self._y, self._w, self._h) = convertToAbsoluteValues(imgSize, (x, y, w, h))
5859
self._width_img = imgSize[0]
@@ -63,8 +64,9 @@ def __init__(self,
6364
self._w = self._x2 - self._x
6465
self._h = self._y2 - self._y
6566
else:
66-
# Needed to implement
67-
raise IOError('To implement')
67+
raise IOError(
68+
'For relative coordinates, the format must be XYWH (x,y,width,height)')
69+
# For absolute coords: (x,y,w,h)=real bb coords
6870
else:
6971
self._x = x
7072
self._y = y
@@ -145,11 +147,16 @@ def compare(det1, det2):
145147
def clone(boundingBox):
146148
absBB = boundingBox.getAbsoluteBoundingBox(format=BBFormat.XYWH)
147149
# return (self._x,self._y,self._x2,self._y2)
148-
newBoundingBox = BoundingBox(boundingBox.getImageName(), boundingBox.getClassId(), \
149-
absBB[0], absBB[1], absBB[2], absBB[3], \
150-
typeCoordinates = boundingBox.getCoordinatesType(), \
151-
imgSize = boundingBox.getImageSize(), \
152-
bbType = boundingBox.getBBType(), \
153-
classConfidence = boundingBox.getConfidence(), \
154-
format = BBFormat.XYWH)
155-
return newBoundingBox
150+
newBoundingBox = BoundingBox(
151+
boundingBox.getImageName(),
152+
boundingBox.getClassId(),
153+
absBB[0],
154+
absBB[1],
155+
absBB[2],
156+
absBB[3],
157+
typeCoordinates=boundingBox.getCoordinatesType(),
158+
imgSize=boundingBox.getImageSize(),
159+
bbType=boundingBox.getBBType(),
160+
classConfidence=boundingBox.getConfidence(),
161+
format=BBFormat.XYWH)
162+
return newBoundingBox

lib/BoundingBoxes.py

Lines changed: 16 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from BoundingBox import *
22
from utils import *
33

4-
class BoundingBoxes:
54

5+
class BoundingBoxes:
66
def __init__(self):
77
self._boundingBoxes = []
88

@@ -11,20 +11,20 @@ def addBoundingBox(self, bb):
1111

1212
def removeBoundingBox(self, _boundingBox):
1313
for d in self._boundingBoxes:
14-
if BoundingBox.compare(d,_boundingBox):
14+
if BoundingBox.compare(d, _boundingBox):
1515
del self._boundingBoxes[d]
1616
return
17-
17+
1818
def removeAllBoundingBoxes(self):
1919
self._boundingBoxes = []
20-
20+
2121
def getBoundingBoxes(self):
2222
return self._boundingBoxes
2323

2424
def getBoundingBoxByClass(self, classId):
2525
boundingBoxes = []
2626
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
2828
boundingBoxes.append(d)
2929
return boundingBoxes
3030

@@ -38,21 +38,21 @@ def getClasses(self):
3838

3939
def getBoundingBoxesByType(self, bbType):
4040
# 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]
4242

4343
def getBoundingBoxesByImageName(self, imageName):
4444
# 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]
4646

4747
def count(self, bbType=None):
48-
if bbType == None: # Return all bounding boxes
48+
if bbType is None: # Return all bounding boxes
4949
return len(self._boundingBoxes)
5050
count = 0
5151
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
5353
count += 1
5454
return count
55-
55+
5656
def clone(self):
5757
newBoundingBoxes = BoundingBoxes()
5858
for d in self._boundingBoxes:
@@ -63,116 +63,15 @@ def clone(self):
6363
def drawAllBoundingBoxes(self, image, imageName):
6464
bbxes = self.getBoundingBoxesByImageName(imageName)
6565
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
7171

7272
# def drawAllBoundingBoxes(self, image):
7373
# for gt in self.getBoundingBoxesByType(BBType.GroundTruth):
7474
# image = add_bb_into_image(image, gt ,color=(0,255,0))
7575
# for det in self.getBoundingBoxesByType(BBType.Detected):
7676
# 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

Comments
 (0)