# Distance Estimation with a Stereo Camera and Accuracy Determination
## 2 Materials and Methods  
To carry out the test, a simple test bench was set up, as illustrated in Figure 1. The main component of this bench was ESP32 microcontrollers (Espressif Systems, SSE: 688018.SH) with an attached OV2640 camera module (Waveshare Shenzhen, China), which offers a maximum resolution of up to 1600 \(\times\) 1200 pixels [12; 13]. The measurement setup consisted of two ESP32-CAM (OV2640) modules mounted in parallel on a single plane at a fixed distance of 5.4 cm from each other to facilitate stereovision, in which two cameras, acting as a stereo pair, captured images simultaneously. Precise parallel alignment and a fixed distance between the cameras were crucial to accurate depth measurement and triangulation. The cameras were securely mounted to avoid any displacement during the measurement process. A measuring tape was placed in front of the cameras, marking distances from 20 to 70 cm in 2.5 cm increments. This made it possible to precisely control the distance measurements. Three measurements were taken for each marked distance to ensure the precision and repeatability of the data. The cameras were mounted in the same perfectly even plane and precisely aligned with the edges to minimize the risk of misalignment. Minor deviations in the camera axes could introduce errors in the triangulation process, which would directly affect the precision of depth measurements. Even slight misalignment causes discrepancies in correspondence points between the images from the two cameras, which in turn leads to errors in distance determination. This project used Mask R-CNN to detect and segment objects in images from two ESP32-CAM cameras. Mask R-CNN, which is based on the ResNet-50 architecture with Feature Pyramid Network (FPN) functionality, allows for precise object position determination and accurate segmentation. Images are loaded and processed in a tensor, which is then passed to a model that returns bounding boxes, class labels, confidence values, and segmentation masks [14; 15; 16]. The detected bounding boxes of the two images are compared to calculate the distances between the corresponding boxes. Functions that convert box coordinates to different representations, such as midpoints or corners, are used for accurate calculations. A cost matrix is created, taking into account vertical and horizontal offsets and area differences, to determine the optimal assignments between objects. A linear assignment method is used to determine which boxes from one image correspond to boxes from another, enabling the tracking of object movement. The results of detection and assignments are visualized in the images using box drawing, class labels, and segmentation masks. This makes it easy to verify the accuracy of the detection and assignments, which is crucial for further analysis and applications. The use of Mask R-CNN  
Figure 1: Schematic view of the test bed for distance measurement with stereo cameras. in this project allowed for precise information about the movement and position of objects in space, which is essential for triangulation and object tracking. To calibrate the cameras in the project, the CameraWebServer program, available from Arduino.IDE (1.8.19.) software as a sample program after installing the camera library, was first uploaded to the ESP32-CAM modules. This program allows access to the video stream from the cameras via a web interface, allowing easy monitoring and recording of live images. With CameraWebServer, it is also possible to adjust camera parameters such as brightness, contrast, white balance, and exposure, which is key to obtaining the higher-quality images needed for calibration. After running the program and obtaining a stable connection to the cameras, the calibration process proceeded, which involved taking images from both cameras at 30 and 50 cm distances. These images were then processed with a Python script that uses the OpenCV library and the Mask R-CNN model for object detection. The script starts by loading the images and preprocessing them.