## 2 Materials and Methods
### Zigzag Length Determination Based on Image Processing
#### 2.3.2 Real-Time Method Based on Image Processing  
The real-time method uses an optical tracking system based, as in the previous method, on a video monitoring camera and a GPS sensor. The zigzag length measurement method is based on tracking a specific region that is called a \"track image\", which contains crucial data that can be used in our goal. The main specifications of the used monitoring camera involve a video streaming image resolution of x = 1280 pixels and y = 960 pixels, as well as an acquisition rate of 30 frames per second in RGB 32-bit format mode. Figure 6: Front panel of the LabVIEW program utilizing the laboratory method: (**a**) original image, (**b**) non-positioned image with the slider, (**c**) image positioned with the slider. Figure 7: The link diagram of the LabVIEW program for measuring zigzag length. The camera operates in continuous mode and transmits images to the LabVIEW program. The LabVIEW program uses a tracking technique based on image pattern recognition, as shown in Figure 8. The track image has a size of (x' by y') pixels. The algorithm determines the object's center, C(x\({}_{0}\),y\({}_{0}\)), then displays both this point and the track image contour on the original image. The zigzag length can be calculated using the track image and C(x\({}_{0}\),y\({}_{0}\)) coordinates. One of the most important concerns is choosing the track image in scope so that it can be easily distinguished from the original image. The track image was chosen to include a rectangular zone that includes the intersection point between the red bar support and the contact wire, as illustrated in Figure 9.  
The zigzag length can be calculated using the x pixel of the C point and the marker on the pantograph plate, as shown in Table 3. The highlighted lines from Table 3 are shown in Figure 9. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Zigzag Length [mm]** & **x Pixel** & **Zigzag Length [mm]** & **x Pixel** \\  & **Coordinate** & & **Coordinate** \\ \hline \(-350\) & 645 & 0 & 825 \\ \(-300\) & 660 & 50 & 850 \\ \(-250\) & 680 & 100 & 875 \\ \(-200\) & 700 & 150 & 905 \\ \(-150\) & 730 & 200 & 935 \\ \(-100\) & 760 & 250 & 970 \\ \(-50\) & 790 & 300 & 1000 \\ \(0\) & 825 & 350 & 1030 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Relation between zigzag length and the x\({}_{0}\) pixel value. Figure 8: Matching image process. Figure 9: Relation between zigzag length and the x\({}_{0}\) pixel value: (a) length = \(-200\) mm, (b) length = \(0\) mm, (c) length = \(200\) mm. Figure 10, which illustrates the relationship between zigzag length, \(z\), and horizontal pixel location, x, shows a linear variation according to Equation (1). \[z=(5x-4100)/3, \tag{1}\]  
Table 3 shows that for a zigzag length change of \(-350\) mm to \(350\) mm, the x pixel coordinate variation ranges from \(645\) to \(1030\), for a total of \(385\) x pixel coordinate variations. In this context, the measuring error is \(1/385\), or \(0.26\%\). Figure 11 illustrates the front panel of the LabVIEW program using the real-time method. Because this method requires a real-time determination of the zigzag length, the \"View\" and \"Modify\" menus are not utilized. Instead, the program permits users to access the other four options. The first menu option, \"Select frame\", allows the human operator to select a specific frame for the future track image. Typically, this menu is utilized at the start of the measuring process, when the inspection vehicle is stopped. The \"Learn track\" menu permits the user to choose a certain rectangular zone as the future track image. The selected track image can be saved via the \"Save track\" menu. To start the measurement process, the human operator can select an image track from the previously created image track library using the menu \"Input track\". Figure 11: Front panel of the LabVIEW program utilizing the real-time method.