'I need to measure the gap between railway switch and track using python

I need to predict the gap in railway switch using python.

Switch image:

switch image



Solution 1:[1]

This is how the signal looks like when you average an horizontal slice in the image. The gap appears as the highest pair of light-to-dark and dark-to-light transitions. By combining several such measurements (+ dimensional calibration), you obtain the info that you want.

enter image description here

Solution 2:[2]

This is a way to general question.
The most important thing you need to know is the scale of the image.
Scale could be like, 1mm for 1 pixel.
The second step is to detect two rails, Here you can use a segmentation model and train to identify tracks.
Then simple find the shortest distance between those two identifies rails.
This is not a simple task, you need to brain strom around the above ideas.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yves Daoust
Solution 2 Kalyan Reddy