Skip to content

Fix _ImageDrawTV #9137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added test/assets/fakedata/draw_rotated_boxes_fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ def test_draw_rotated_boxes():
assert_equal(result, expected)


@pytest.mark.skipif(PILLOW_VERSION < (10, 1), reason="The reference image is only valid for PIL >= 10.1")
def test_draw_rotated_boxes_fill():
img = torch.full((3, 500, 500), 255, dtype=torch.uint8)
colors = ["blue", "yellow", (0, 255, 0), "black"]

result = utils.draw_bounding_boxes(img, rotated_boxes, colors=colors, fill=True)
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "fakedata", "draw_rotated_boxes_fill.png")
expected = torch.as_tensor(np.array(Image.open(path))).permute(2, 0, 1)
assert_equal(result, expected)


@pytest.mark.parametrize("fill", [True, False])
def test_draw_boxes_dtypes(fill):
img_uint8 = torch.full((3, 100, 100), 255, dtype=torch.uint8)
Expand Down
2 changes: 1 addition & 1 deletion torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def oriented_rectangle(self, xy, fill=None, outline=None, width=1):
width=width,
fill=outline,
)
self.rectangle(xy, fill=fill, outline=None, width=0)
self.polygon(xy, fill=fill, outline=None, width=0)

def dashed_line(self, xy, fill=None, width=0, joint=None, dash_length=5, space_length=5):
# Calculate the total length of the line
Expand Down
Loading