mmcv.ops.box_iou_rotated¶
- mmcv.ops.box_iou_rotated(bboxes1: torch.Tensor, bboxes2: torch.Tensor, mode: str = 'iou', aligned: bool = False, clockwise: bool = True) → torch.Tensor[source]¶
Return intersection-over-union (Jaccard index) of boxes.
Both sets of boxes are expected to be in (x_center, y_center, width, height, angle) format.
If
aligned
isFalse
, then calculate the ious between each bbox of bboxes1 and bboxes2, otherwise the ious between each aligned pair of bboxes1 and bboxes2.Note
The operator assumes:
The positive direction along x axis is left -> right.
The positive direction along y axis is top -> down.
The w border is in parallel with x axis when angle = 0.
However, there are 2 opposite definitions of the positive angular direction, clockwise (CW) and counter-clockwise (CCW). MMCV supports both definitions and uses CW by default.
Please set
clockwise=False
if you are using the CCW definition.The coordinate system when
clockwise
isTrue
(default)0-------------------> x (0 rad) | A-------------B | | | | | box h | | angle=0 | | D------w------C v y (pi/2 rad)
In such coordination system the rotation matrix is
\[\begin{split}\begin{pmatrix} \cos\alpha & -\sin\alpha \\ \sin\alpha & \cos\alpha \end{pmatrix}\end{split}\]The coordinates of the corner point A can be calculated as:
\[\begin{split}P_A= \begin{pmatrix} x_A \\ y_A\end{pmatrix} = \begin{pmatrix} x_{center} \\ y_{center}\end{pmatrix} + \begin{pmatrix}\cos\alpha & -\sin\alpha \\ \sin\alpha & \cos\alpha\end{pmatrix} \begin{pmatrix} -0.5w \\ -0.5h\end{pmatrix} \\ = \begin{pmatrix} x_{center}-0.5w\cos\alpha+0.5h\sin\alpha \\ y_{center}-0.5w\sin\alpha-0.5h\cos\alpha\end{pmatrix}\end{split}\]The coordinate system when
clockwise
isFalse
0-------------------> x (0 rad) | A-------------B | | | | | box h | | angle=0 | | D------w------C v y (-pi/2 rad)
In such coordination system the rotation matrix is
\[\begin{split}\begin{pmatrix} \cos\alpha & \sin\alpha \\ -\sin\alpha & \cos\alpha \end{pmatrix}\end{split}\]The coordinates of the corner point A can be calculated as:
\[\begin{split}P_A= \begin{pmatrix} x_A \\ y_A\end{pmatrix} = \begin{pmatrix} x_{center} \\ y_{center}\end{pmatrix} + \begin{pmatrix}\cos\alpha & \sin\alpha \\ -\sin\alpha & \cos\alpha\end{pmatrix} \begin{pmatrix} -0.5w \\ -0.5h\end{pmatrix} \\ = \begin{pmatrix} x_{center}-0.5w\cos\alpha-0.5h\sin\alpha \\ y_{center}+0.5w\sin\alpha-0.5h\cos\alpha\end{pmatrix}\end{split}\]- Parameters
boxes1 (torch.Tensor) – rotated bboxes 1. It has shape (N, 5), indicating (x, y, w, h, theta) for each row. Note that theta is in radian.
boxes2 (torch.Tensor) – rotated bboxes 2. It has shape (M, 5), indicating (x, y, w, h, theta) for each row. Note that theta is in radian.
mode (str) – “iou” (intersection over union) or iof (intersection over foreground).
clockwise (bool) – flag indicating whether the positive angular orientation is clockwise. default True. New in version 1.4.3.
- Returns
Return the ious betweens boxes. If
aligned
isFalse
, the shape of ious is (N, M) else (N,).- Return type