diff --git a/test/assets/fakedata/draw_rotated_boxes_fill.png b/test/assets/fakedata/draw_rotated_boxes_fill.png new file mode 100644 index 00000000000..474b771f04e Binary files /dev/null and b/test/assets/fakedata/draw_rotated_boxes_fill.png differ diff --git a/test/test_utils.py b/test/test_utils.py index 000798a0609..8b6f357ce6e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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) diff --git a/torchvision/utils.py b/torchvision/utils.py index eec7d21293f..050cc51d893 100644 --- a/torchvision/utils.py +++ b/torchvision/utils.py @@ -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