Skip to content

Commit 0dfed91

Browse files
committed
Fix all ruff linter errors and format with ruff
1 parent d45ffcd commit 0dfed91

13 files changed

+88
-70
lines changed

bbox_visualizer/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
from ._version import __version__
44
from .core import (
5-
draw_rectangle,
6-
draw_multiple_rectangles,
75
add_label,
86
add_multiple_labels,
9-
add_T_label,
107
add_multiple_T_labels,
8+
add_T_label,
119
draw_flag_with_label,
1210
draw_multiple_flags_with_labels,
11+
draw_multiple_rectangles,
12+
draw_rectangle,
1313
)
1414

1515
__all__ = [
1616
"__version__",
17-
"draw_rectangle",
18-
"draw_multiple_rectangles",
19-
"add_label",
20-
"add_multiple_labels",
2117
"add_T_label",
18+
"add_label",
2219
"add_multiple_T_labels",
20+
"add_multiple_labels",
2321
"draw_flag_with_label",
2422
"draw_multiple_flags_with_labels",
23+
"draw_multiple_rectangles",
24+
"draw_rectangle",
2525
]
2626

2727
__author__ = """Shoumik Sharar Chowdhury"""

bbox_visualizer/core/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""Core functionality for bbox-visualizer."""
22

3-
from .rectangle import draw_rectangle, draw_multiple_rectangles
4-
from .labels import add_label, add_multiple_labels
53
from .flags import (
6-
add_T_label,
74
add_multiple_T_labels,
5+
add_T_label,
86
draw_flag_with_label,
97
draw_multiple_flags_with_labels,
108
)
9+
from .labels import add_label, add_multiple_labels
10+
from .rectangle import draw_multiple_rectangles, draw_rectangle
1111

1212
__all__ = [
13-
"draw_rectangle",
14-
"draw_multiple_rectangles",
15-
"add_label",
16-
"add_multiple_labels",
1713
"add_T_label",
14+
"add_label",
1815
"add_multiple_T_labels",
16+
"add_multiple_labels",
1917
"draw_flag_with_label",
2018
"draw_multiple_flags_with_labels",
19+
"draw_multiple_rectangles",
20+
"draw_rectangle",
2121
]

bbox_visualizer/core/flags.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Functions for drawing flag and T-shaped labels."""
22

3-
import cv2
43
import logging
5-
import numpy as np
64
from typing import List, Tuple
75

8-
from ._utils import _check_and_modify_bbox, _validate_bbox, _validate_color
9-
from .rectangle import draw_rectangle
6+
import cv2
7+
import numpy as np
8+
9+
from ._utils import _check_and_modify_bbox, _validate_color
1010
from .labels import add_label
11+
from .rectangle import draw_rectangle
1112

1213
font = cv2.FONT_HERSHEY_SIMPLEX
1314

@@ -135,7 +136,7 @@ def draw_flag_with_label(
135136
)
136137

137138
x_center = (bbox[0] + bbox[2]) // 2
138-
y_bottom = int((bbox[1] * 0.75 + bbox[3] * 0.25))
139+
y_bottom = int(bbox[1] * 0.75 + bbox[3] * 0.25)
139140
y_top = bbox[1] - (y_bottom - bbox[1])
140141
if y_top < 0:
141142
logging.warning(

bbox_visualizer/core/labels.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Functions for adding text labels to bounding boxes."""
22

3+
from typing import List, Tuple
4+
35
import cv2
46
import numpy as np
5-
from typing import List, Tuple
67

7-
from ._utils import _check_and_modify_bbox, _validate_bbox, _validate_color
8+
from ._utils import _check_and_modify_bbox, _validate_color
89

910
font = cv2.FONT_HERSHEY_SIMPLEX
1011

bbox_visualizer/core/rectangle.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Functions for drawing rectangles on images."""
22

3+
from typing import List, Tuple
4+
35
import cv2
46
import numpy as np
5-
from typing import List, Tuple
67

7-
from ._utils import _check_and_modify_bbox, _validate_bbox, _validate_color
8+
from ._utils import _check_and_modify_bbox, _validate_color
89

910

1011
def draw_rectangle(

examples/multiple_objects.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import json
22

3-
import bbox_visualizer as bbv
43
import cv2
54

6-
img = cv2.imread('../images/source_multiple.jpg')
7-
annotation = json.load(open('../images/source_multiple.json'))
5+
import bbox_visualizer as bbv
6+
7+
img = cv2.imread("../images/source_multiple.jpg")
8+
annotation = json.load(open("../images/source_multiple.json"))
89
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
910

1011
labels = []
1112
bboxes = []
12-
for shape in annotation['shapes']:
13-
labels.append(shape['label'])
14-
mins = shape['points'][0]
15-
maxs = shape['points'][1]
13+
for shape in annotation["shapes"]:
14+
labels.append(shape["label"])
15+
mins = shape["points"][0]
16+
maxs = shape["points"][1]
1617
bboxes.append(mins + maxs)
1718

1819
img_with_boxes = bbv.draw_multiple_rectangles(img, bboxes)

examples/multiple_objects_example.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
"outputs": [],
1717
"source": [
1818
"import json\n",
19+
"\n",
20+
"import cv2\n",
1921
"import matplotlib.pyplot as plt\n",
22+
"\n",
2023
"import bbox_visualizer as bbv\n",
21-
"import cv2\n",
2224
"\n",
23-
"img = cv2.imread('../images/source_multiple.jpg')\n",
24-
"annotation = json.load(open('../images/source_multiple.json'))\n",
25+
"img = cv2.imread(\"../images/source_multiple.jpg\")\n",
26+
"annotation = json.load(open(\"../images/source_multiple.json\"))\n",
2527
"img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)"
2628
]
2729
},
@@ -42,10 +44,10 @@
4244
"source": [
4345
"labels = []\n",
4446
"bboxes = []\n",
45-
"for shape in annotation['shapes']:\n",
46-
" labels.append(shape['label'])\n",
47-
" mins = shape['points'][0]\n",
48-
" maxs = shape['points'][1]\n",
47+
"for shape in annotation[\"shapes\"]:\n",
48+
" labels.append(shape[\"label\"])\n",
49+
" mins = shape[\"points\"][0]\n",
50+
" maxs = shape[\"points\"][1]\n",
4951
" bboxes.append(mins + maxs)"
5052
]
5153
},

examples/single_object.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import json
22

3-
import bbox_visualizer as bbv
43
import cv2
54

6-
img = cv2.imread('../images/source_single.jpg')
7-
annotation = json.load(open('../images/source_single.json'))
5+
import bbox_visualizer as bbv
6+
7+
img = cv2.imread("../images/source_single.jpg")
8+
annotation = json.load(open("../images/source_single.json"))
89
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
910

10-
points = annotation['shapes'][0]['points']
11-
label = annotation['shapes'][0]['label']
11+
points = annotation["shapes"][0]["points"]
12+
label = annotation["shapes"][0]["label"]
1213
(xmin, ymin), (xmax, ymax) = points
1314
bbox = [xmin, ymin, xmax, ymax]
1415

examples/single_object_example.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
"outputs": [],
1717
"source": [
1818
"import json\n",
19+
"\n",
20+
"import cv2\n",
1921
"import matplotlib.pyplot as plt\n",
22+
"\n",
2023
"import bbox_visualizer as bbv\n",
21-
"import cv2\n",
2224
"\n",
23-
"img = cv2.imread('../images/source_single.jpg')\n",
24-
"annotation = json.load(open('../images/source_single.json'))\n",
25+
"img = cv2.imread(\"../images/source_single.jpg\")\n",
26+
"annotation = json.load(open(\"../images/source_single.json\"))\n",
2527
"img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)"
2628
]
2729
},
@@ -41,11 +43,11 @@
4143
}
4244
],
4345
"source": [
44-
"points = annotation['shapes'][0]['points']\n",
45-
"label = annotation['shapes'][0]['label']\n",
46+
"points = annotation[\"shapes\"][0][\"points\"]\n",
47+
"label = annotation[\"shapes\"][0][\"label\"]\n",
4648
"\n",
47-
"print(f'Points box: {points}, {type(points)}')\n",
48-
"print(f'Label box: {label}, {type(label)}')"
49+
"print(f\"Points box: {points}, {type(points)}\")\n",
50+
"print(f\"Label box: {label}, {type(label)}\")"
4951
]
5052
},
5153
{

examples/test_multiple_objects_example.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@
77
"""
88

99
import json
10-
import bbox_visualizer as bbv
10+
1111
import cv2
1212

13+
import bbox_visualizer as bbv
14+
15+
1316
def main():
1417
# Load image and annotation
15-
img = cv2.imread('../images/test_images/source_multiple_cats.jpg')
18+
img = cv2.imread("../images/test_images/source_multiple_cats.jpg")
1619
if img is None:
1720
print("Error: Could not load image. Please check the path.")
1821
return
19-
22+
2023
try:
21-
annotation = json.load(open('../images/test_images/source_multiple_cats.json'))
24+
annotation = json.load(open("../images/test_images/source_multiple_cats.json"))
2225
except FileNotFoundError:
2326
print("Error: Could not load annotation file. Please check the path.")
2427
return
2528

2629
# Extract labels and bounding boxes from annotation
2730
labels = []
2831
bboxes = []
29-
for shape in annotation['shapes']:
30-
labels.append(shape['label'])
31-
mins = shape['points'][0] # [xmin, ymin]
32-
maxs = shape['points'][1] # [xmax, ymax]
32+
for shape in annotation["shapes"]:
33+
labels.append(shape["label"])
34+
mins = shape["points"][0] # [xmin, ymin]
35+
maxs = shape["points"][1] # [xmax, ymax]
3336
bboxes.append(mins + maxs) # [xmin, ymin, xmax, ymax]
3437

3538
# Draw different visualizations
@@ -50,5 +53,6 @@ def main():
5053
cv2.waitKey(0)
5154
cv2.destroyAllWindows()
5255

56+
5357
if __name__ == "__main__":
54-
main()
58+
main()

examples/test_single_object_example.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
"""
88

99
import json
10-
import bbox_visualizer as bbv
10+
1111
import cv2
1212

13+
import bbox_visualizer as bbv
14+
15+
1316
def main():
1417
# Load image and annotation
15-
img = cv2.imread('../images/test_images/source_bird.jpg')
18+
img = cv2.imread("../images/test_images/source_bird.jpg")
1619
if img is None:
1720
print("Error: Could not load image. Please check the path.")
1821
return
19-
22+
2023
try:
21-
annotation = json.load(open('../images/test_images/source_bird.json'))
24+
annotation = json.load(open("../images/test_images/source_bird.json"))
2225
except FileNotFoundError:
2326
print("Error: Could not load annotation file. Please check the path.")
2427
return
@@ -27,16 +30,15 @@ def main():
2730
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
2831

2932
# Extract bounding box and label from annotation
30-
points = annotation['shapes'][0]['points']
31-
label = annotation['shapes'][0]['label']
33+
points = annotation["shapes"][0]["points"]
34+
label = annotation["shapes"][0]["label"]
3235
(xmin, ymin), (xmax, ymax) = points
3336
bbox = [xmin, ymin, xmax, ymax]
3437

3538
# Draw different visualizations
3639
img_with_box = bbv.draw_rectangle(img, bbox)
3740
img_with_box_2 = img_with_box.copy()
3841

39-
img_label = bbv.add_label(img_with_box, label, bbox)
4042
img_T_label = bbv.add_T_label(img_with_box_2, label, bbox)
4143
img_flag = bbv.draw_flag_with_label(img, label, bbox)
4244

@@ -49,5 +51,6 @@ def main():
4951
cv2.waitKey(0)
5052
cv2.destroyAllWindows()
5153

54+
5255
if __name__ == "__main__":
53-
main()
56+
main()

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Tests for bbox-visualizer package."""
1+
"""Tests for bbox-visualizer package."""

tests/test_bbox_visualizer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import pytest
2-
import numpy as np
31
import logging
4-
from bbox_visualizer.core import rectangle, labels, flags
2+
3+
import numpy as np
4+
import pytest
5+
6+
from bbox_visualizer.core import flags, labels, rectangle
57

68

79
@pytest.fixture

0 commit comments

Comments
 (0)