# Bolt Loosening Detection Using Key-Point Detection Enhanced by Synthetic Datasets
## Materials and Methods
### Calculation of Bolt Loosening Angle
#### 2.4.3 Analysis of Perspective Errors  
In this subsection, the theoretical perspective error analysis of the bolt loosening angle calculation method proposed in this paper is presented. The bolt images obtained at different camera angles have different extents of perspective distortion. This kind of perspective distortion may lead to large errors in the calculation of the bolt loosening angle. The schematic diagram of the image perspective distortion caused by the camera angle is shown in Figure 15.  
Figure 14: Calculation of the rotation bolt loosening angle. Figure 13: The angular state of the fist bolt corner to the reference line. As shown in Figure 15a, when the camera shoots an object from a certain angle, the distance between two points on the actual object is changed in the camera frame according to the principle of perspective. Reflected in the image, the change in the distance leads to a change in the coordinates of the points. Coordinate changes to the corner points after perspective distortion is shown in Figure 15b. Since the width of the bolt is small in relation to the distance of the camera from the bolt, the coordinate change in the horizontal direction (\(x\)-axis) caused by the perspective distortion can be approximately ignored. Therefore, in the error analysis, this paper mainly considers the coordinate changes in the vertical direction (\(y\)-axis). Take the horizontal axis passing through the center of the bolt as the \(x\)-axis and the vertical axis as the \(y\)-axis. In the images obtained with the camera shooting bolts directly above, the coordinates of the three corner points in the upper half of the \(x\)-axis are in order, \(\left(x_{i-1},\ y_{i-1}\right),\left(x_{i},\ y_{i}\right),\left(x_{i+1},\ y_{i+1}\right)\). The relationship between these coordinates, as in Equation (4), can be found. \[\left\{ \begin{array}{c}x_{i}=r\times cosa_{i},\ \ y_{i}=r\times sina_{i}\\ x_{i-1}=r\times cosa_{i-1},\ \ y_{i-1}=r\times sina_{i-1},\ \ \alpha_{i-1}= \alpha_{i}+60^{\circ}\\ x_{i+1}=r\times cosa_{i+1},\ \ y_{i+1}=r\times sina_{i+1},\ \ a_{i+1}= \alpha_{i}-60^{\circ}\end{array} \right. \tag{4}\]  
where \(r\) is the radius of the outer circle of the bolt hexagon. In the image taken by the camera at angle \(\beta\) above, after perspective distortion, the coordinates of the three corner points in the upper half of the \(x\)-axis are, in order, \(\left(x_{i-1}^{\#},\ y_{i-1}^{\#}\right),\left(x_{i}^{\#},\ y_{i}^{\#}\right), \left(x_{i+1}^{\#},\ y_{i+1}^{\#}\right)\). The following equation can be achieved according to the geometric relationship in perspective distortion. \[\left\{ \begin{array}{c}x_{i}^{\#}=x_{i}\\ y_{i}^{\#}\cong\ y_{i}\times cos\gamma\\ \gamma\cong\beta\end{array} \right. \tag{5}\]  
where \(\gamma\) is the angle of the camera imaging sensor plane across the plane of the bolt and \(\cong\) is the approximately equal sign. Combining Equations (4) and (5), the result of the following equation can be calculated. \[\left\{ \begin{array}{c}x_{i}^{\#}=r\times cosa_{i},\ \ y_{i}^{\#}=r\times sina_{i} \times cos\beta\\ x_{i-1}^{\#}=r\times cos(\alpha_{i}+60^{\circ}),\ \ y_{i-1}^{\#}=r\times sin( \alpha_{i}+60^{\circ})\times cos\beta\\ x_{i+1}^{\#}=r\times cos(\alpha_{i}-60^{\circ}),\ \ y_{i+1}^{\#}=r\times sin( \alpha_{i}-60^{\circ})\times cos\beta\end{array} \right. \tag{6}\]  
Figure 15: Schematic diagram of image perspective distortion caused by camera angle. (**a**) Geometric principle of perspective distortion; (**b**) Coordinate changes in corner points after perspective distortion. Accordingly, the angle \(\alpha_{i}^{\#}\) between each corner point and the \(x\)-axis after perspective deformation can be calculated. \[\left\{ \begin{array}{c}\alpha_{i}^{\#}=arctan\frac{y_{i}^{\#}}{x_{i}^{\#}}\\ \alpha_{i-1}^{\#}=arctan\frac{y_{i-1}^{\#}}{x_{i-1}^{\#}}\\ \alpha_{i+1}^{\#}=arctan\frac{y_{i+1}^{\#}}{x_{i+1}^{\#}}\end{array} \right. \tag{7}\]  
The calculation of the three corner points in the bottom half of the \(x\)-axis is the same as the process described above.