## 2 Methods
### Binocular Camera Distance Measurement  
In the previous section we have assumed that the lane width is 4.5 m, but for real road conditions, the lane width varies from road to road, so it is necessary to actually measure the lane width. The accuracy of the front monocular camera in measuring the lateral width is not enough, so this paper uses two binocular cameras fixed under the left and right  
Figure 6: Value of the intersection of the left and right lane lines on the \(x\)-axis.  
Figure 7: Flow chart of monocular camera lane change judgment.  
rearview mirrors of the vehicle to measure the distance between the two sides of the vehicle from the lane line, and then measure the distance between the two cameras under the left and right rearview mirrors to find out the lane width. The basic principle of binocular camera stereo vision is to use two cameras to complete binocular image acquisition of the target in front of the lens. Due to the difference in the shooting angle and position of the left and right cameras for image acquisition, there is a certain parallax between the two images of the target object acquired by the two cameras at the same moment, and the spatial coordinates of the target object are derived based on the parallax [25]. The binocular vision ranging model is shown in Figure 8.  
In the Figure 8, \(O_{l}\), and \(O_{r}\) are the optical center positions of the two cameras. The length of the line between \(O_{l}\) and \(O_{r}\) is the baseline distance \(B\), \(Z\) is the optical axis of the left camera, the left and right cameras are parallel to each other. If there is a point \(P(x,y,z)\) in space, the projection points on the left and right camera images are \(P_{l}(x_{l},y_{l})\) and \(P_{r}(x_{r},y_{r})\). When the left and right cameras are mounted ideally, then we have \(y_{l}=y_{r}=y^{\prime}\). The following equation can be derived from similar triangles:  
\[\left\{\begin{array}{l}x_{l}=f\frac{x}{z}\\ x_{r}=f\frac{B-x}{z}\\ y^{\prime}=f\frac{y}{z}\end{array}\right. \tag{18}\]  
By transforming the above equation, it is possible to derive the coordinate equation that can solve for the point P in space.  
\[\left\{\begin{array}{l}x=\frac{B\cdot x_{l}}{x_{l}-x_{r}}=\frac{B\cdot x_{l }}{D}\\ y=\frac{B\cdot y^{\prime}}{x_{l}-x_{r}}=\frac{B\cdot y^{\prime}}{D}\\ Z=\frac{B\cdot f}{x_{l}-x_{r}}=\frac{B\cdot f}{D}\end{array}\right. \tag{19}\]  
In the above equation, \(D=x_{l}-x_{r}\), is called the parallax of the two images captured by the left and right cameras. The above equation shows that to find the coordinates of a spatial point using a binocular camera requires the baseline distance \(B\) of the left and right cameras, the parallax \(D\) of the left and right images, and the focal length \(f\) of the camera. \(B\) and \(f\) are derived from the calibration of the camera, and in this paper the binocular camera is calibrated using the Zhengyou Zhang calibration method [26]. Parallax \(D\) is obtained by stereo matching, and this paper uses the Block Matching (BM) algorithm that comes with OpenCV to perform stereo matching, which has the advantage that the algorithm is fast, which meets our requirement of using it on a moving vehicle.  
Figure 8: Model for distance measurement by binocular camera.