# A Method for Adapting Stereo Matching Algorithms to Real Environments
## 3 Materials and Methods
### Calculation of ACS Parameter  
In order to execute the ACS module, it is necessary to estimate the values of parameters \(c\) and \(\theta\) for a pair of images processed by a stereo matching algorithm. The estimation of these parameters consists of the steps presented in Figure 2.  
In the first step, keypoints are identified in both of the images from a stereo camera. In the method presented in this paper, SURF descriptors are used for this purpose [25]. The keypoints detected on the left image are then matched with the keypoints of the right image. The next step consists of excluding some of the matched points from further calculations. One reason for excluding keypoints is related to the location of pairs of matched keypoints. Let us assume that a keypoint located in the left image at coordinates \((x_{k0},y_{k0})\) is matched with a keypoint located in the right image at coordinates \((x_{k1},y_{k1})\). The difference \(|y_{k0}-y_{k1}|\) indicates that these keypoints were matched incorrectly if this difference is beyond the acceptable value. The acceptance threshold is set by parameter \(H\). The value of this parameter depends on the extent of stereo camera inaccuracies that are expected to occur. The value of \(H\) is also influenced by the expected deterioration in camera calibration caused by its usage over time. In general, the number of inaccuracies remaining after a pattern-based calibration is low, and they are limited to a few pixels. Such a value is high enough to significantly deteriorate the quality of a disparity map obtained after processing these images, but it is not high enough to be corrected by additional calibration. A precise selection of parameter \(H\) is not crucial for the final results because its purpose is only to exclude pairs of points matched incorrectly from further calculations, i.e., points for which the location on a side image is evidently different from the location expected on the basis of a matched point on a reference image. The influence of the selection of parameter \(H\) on the quality of the results is presented in the experiments described in Section 4. After the selection of points, the ACS module estimates the \(c\) parameter. The \(c\) parameter is calculated directly from the disparity values of pairs of keypoints, contrary to a typical bundle adjustment, which is performed iteratively. As mentioned earlier, the ACS module executes for every pair of images processed by a stereo matching algorithm. Many of these algorithms are expected to work in real time. Therefore, any time-consuming process, such as iterative bundle adjustment, is not acceptable. Parameter \(c\) is obtained using Equation (6). \[c=\frac{\sum_{k=1}^{K}(y_{k0}-y_{k1})}{K} \tag{6}\]  
where \(y_{k0}\) and \(y_{k1}\) are the y-coordinates of corresponding keypoints, and the number of keypoints is \(K\). \(c\) is equal to the mean average of all differences in the vertical disparities of corresponding keypoints. As far as the rotations of images are concerned, the ACS module can improve calibration by rotating a side image. It is possible to estimate the extent of a necessary rotation only on the basis of the discrepancies of corresponding keypoints in the y-axis. The locations of corresponding keypoints in the x-axis are highly affected by the disparities caused by differences in the distances of the considered points from a stereo camera. The ACS module executes before stereo matching; therefore, differences in the locations of points in the x-axis are inconclusive for estimating inaccuracies in rotation. otation affects the components of points to a different extent, depending on the locations of the points. If the points are located along a horizontal line going through the center of an image, then these points are almost fully shifted in the y-axis. In this paper, this line is called line X. Let us denote with \(\alpha\) an acute angle that is between line X, a line passing through the center of an image, and some point \(p\).