## 2 Materials and Methods
### Binocular Distance Measurement Algorithm  
Binocular vision leverages the parallax principle to ascertain the three-dimensional attributes of the object intended for measurement, utilizing images captured by left and right cameras. As illustrated in Figure 4, for any spatial point, both cameras simultaneously capture the point's position, denoted as W. Based on the spatial positions xl and xr read by each camera, the position of spatial point W is calculated. The 3D world coordinates of an object are projected onto the image plane and transformed into 2D image coordinates during camera imaging. Conversely, in the binocular vision 3D reconstruction process, the aim is to reverse this operation, reconstructing the object's 3D world coordinates from its 2D image coordinates. This reconstruction necessitates utilizing parallax information from binocular cameras. The positions of the imaging points captured by the left and right cameras in the image coordinate system require a spatial transformation matrix to map them into 3D world coordinates. This transformation hinges on the binocular cameras' internal and  
Figure 4: Binocular disparity principle. external parameters. The internal parameters include the focal length, optical center, and lens aberration coefficient, characterizing the camera sensor's imaging properties. The external parameters describe the camera's position and orientation relative to the world coordinate system, incorporating the rotation matrix and the translation vector between the two cameras. The above parameters, which are crucial for 3D reconstruction, are obtainable through precise calibration. MATLAB 2020a's Camera Calibration Toolbox is employed for this standard calibration, which involves capturing a series of images of a fixed calibration object (such as a checkerboard grid) to extract spatial geometric feature points and compute the camera's internal and external parameters. \(W(X,Y,Z)\) is considered a spatial point for which the imaging point in the pixel coordinate system is \((u,\ v)\) and the model plane is \(\text{Z}=0\). The parameters can be obtained by utilizing the checkerboard grid coordinates as the world coordinate system. They can be derived using Equation (7):  
\[\text{s} \begin{bmatrix}u\\ v\\ 1\end{bmatrix} =A \begin{bmatrix}r_{1}&r_{2}&r_{3}&t\\ \end{bmatrix}\begin{bmatrix}X\\ Y\\ 0\\ 1\end{bmatrix} =A \begin{bmatrix}r_{1}&r_{21}&r_{3}\\ \end{bmatrix}\begin{bmatrix}X\\ Y\\ 1\end{bmatrix}  \tag{7}\]  
where the variables are defined as follows:  
\(s\) represents the scale factor, indicating the mapping scale;  
\( \begin{bmatrix}r_{1}&r_{2}&r_{3}\\ \end{bmatrix} \) denotes the rotation matrix between the camera coordinate system and the world coordinate system;  
\(r_{1}\) and \(r_{2}\) are unit orthogonal vectors within the unit orthogonal matrix;  
\(t\) symbolizes the translation vector of the camera coordinate system relative to the world coordinate system;  
\(A\) is the camera parameter matrix, as shown in Equation (8). \[\text{A}= \begin{pmatrix}f_{x}&0&u_{0}\\ 0&f_{y}&v_{0}\\ 0&0&1\end{pmatrix}  \tag{8}\]  
Here, \(f_{x}\) represents the number of pixels focused in the x-direction, and \(f_{y}\) signifies the number of pixels focused in the y-direction. The coordinates \((u_{0},\ v_{0})\) denote the camera's center point. Let \(\text{H}= \begin{bmatrix}r_{1}&r_{21}&t\end{bmatrix} = \begin{bmatrix}h_{1}&h_{2} &h_{3}\end{bmatrix} \) to obtain Equations (9) and (10):  
\[s \begin{bmatrix}u\\ v\\ 1\end{bmatrix} =H \begin{bmatrix}X\\ Y\\ 1\end{bmatrix}  \tag{9}\]  
\[ \begin{cases}h_{1}^{T}A^{-T}A^{-1}h_{2}=0\\ h_{1}^{T}A^{-T}A^{-1}h_{1}=h_{2}^{T}A^{-T}A^{-1}h_{2}\end{cases}  \tag{10}\]  
The matrices for both the internal and external parameters can be obtained using Equations (7)-(10). After calibration, we utilize functions from the OpenCV 4.5.5 library for image correction in the binocular system. Initially, parameters are fed into the cv2.stereoRectify() function, enabling the correction of images from both cameras to a nearly coplanar 2D plane.