|
|
@ -402,7 +402,7 @@ def xyxy2xywh(x): |
|
|
|
def xywh2xyxy(x): |
|
|
|
def xywh2xyxy(x): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Convert bounding box coordinates from (x, y, width, height) format to (x1, y1, x2, y2) format where (x1, y1) is the |
|
|
|
Convert bounding box coordinates from (x, y, width, height) format to (x1, y1, x2, y2) format where (x1, y1) is the |
|
|
|
top-left corner and (x2, y2) is the bottom-right corner. |
|
|
|
top-left corner and (x2, y2) is the bottom-right corner. Note: ops per 2 channels faster than per channel. |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
x (np.ndarray | torch.Tensor): The input bounding box coordinates in (x, y, width, height) format. |
|
|
|
x (np.ndarray | torch.Tensor): The input bounding box coordinates in (x, y, width, height) format. |
|
|
@ -412,12 +412,10 @@ def xywh2xyxy(x): |
|
|
|
""" |
|
|
|
""" |
|
|
|
assert x.shape[-1] == 4, f"input shape last dimension expected 4 but input shape is {x.shape}" |
|
|
|
assert x.shape[-1] == 4, f"input shape last dimension expected 4 but input shape is {x.shape}" |
|
|
|
y = torch.empty_like(x) if isinstance(x, torch.Tensor) else np.empty_like(x) # faster than clone/copy |
|
|
|
y = torch.empty_like(x) if isinstance(x, torch.Tensor) else np.empty_like(x) # faster than clone/copy |
|
|
|
dw = x[..., 2] / 2 # half-width |
|
|
|
xy = x[..., :2] # centers |
|
|
|
dh = x[..., 3] / 2 # half-height |
|
|
|
wh = x[..., 2:] / 2 # half width-height |
|
|
|
y[..., 0] = x[..., 0] - dw # top left x |
|
|
|
y[..., :2] = xy - wh # top left xy |
|
|
|
y[..., 1] = x[..., 1] - dh # top left y |
|
|
|
y[..., 2:] = xy + wh # bottom right xy |
|
|
|
y[..., 2] = x[..., 0] + dw # bottom right x |
|
|
|
|
|
|
|
y[..., 3] = x[..., 1] + dh # bottom right y |
|
|
|
|
|
|
|
return y |
|
|
|
return y |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|