Skip to content

Commit cb4b1bc

Browse files
committed
feat: Update pillow bounding boxes visualization.
1 parent 927e20a commit cb4b1bc

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

vis4d/vis/image/bbox3d_visualizer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ def _draw_image(self, sample: DataSample) -> NDArrayUI8:
316316

317317
selected_corner = project_point(box.corners[0], sample.intrinsics)
318318
self.canvas.draw_text(
319-
(selected_corner[0], selected_corner[1]),
320-
box.label,
319+
(selected_corner[0], selected_corner[1]), box.label, box.color
321320
)
322321

323322
if self.plot_trajectory:

vis4d/vis/image/bounding_box_visualizer.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(
4747
n_colors: int = 50,
4848
cat_mapping: dict[str, int] | None = None,
4949
file_type: str = "png",
50+
width: int = 2,
5051
canvas: CanvasBackend = PillowCanvasBackend(),
5152
viewer: ImageViewerBackend = MatplotlibImageViewer(),
5253
**kwargs: ArgsType,
@@ -71,6 +72,7 @@ def __init__(
7172
else {}
7273
)
7374
self.file_type = file_type
75+
self.width = width
7476
self.canvas = canvas
7577
self.viewer = viewer
7678

@@ -187,8 +189,8 @@ def _draw_image(self, sample: DataSample) -> NDArrayUI8:
187189
"""
188190
self.canvas.create_canvas(sample.image)
189191
for box in sample.boxes:
190-
self.canvas.draw_box(box.corners, box.color)
191-
self.canvas.draw_text(box.corners[:2], box.label)
192+
self.canvas.draw_box(box.corners, box.color, width=self.width)
193+
self.canvas.draw_text(box.corners[:2], box.label, box.color)
192194

193195
return self.canvas.as_numpy_image()
194196

@@ -206,11 +208,7 @@ def save_to_disk(self, cur_iter: int, output_folder: str) -> None:
206208
for sample in self._samples:
207209
image_name = f"{sample.image_name}.{self.file_type}"
208210

209-
self.canvas.create_canvas(sample.image)
210-
211-
for box in sample.boxes:
212-
self.canvas.draw_box(box.corners, box.color)
213-
self.canvas.draw_text(box.corners[:2], box.label)
211+
_ = self._draw_image(sample)
214212

215213
self.canvas.save_to_disk(
216214
os.path.join(output_folder, image_name)

vis4d/vis/image/canvas/pillow_backend.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ def draw_text(
115115
raise ValueError(
116116
"No Image Draw initialized! Did you call 'create_canvas'?"
117117
)
118-
self._image_draw.text(position, text, color, font=self._font)
118+
left, top, right, bottom = self._image_draw.textbbox(
119+
position, text, font=self._font
120+
)
121+
self._image_draw.rectangle(
122+
(left - 2, top - 2, right + 2, bottom + 2), fill=color
123+
)
124+
self._image_draw.text(position, text, (255, 255, 255), font=self._font)
119125

120126
def draw_box(
121127
self,

0 commit comments

Comments
 (0)