# Learn the Basics This chapter introduces the basic conception of rotated object detection and the framework of MMRotate, and provides links to detailed tutorials about MMRotate. ## What is rotated object detection ### Problem definition Benefiting from the vigorous development of general object detection, most current rotated object detection models are based on classic general object detector. With the development of detection tasks, horizontal boxes have been unable to meet the needs of researchers in some subdivisions. We call it rotating object detection by redefining the object representation and increasing the number of regression degrees of freedom to achieve rotated rectangle, quadrilateral, and even arbitrary shape detection. Performing high-precision rotated object detection more efficiently has become a current research hotspot. The following areas are where rotated object detection has been applied or has great potential: face recognition, scene text, remote sensing, self-driving, medical, robotic grasping, etc. ### What is rotated box The most notable difference between rotated object detection and generic detection is the replacement of horizontal box annotations with rotated box annotations. They are defined as follows: - Horizontal box: A rectangle with the `width` along the `x-axis` and `height` along the `y-axis`. Usually, it can be represented by the coordinates of 2 diagonal vertices `(x_i, y_i)` (i = 1, 2), or it can be represented by the coordinates of the center point and the `width` and `height`, `(x_center, y_center, width, height)`. - Rotated box: It is obtained by rotating the horizontal box around the center point by an `angle`, and the definition method of its rotated box is obtained by adding a radian parameter `(x_center, y_center, width, height, theta)`, where `theta = angle * pi / 180`. The unit of `theta` is `rad`. When the rotation angle is a multiple of 90°, the rotated box degenerates into a horizontal box. The rotated box annotations exported by the annotation software are usually polygons, which need to be converted to the rotated box definition method before training. ```{note} In MMRotate, angle parameters are in radians. ``` ### Rotation direction A rotated box can be obtained by rotating a horizontal box clockwise or counterclockwise around its center point. The rotation direction is closely related to the choice of the coordinate system. The image space adopts the right-handed coordinate system `(y, x)`, where y is `up->down` and x is `left->right`. There are two opposite directions of rotation: - Clockwise(CW) Schematic of `CW` ``` 0-------------------> x (0 rad) | A-------------B | | | | | box h | | angle=0 | | D------w------C v y (pi/2 rad) ``` Rotation matrix of `CW` ```{math} \begin{pmatrix} \cos\alpha & -\sin\alpha \\ \sin\alpha & \cos\alpha \end{pmatrix} ``` Rotation transformation of `CW` ```{math} 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} ``` - Counterclockwise(CCW) Schematic of `CCW` ``` 0-------------------> x (0 rad) | A-------------B | | | | | box h | | angle=0 | | D------w------C v y (-pi/2 rad) ``` Rotation matrix of `CCW` ```{math} \begin{pmatrix} \cos\alpha & \sin\alpha \\ -\sin\alpha & \cos\alpha \end{pmatrix} ``` Rotation transformation of `CCW` ```{math} 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} ``` The operators that can set the rotation direction in MMCV are: - box_iou_rotated (Defaults to `CW`) - nms_rotated (Defaults to `CW`) - RoIAlignRotated (Defaults to `CCW`) - RiRoIAlignRotated (Defaults to `CCW`). ```{note} In MMRotate, the rotation direction of the rotated boxes is `CW`. ``` ### Definition of rotated box Due to the difference in the definition range of `theta`, the following three definitions of the rotated box gradually emerge in rotated object detection: - {math}`D_{oc^{\prime}}`: OpenCV Definition, `angle∈(0, 90°]`, `theta∈(0, pi / 2]`, The angle between the `width` of the rectangle and the positive semi-axis of x is a positive acute angle. This definition comes from the `cv2.minAreaRect` function in OpenCV, which returns an angle in the range `(0, 90°]`. - {math}`D_{le135}`: Long Edge Definition (135°),`angle∈[-45°, 135°)`, `theta∈[-pi / 4, 3 * pi / 4)` and `width > height`. - {math}`D_{le90}`: Long Edge Definition (90°),`angle∈[-90°, 90°)`, `theta∈[-pi / 2, pi / 2)` and `width > height`.