# Distance Estimation with a Stereo Camera and Accuracy Determination
## 2 Materials and Methods
It then uses the aforementioned neural network model to detect and classify objects in the images. Once the objects are detected, the script calculates various parameters, such as the positions of the objects' centers of mass, the distances between the objects, and the differences in their surfaces. The next step is to calculate the cost of moving objects between two images. In the context of image processing, especially in stereovision, these costs take into account differences in horizontal positions (\(X\)-axis displacement), vertical positions (\(Y\)-axis displacement), and changes in object surfaces. These costs are crucial to correctly matching objects detected in images from the two cameras, as they make it possible to determine exactly which elements in one image correspond to elements in the other image. The process involves analyzing the differences between the images and finding the best match for each object, which is necessary to calculate the distances to those objects. The script matches objects between images and then calculates the distances to those objects, taking into account the known distance between cameras and viewing angles. An important aspect of this process is the calculation of the focal length and angle tangent, which are necessary to accurately calculate the final distance to the objects. The focal length is a parameter that describes the ability of a lens to focus light, which is crucial in determining image scaling. The angle tangent, on the other hand, refers to the ratio of the distance between cameras to the distance to the object in the scene. The final distance away is calculated on the basis of these parameters, allowing you to accurately determine the distance to objects in the scene. If, after entering the calculated parameters and subjecting the uploaded images to analysis, the final distance agrees (30 or 50 cm), then the measurement has been made correctly. This was the basic calibration of the cameras using images from two distances, which provided the necessary camera parameters, namely the focal length and angle tangent, which will be used to estimate the distance of objects in other positions as well. In short, the calibration of the system consisted of taking images from both cameras at two known distances from the object. On the basis of the known parameters of the cameras, the distances between them, and image analysis, the necessary system parameters were determined. With these, the system was able to calculate the distances to objects based on new images at other distances. The calibration process is shown in the flow chart in Figure 2.  
The final element is the calculation of the distance of the object from the cameras. This was calculated based on Equation (1):  
\[d=f_{l}+\frac{d_{c}\cdot N}{2\cdot p\cdot tan\alpha} \tag{1}\]  
where:  
\(d\)--distance of the object from the cameras [cm];  
\(f_{l}\)--focal length of the cameras [cm];  
\(d_{c}\)--distance between cameras [cm];  
\(N\)--width of the image [px];  
\(p\)--difference in the position of corresponding points in the images from two cameras (parallax in stereoscopy) [px];tana_--tangent of the angle of view of the camera. This formula is based on the principles of trigonometry and the geometry of stereoscopic vision. The tangent of the angle helps to account for the divergence of the optical axes of the two cameras, and the parallax (\(p\)) helps determine the precise difference in position of the same object in the two images. The focal length (\(f_{l}\)) and the image width (\(N\)) are essential for scaling distances and accurately placing an object in three-dimensional space. To better understand the equation, a diagram was created, as shown in Figure 3.  
The methodology of the study included a test conducted on two objects: a white teacup and a LEGO human figure, as the previously mentioned identifying models detect  
Figure 3: Illustration of the calculation method. Figure 2: Flow chart of the calibration process. them without any problem.