## 3 Approach
### Rail Track Topology Reconstruction  
#### 3.2.1 Coordinate System Setup  
Our train-mounted equipment is installed as shown in Figure 4. Our algorithm implementation requires one LiDAR and one telephoto camera, both mounted on the top of the train's locomotive. It is worth noting that the positions of the LiDAR and camera are parallel to the ground. However, the images captured by the camera exhibit a perspective projection relationship with the real world. We propose a method to transform perspective-projected images into orthogonal projection and then perform post-processing under orthogonal projection. Under orthogonal projection, a pair of rail lines are parallel and their pixel dimensions are proportional to the actual distance. We therefore use a homography transformation [34] to convert the image of the perspective projection into an orthogonal projection and use the camera parameters and poses to localize the orthogonal image, as shown in Figure 5b. As shown in Figure 5a, we set the midpoint of the track directly below the front of the train as the origin of the rail coordinate system, the direction of travel of the train as the \(z\)-axis, the axis perpendicular to the rail plane and facing upwards as the \(y\)-axis, and the direction of the \(x\)-axis pointing to the left of the \(z\)-axis. The camera and LiDAR coordinate systems are set up similarly. The normal vector of the image plane is aligned with the \(z\)-axis, facing outwards, while the vector pointing upwards is aligned with the \(y\)-axis. The \(x\)-axis is positioned to the left of the \(z\)-axis. Figure 4: The LiDAR and camera are positioned at the top of the locomotive’s front end, with their field of view centers parallel to the ground. The transformation relationship between the camera coordinate system and the rail coordinate system is shown in Equation (1), where \(Z_{c}\) is the depth of the object point to the image plane, \(K\) is the camera intrinsic parameters, and \(T_{r\_c}\) is the extrinsic parameters of the camera relative to the rail coordinate system. In our system, the pixel coordinate of the image is represented by \(u\) and \(v\) where \(u\) represents the horizontal pixels, while \(v\) represents the vertical pixels. The railroad track coordinate is represented by \(X_{r}\), \(Y_{r}\), and \(Z_{r}\). \[Z_{c} \begin{bmatrix}u\\ v\end{bmatrix} =KT_{r\_c} \begin{bmatrix}X_{r}\\ Y_{r}\\ Z_{r}\end{bmatrix} ,Y_{r}=0 \tag{1}\]  
Based on Characteristic 2, the points in the rail track area all have zero \(Y\)-values in the rail coordinate system and a linear system of equations can be created with known parameters to calculate the point coordinates in the rail coordinate system for each pixel in the camera coordinate system. \[ \begin{bmatrix}u\\ v\\ 1\end{bmatrix} =M \begin{bmatrix}X_{r}\\ 0^{T}\\ Z_{r}\end{bmatrix} ,M= \begin{bmatrix}R&t\\ 0^{T}&1\end{bmatrix}  \tag{2}\]  
\[ \begin{bmatrix}X_{r}\\ 0\\ Z_{r}\\ 1\end{bmatrix} =S \begin{bmatrix}u_{0}\\ v_{0}\\ 1\\ 1\end{bmatrix}  \tag{3}\]  
This transformation process is shown by Equation (2), where \(M\) is the transformation matrix from camera to rail coordinates [37,38]. The orthogonal projection can be considered as a scaling and rotation of the points in the rail track coordinate system, this process can be represented by (3), where \(S\) is the transformation matrix of the two coordinate systems and \(u_{0}\) and \(v_{0}\) are the pixel points of the orthogonal image coordinate system. Similarly, the LiDAR point cloud is projected in the rail coordinate system using a similar approach. Figure 5: Diagram of the coordinate system setup and projection process. (**a**) Illustrates the setup of coordinate systems, where three coordinate systems, namely the camera coordinate system, the LiDAR coordinate system, and the railway coordinate system, are defined for ease of computation and representation.