## 3 Rail Track Detection Based on Approach of Computer Vision
Values between the thresholds are accepted only if the region is directly connected to the edge of strong intensity. Calibration of parameters can be performed depending on the input data, and it is a desirable part of the process [24]. As we can see in Figure 3b, the Canny method gave very good results; the edges of interest were identified. However, in order to single out only the track on which the train is moving (on which the camera is located), the method of separating the region of interest (ROI) was used. Array of the position follows:  
\[ \begin{array}{c}\text{array}([[[\text{750, 1080}],\\ \text{[1450, 1080}],\\ \text{[1000, 400]]]]).}\end{array}  \tag{2}\]  
After defining the ROI, the so-called image masking was performed. The pixel values are transferred to the binary domain (values 0 and 1). The idea behind it all is to merge the Canny image and the masked image, so that only the gradient region of interest remains. It is extremely important here that the images to be merged are of the same dimensions, because pixels are added together so that only pixels with a value of 1 are drawn. This procedure completed the first phase of the CV algorithm--the edges were isolated using the Canny edge detection method. The second phase of the CV algorithm--Hough transform--refers to rail track detection based on the results obtained using the Canny algorithm. [PERSON] et al. [25] proposed the Hough-transform-based Canny (HT-Canny) algorithm for edge detection. The HT-Canny  
Figure 4: Image processing. (**a**) Blurred image; (**b**) Canny image. algorithm can more efficiently detect the low-intensity edge compared to traditional algorithms. For instance, [PERSON] et al. [26] used a similar approach with Hough transform to that presented in this paper to detect railway tracks. By switching from the Cartesian coordinate system to the parametric (m, b), i.e., by mapping the lines from image space to points on the parametric space, as well as the points from image space to the lines on the parametric space, a Hough space was obtained. A \"grid\" was used to determine the points with the largest number of intersecting lines. The number of cells in this grid is stellate, so that the most optimal parameter is found, in order to obtain the best possible detection results. The cells with the largest number of cross-sections formed the best fit lines. There are several arguments in Hough transform's statement that are of paramount importance. The resolution of the Hough accumulator array (previously referred to in the text as a grid) filled with votes in each bin (previously mentioned as cell) represents a distinct value of r and \(\Theta\). These parameters define the size of the bins:  
* r--distance resolution of the accumulator in the pixels;
* \(\Theta\)--angle resolution of the accumulator in radians. Proved by trial-and-error method, the larger the bins, the worse the accuracy at the detection points. The smaller they are, the greater the accuracy of line detection, but it should not be exaggerated as it can lead to lower accuracy, as well as to the use of too many computer resources and, therefore, time. Finally, a precision of 2 pixels for r was taken, accompanied by \(1^{\circ}\) precision, \(\pi/180^{\circ}\) (in radians) for \(\Theta\). Two additional essential parameters also used:  
* Minimum line detection length (in pixels): 5;
* Maximum allowable gap (in pixels): 370. Figure 5 shows the results of the Hough transform for different input images. Additional research is necessary to optimize the CV algorithm for fast processing in the real-time system and increase of precision in the parts where the railway has curves or intersects with other tracks. Figure 6 shows the same track detail with initial Hough transform parameters (a) and with optimized set of parameters (b). Figure 6a shows certain detection errors that have been corrected by correcting parameters and optimizing the system, as shown in Figure 6b. Figure 5: Hough transform, detected track of the train route marked by blue lines.