Skip to content

Commit c2f5d73

Browse files
committed
✏️ black fixes
1 parent c30aa31 commit c2f5d73

File tree

5 files changed

+338
-231
lines changed

5 files changed

+338
-231
lines changed

utils/bbox.py

+51-27
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import cv2
44
from .colors import get_color
55

6+
67
class BoundBox:
7-
def __init__(self, xmin, ymin, xmax, ymax, c = None, classes = None):
8+
def __init__(self, xmin, ymin, xmax, ymax, c=None, classes=None):
89
self.xmin = xmin
910
self.ymin = ymin
1011
self.xmax = xmax
1112
self.ymax = ymax
1213

13-
self.c = c
14+
self.c = c
1415
self.classes = classes
1516

1617
self.label = -1
@@ -28,6 +29,7 @@ def get_score(self):
2829

2930
return self.score
3031

32+
3133
def _interval_overlap(interval_a, interval_b):
3234
x1, x2 = interval_a
3335
x3, x4 = interval_b
@@ -36,59 +38,81 @@ def _interval_overlap(interval_a, interval_b):
3638
if x4 < x1:
3739
return 0
3840
else:
39-
return min(x2,x4) - x1
41+
return min(x2, x4) - x1
4042
else:
4143
if x2 < x3:
42-
return 0
44+
return 0
4345
else:
44-
return min(x2,x4) - x3
46+
return min(x2, x4) - x3
47+
4548

4649
def bbox_iou(box1, box2):
4750
intersect_w = _interval_overlap([box1.xmin, box1.xmax], [box2.xmin, box2.xmax])
4851
intersect_h = _interval_overlap([box1.ymin, box1.ymax], [box2.ymin, box2.ymax])
4952

5053
intersect = intersect_w * intersect_h
5154

52-
w1, h1 = box1.xmax-box1.xmin, box1.ymax-box1.ymin
53-
w2, h2 = box2.xmax-box2.xmin, box2.ymax-box2.ymin
55+
w1, h1 = box1.xmax - box1.xmin, box1.ymax - box1.ymin
56+
w2, h2 = box2.xmax - box2.xmin, box2.ymax - box2.ymin
5457

55-
union = w1*h1 + w2*h2 - intersect
58+
union = w1 * h1 + w2 * h2 - intersect
5659

57-
if union == 0: return 0
60+
if union == 0:
61+
return 0
5862

5963
return float(intersect) / union
6064

61-
def draw_boxes(image, boxes, labels, obj_thresh, quiet=True, number_color = False):
65+
66+
def draw_boxes(image, boxes, labels, obj_thresh, quiet=True, number_color=False):
6267
for box in boxes:
63-
label_str = ''
68+
label_str = ""
6469
label = -1
6570

6671
for i in range(len(labels)):
6772
if box.classes[i] > obj_thresh:
68-
if label_str != '': label_str += ', '
69-
label_str += (labels[i] + ' ' + str(round(box.get_score()*100,0)) + '%')
73+
if label_str != "":
74+
label_str += ", "
75+
label_str += (
76+
labels[i] + " " + str(round(box.get_score() * 100, 0)) + "%"
77+
)
7078
label = i
71-
if not quiet: print(label_str)
79+
if not quiet:
80+
print(label_str)
7281

7382
if label >= 0:
74-
text_size = cv2.getTextSize(label_str, cv2.FONT_HERSHEY_SIMPLEX, 1.1e-4 * image.shape[0], 2)
83+
text_size = cv2.getTextSize(
84+
label_str, cv2.FONT_HERSHEY_SIMPLEX, 1.1e-4 * image.shape[0], 2
85+
)
7586
width, height = text_size[0][0], text_size[0][1]
76-
region = np.array([[box.xmin-3, box.ymin],
77-
[box.xmin-3, box.ymin-height-16],
78-
[box.xmin+width+6, box.ymin-height-16],
79-
[box.xmin+width+6, box.ymin]], dtype='int32')
87+
region = np.array(
88+
[
89+
[box.xmin - 3, box.ymin],
90+
[box.xmin - 3, box.ymin - height - 16],
91+
[box.xmin + width + 6, box.ymin - height - 16],
92+
[box.xmin + width + 6, box.ymin],
93+
],
94+
dtype="int32",
95+
)
8096
# Use one only color
8197
if number_color:
8298
label = number_color
8399

84-
cv2.rectangle(img=image, pt1=(box.xmin,box.ymin), pt2=(box.xmax,box.ymax), color=get_color(label), thickness=1)
100+
cv2.rectangle(
101+
img=image,
102+
pt1=(box.xmin, box.ymin),
103+
pt2=(box.xmax, box.ymax),
104+
color=get_color(label),
105+
thickness=1,
106+
)
85107
cv2.fillPoly(img=image, pts=[region], color=get_color(label))
86-
cv2.putText(img=image,
87-
text=label_str,
88-
org=(box.xmin+6, box.ymin - 6),
89-
fontFace=cv2.FONT_HERSHEY_SIMPLEX,
90-
fontScale=0.7e-3 * image.shape[0],
91-
color=(0,0,0),
92-
thickness=2)
108+
cv2.putText(
109+
img=image,
110+
text=label_str,
111+
org=(box.xmin + 6, box.ymin - 6),
112+
fontFace=cv2.FONT_HERSHEY_SIMPLEX,
113+
fontScale=0.7e-3 * image.shape[0],
114+
color=(0, 0, 0),
115+
thickness=2,
116+
)
93117

94118
return image

utils/colors.py

+82-81
Original file line numberDiff line numberDiff line change
@@ -9,88 +9,89 @@ def get_color(label):
99
if label < len(colors):
1010
return colors[label]
1111
else:
12-
print('Label {} has no color, returning default.'.format(label))
12+
print("Label {} has no color, returning default.".format(label))
1313
return (0, 255, 0)
1414

15+
1516
colors = [
16-
[31 , 0 , 255] ,
17-
[0 , 159 , 255] ,
18-
[255 , 95 , 0] ,
19-
[255 , 19 , 0] ,
20-
[255 , 0 , 0] ,
21-
[255 , 38 , 0] ,
22-
[0 , 255 , 25] ,
23-
[255 , 0 , 133] ,
24-
[255 , 172 , 0] ,
25-
[108 , 0 , 255] ,
26-
[0 , 82 , 255] ,
27-
[0 , 255 , 6] ,
28-
[255 , 0 , 152] ,
29-
[223 , 0 , 255] ,
30-
[12 , 0 , 255] ,
31-
[0 , 255 , 178] ,
32-
[108 , 255 , 0] ,
33-
[184 , 0 , 255] ,
34-
[255 , 0 , 76] ,
35-
[146 , 255 , 0] ,
36-
[51 , 0 , 255] ,
37-
[0 , 197 , 255] ,
38-
[255 , 248 , 0] ,
39-
[255 , 0 , 19] ,
40-
[255 , 0 , 38] ,
41-
[89 , 255 , 0] ,
42-
[127 , 255 , 0] ,
43-
[255 , 153 , 0] ,
44-
[0 , 255 , 255] ,
45-
[0 , 255 , 216] ,
46-
[0 , 255 , 121] ,
47-
[255 , 0 , 248] ,
48-
[70 , 0 , 255] ,
49-
[0 , 255 , 159] ,
50-
[0 , 216 , 255] ,
51-
[0 , 6 , 255] ,
52-
[0 , 63 , 255] ,
53-
[31 , 255 , 0] ,
54-
[255 , 57 , 0] ,
55-
[255 , 0 , 210] ,
56-
[0 , 255 , 102] ,
57-
[242 , 255 , 0] ,
58-
[255 , 191 , 0] ,
59-
[0 , 255 , 63] ,
60-
[255 , 0 , 95] ,
61-
[146 , 0 , 255] ,
62-
[184 , 255 , 0] ,
63-
[255 , 114 , 0] ,
64-
[0 , 255 , 235] ,
65-
[255 , 229 , 0] ,
66-
[0 , 178 , 255] ,
67-
[255 , 0 , 114] ,
68-
[255 , 0 , 57] ,
69-
[0 , 140 , 255] ,
70-
[0 , 121 , 255] ,
71-
[12 , 255 , 0] ,
72-
[255 , 210 , 0] ,
73-
[0 , 255 , 44] ,
74-
[165 , 255 , 0] ,
75-
[0 , 25 , 255] ,
76-
[0 , 255 , 140] ,
77-
[0 , 101 , 255] ,
78-
[0 , 255 , 82] ,
79-
[223 , 255 , 0] ,
80-
[242 , 0 , 255] ,
81-
[89 , 0 , 255] ,
82-
[165 , 0 , 255] ,
83-
[70 , 255 , 0] ,
84-
[255 , 0 , 172] ,
85-
[255 , 76 , 0] ,
86-
[203 , 255 , 0] ,
87-
[204 , 0 , 255] ,
88-
[255 , 0 , 229] ,
89-
[255 , 133 , 0] ,
90-
[127 , 0 , 255] ,
91-
[0 , 235 , 255] ,
92-
[0 , 255 , 197] ,
93-
[255 , 0 , 191] ,
94-
[0 , 44 , 255] ,
95-
[50 , 255 , 0]
17+
[31, 0, 255],
18+
[0, 159, 255],
19+
[255, 95, 0],
20+
[255, 19, 0],
21+
[255, 0, 0],
22+
[255, 38, 0],
23+
[0, 255, 25],
24+
[255, 0, 133],
25+
[255, 172, 0],
26+
[108, 0, 255],
27+
[0, 82, 255],
28+
[0, 255, 6],
29+
[255, 0, 152],
30+
[223, 0, 255],
31+
[12, 0, 255],
32+
[0, 255, 178],
33+
[108, 255, 0],
34+
[184, 0, 255],
35+
[255, 0, 76],
36+
[146, 255, 0],
37+
[51, 0, 255],
38+
[0, 197, 255],
39+
[255, 248, 0],
40+
[255, 0, 19],
41+
[255, 0, 38],
42+
[89, 255, 0],
43+
[127, 255, 0],
44+
[255, 153, 0],
45+
[0, 255, 255],
46+
[0, 255, 216],
47+
[0, 255, 121],
48+
[255, 0, 248],
49+
[70, 0, 255],
50+
[0, 255, 159],
51+
[0, 216, 255],
52+
[0, 6, 255],
53+
[0, 63, 255],
54+
[31, 255, 0],
55+
[255, 57, 0],
56+
[255, 0, 210],
57+
[0, 255, 102],
58+
[242, 255, 0],
59+
[255, 191, 0],
60+
[0, 255, 63],
61+
[255, 0, 95],
62+
[146, 0, 255],
63+
[184, 255, 0],
64+
[255, 114, 0],
65+
[0, 255, 235],
66+
[255, 229, 0],
67+
[0, 178, 255],
68+
[255, 0, 114],
69+
[255, 0, 57],
70+
[0, 140, 255],
71+
[0, 121, 255],
72+
[12, 255, 0],
73+
[255, 210, 0],
74+
[0, 255, 44],
75+
[165, 255, 0],
76+
[0, 25, 255],
77+
[0, 255, 140],
78+
[0, 101, 255],
79+
[0, 255, 82],
80+
[223, 255, 0],
81+
[242, 0, 255],
82+
[89, 0, 255],
83+
[165, 0, 255],
84+
[70, 255, 0],
85+
[255, 0, 172],
86+
[255, 76, 0],
87+
[203, 255, 0],
88+
[204, 0, 255],
89+
[255, 0, 229],
90+
[255, 133, 0],
91+
[127, 0, 255],
92+
[0, 235, 255],
93+
[0, 255, 197],
94+
[255, 0, 191],
95+
[0, 44, 255],
96+
[50, 255, 0],
9697
]

0 commit comments

Comments
 (0)