# Tilt-Induced Error Compensation with Vision-Based Method for Polarization Navigation
## 2 Principle of Visual Horizontal Attitude Angle Measurement
### Attitude Estimation Algorithm Based on Horizon  
According to the horizon projection model shown in Figure 6, the world coordinate system, the body coordinate system and the image coordinate system are established. The camera is fixed on the head of the UAV, with the camera coordinate system overlapped with the body coordinate system.  
Let \(p_{w}\) represent any point on the horizon whose coordinate in the world coordinate system is \(p_{w}=(x_{w},0,0)\), then the coordinates of the projection point \(p^{\prime}\) in the pixel coordinate system can be obtained by the following formula:  
\[sp_{u}=AR(R_{0}\mathtt{p}_{w}+T) \tag{15}\]  
Figure 4: Image edge detection results. (**a**) Original image; (**b**) Edge detection result using the basic Canny algorithm; (**c**) Edge detection result using the improved Canny algorithm.  
where \(s\) is the scale factor, \(A\) is the internal reference matrix, and \(R\) is the rotation matrix, \(R=R_{1}R_{2}R_{3}\), with \(R_{1}\), \(R_{2}\), and \(R_{3}\) corresponding to the rotation matrices obtained around the three axes, respectively. \(R_{0}\) denotes the rotation matrix of the UAV at its initial position. Assuming that the center point \(o_{w}\) of the world coordinate system is located on the \(yoz\) plane, the position of \(o_{w}\) in the camera coordinate system is \(T=\left(0,t_{y},t_{z}\right)^{T}\), and the yaw angle is 0. The following expansion of Equation (15) can be obtained:  
\[s\begin{bmatrix}u\\ v\\ 1\end{bmatrix}=\begin{bmatrix}f_{x}[x_{w}\cos\phi-\sin\phi(t_{y}\cos\theta-t_{ z}\sin\theta)]+u_{0}(t_{y}\sin\theta+t_{z}\cos\theta)\\ f_{y}[x_{w}\sin\phi+\cos\phi(t_{y}\cos\theta-t_{z}\sin\theta)]+v_{0}(t_{y}\sin \theta+t_{z}\cos\theta)\\ t_{y}\sin\theta+t_{z}\cos\theta\end{bmatrix} \tag{16}\]  
Since the horizon is infinitely distant from the ground, that is, \(t_{z}\rightarrow+\infty\), when \(\phi\
eq\pi/2\), the variables are brought into the formula and \(x_{w}\) is eliminated. The simplification can be achieved:  
\[v=(\frac{f_{y}}{f_{x}}\tan\phi)(u-u_{0})-\frac{f_{y}}{\cos\phi}\tan\theta+v_{0} \tag{17}\]  
where \(f_{x},f_{y}\), \(u_{0}\), and \(v_{0}\) represent the focal lengths and principal point coordinates in the internal parameter matrix \(A\), respectively. These parameters were obtained via camera  
Figure 5: Visual Illustration of Horizon Extraction Process.  
Figure 6: Horizon projection model.  
calibration, yielding \(f_{x}=417.4831,f_{y}=417.5472\), \(u_{0}=327.8796\), \(v_{0}=214.3221\). If we assume that the slope of the straight line is \(k\) and the intercept is \(b\), then:  
\[\left\{\begin{array}{l}\phi=\arctan(k\frac{f_{x}}{f_{y}})\\ \theta=\arctan\left[\frac{(v_{0}-ku_{0}-b)\cos\phi}{f_{y}}\right]\end{array}\right. \tag{18}\]  
When the roll angle \(\phi=\pm\pi/2\), the horizon in the pixel coordinate system is perpendicular to the u-axis at the point up, then the horizon equation is \(u=u_{p}\) and the pitch angle can be obtained as  
\[\theta=\arctan(\frac{u_{p}-u_{0}}{f_{x}}) \tag{19}\]  
From the above analysis, as long as the horizon in the UAV-captured image can be accurately and reliably extracted, and its linear parameters determined, the roll angle and pitch angles of the UAV can be calculated using the formula.