# A Method for Adapting Stereo Matching Algorithms to Real Environments
## 3 Materials and Methods
### Calculation of ACS Parameter
The coordinates of \(p\) are affected by rotation to a different extent, depending on angle \(\alpha\). In order to estimate rotation, the ACS module considers the keypoints located in the area in the vicinity of line X within the range for which \(|\alpha|<=\pi/6\). This area is marked in gray in Figure 3.  
The keypoints in this area are used to estimate the rotation performed in the ACS module on the basis of three factors. The first factor is related to the location of a keypoint in the image. If a point from the right side of the side image is shifted towards the top of the image, then it indicates that the rotation should be greater in the clockwise direction. In contrast, in the left part of an image, the location of a point higher than a corresponding point for the reference image indicates that it should be moved lower in the side image by rotating the image counterclockwise. Accordingly, the rotation is affected by locations that are too low for the corresponding points in the side image. The rotation of an image performed in the ACS module is estimated on the basis of the average discrepancies in the y-axis of the keypoints with respect to the angle \(\alpha\). This angle is equal to \(atan((y_{k1}-y_{k0})/(x_{center}-x_{k1}))\), where \(y_{k1}-y_{k0}\) is a discrepancy in the matched keypoints in the y-axis, and \(x_{center}-x_{k1}\) is the distance of a keypoint in the side image from the rotation center, which is in the middle of the image. The \(\alpha\) angle is, in fact, the rotation that should be executed in order to minimize the discrepancy in the considered point. An average value of these angles is calculated in order to adjust the rotation to the set of all considered keypoints. The value of \(\alpha\) is the first factor influencing the extent of the rotation \(\theta\) performed in the ACS module. The whole formula for estimating the rotation is presented in Equation (7). \[\theta=(\sum_{k=1}^{K}(atan((y_{k1}-y_{k0})/(x_{center}-x_{k1}))((1+\sqrt{(}2) )/2)(|x_{center}-x_{k1}|/x_{center}))/K \tag{7}\]  
The second factor influencing rotation is equal to \((1+\sqrt{(}2))/2\). The presence of this factor is a consequence of taking into account the keypoints from the whole area marked with gray in Figure 3. For these points, the rotation partly affects their x- and y-coordinates. The impact on the y-coordinate is the lowest for points placed along the line passing through the center and inclined at an angle of \(\pi/6\) to the horizontal line. The observation that a point on this line has a discrepancy of \(e\) indicates that a rotation resulting in moving the point by \(e\frac{1}{cos(\pi/6)}\) should occur. The rotation for discrepancies in the points on the edge of the considered area needs to be larger than the rotation for the same discrepancy located along line X. On line X, discrepancy \(e\) implies that a point should be moved \(e\) points in the y-axis. For this reason, the second factor is equal to \((1+\sqrt{(}2))/2\). It is an average value for the whole considered area. Figure 2: The process of estimating the parameters of transformations performed in the ACS module. The third factor included in Equation (7) is \((|x_{center}-x_{k1}|/x_{center})\). It is added in order to reduce the significance of points located closer to the center of an image. The significance of these points needs to be reduced because any minor inaccuracy in the estimation of the keypoint coordinates inappropriately indicates that a large rotation should be performed. For example, suppose a keypoint has a discrepancy of one pixel towards the top of an image and it is located two points to the side of the center of an image. In that case, such a discrepancy indicates that the image should be rotated by \(\pi/6\). However, if the location of this point was placed only two points lower, then it would indicate that such a rotation should be executed in a different direction.