Skip to content

Commit b89dc61

Browse files
adjust box conversion in _parallelogram_to_bounding_boxes
1 parent 7caac6e commit b89dc61

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

torchvision/transforms/v2/functional/_geometry.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,15 @@ def _parallelogram_to_bounding_boxes(parallelogram: torch.Tensor) -> torch.Tenso
478478
r_rad = torch.where(hp > wp, r14 + torch.pi / 2, r12)
479479
cos, sin = r_rad.cos(), r_rad.sin()
480480

481-
out_boxes = convert_bounding_box_format(
482-
torch.stack((cx, cy, w, h, r_rad * 180 / torch.pi), dim=-1),
483-
old_format=tv_tensors.BoundingBoxFormat.CXCYWHR,
484-
new_format=tv_tensors.BoundingBoxFormat.XYXYXYXY,
485-
inplace=False,
486-
).reshape(original_shape)
481+
x1 = cx - w / 2 * cos - h / 2 * sin
482+
y1 = cy - h / 2 * cos + w / 2 * sin
483+
x2 = cx + w / 2 * cos - h / 2 * sin
484+
y2 = cy - h / 2 * cos - w / 2 * sin
485+
x3 = cx + w / 2 * cos + h / 2 * sin
486+
y3 = cy + h / 2 * cos - w / 2 * sin
487+
x4 = cx - w / 2 * cos + h / 2 * sin
488+
y4 = cy + h / 2 * cos + w / 2 * sin
489+
out_boxes = torch.stack((x1, y1, x2, y2, x3, y3, x4, y4), dim=-1).reshape(original_shape)
487490

488491
if need_cast:
489492
out_boxes = out_boxes.to(dtype)

0 commit comments

Comments
 (0)