Rail Detection Based on LSD and the Least Square Curve Fitting


It is necessary to rely on the rail gauge to determine whether the object beside the track will affect train operation safety or not. A convenient and fast method based on line segment detector (LSD) and the least square curve fitting to identify the rail in the image is proposed in this paper. The image in front of the train can be obtained through the camera on-board. After preprocessing, it will be divided equally along the longitudinal axis. Utilizing the characteristics of the LSD algorithm, the edges are approximated into multiple line segments. After screening the terminals of the line segments, it can generate the mathematical model of the rail in the image based on the least square. Experiments show that the algorithm in this paper can fit the rail curve accurately and has good applicability and robustness.

This is a preview of subscription content, access via your institution.


  1. [1]

    A. Catalano, F. A. Bruno, C. Galliano, M. Pisco, G. V. Persiano, A. Cutolo, A. Cusano. An optical fiber based intracellular system for railway security. Sensors and Actuators A: Physical, vol. 253, pp. 91–100, 2017. DOI: https://doi.org/10.1016/j.sna.2016.11.026.

    Article  Google Scholar 

  2. [2]

    Z. Teng, F. Liu, B. P. Zhang. Visual railway detection by superpixel based intracellular decisions. Multimedia Tools and Applications, vol. 75, no. 5, pp. 2473–2486, 2016. DOI: https://doi.org/10.1007/s11042-015-2654-x.

    Article  Google Scholar 

  3. [3]

    A. I. Potekhin, S. A. Branishtov, S. K. Kuznetsov. Discrete-event models of a railway network. Automation and Remote Control, vol. 77, no. 2, pp. 344–355, 2016. DOI: https://doi.org/10.1134/S0005117916020107.

    MathSciNet  Article  MATH  Google Scholar 

  4. [4]

    Z. L. Wang, B. G. Cai. Geometry constraints-based method for visual rail track extraction. Journal of Transportation Systems Engineering and Information Technology, vol. 17, no. 6, pp. 56–62, 84, 2017. DOI: https://doi.org/10.16097/j.cnki.1009-6744.2017.06.009. (in Chinese)

    Article  Google Scholar 

  5. [5]

    L. Y. Liu, Q. Chen, Y. N. Li, Y. H. Yang, Y. She. Feature points extraction from high speed railway track images based on second derivative Harris operator. Science of Surveying and Mapping, vol. 40, no. 5, pp. 84–88, 2015. DOI: https://doi.org/10.16251/j.cnki.1009-2307.2015.05.018. (in Chinese)

    Article  Google Scholar 

  6. [6]

    Q. X. Wang, X. F. Liang, Y. L. Liu, Z. J. Lu, C. Peng. Railway rail identification detection method using machine vision. Journal of Central South University (Science and Technology), vol. 45, no. 7, pp. 2496–2502, 2014. (in Chinese)

    Google Scholar 

  7. [7]

    Y. Dong, B. Guo. Railway track detection algorithm based on Hu invariant moment feature. Journal of the China Railway Society, vol. 40, no. 10, pp. 64–70, 2018. DOI: https://doi.org/10.3969/j.issn.1001-8360.2018.10.010. (in Chinese)

    MathSciNet  Article  Google Scholar 

  8. [8]

    Z. Hang, Y. Dong. Rail detection algorithm based on Hough transform and Catmull-ROM spline curve. Journal of Graphics, vol. 39, no. 6, pp. 1078–1083, 2018. DOI: https://doi.org/10.11996/JG.j.2095-302X.2018061078. (in Chinese)

    Article  Google Scholar 

  9. [9]

    Y. L. Sun. Research on Automatic Detection Algorithm of Railway Obstacles Based on Image, Ph. D. dissertation, Xidian University, Xi’an, China, 2018. (in Chinese)

    Google Scholar 

  10. [10]

    Q. X. Wang, X. F. Liang, Y. L. Liu, Z. J. Lu, C. Peng. Visual detection method for the invasion of slowly changing foreign matters to railway lines. China Railway Science, vol. 35, no. 3, pp. 137–143, 2014. DOI: https://doi.org/10.3969/j.issn.1001-4632.2014.03.21. (in Chinese)

    Article  Google Scholar 

  11. [11]

    X. Y. Gong, H. Su, D. Xu, Z. T. Zhang, F. Shen, H. B. Yang. An overview of contour detection approaches. International Journal of Automation and Computing, vol. 15, no. 6, pp. 656–672, 2018. DOI: https://doi.org/10.1007/s11633-018-1117-z.

    Article  Google Scholar 

  12. [12]

    R. C. Gonzalez, R. E. Woods. Digital Image Processing, Q. Q. Ruan, Y. Z. Ruan, trans, 3rd ed., Beijing, China: Publishing House of Electronics Industry, pp. 221, 449–466, 2017.

    Google Scholar 

  13. [13]

    W. L. Cui, Y. J. Wang, S. Q. Kang, J. B. Xie, Qingyan Wang, V. I. Mikulovich. Road lane line detection method based on improved YOLOV3 algorithm. Acta Automatica Sinica, Published online (in Chinese) DOI: https://doi.org/10.16383/j.aas.c190178.

  14. [14]

    C. Xin, Y. Liu. Research on lane recognition algorithm based on probability Hough transform. Bulletin of Surveying and Mapping, no. S2, pp. 52–55, 2019. (in Chinese)

  15. [15]

    X. J. Zheng, B. J. Zhong. Overview and evaluation of image straight line segment detection algorithms. Computer Engineering and Application, vol. 55, no. 17, pp. 9–19, 2019. DOI: https://doi.org/10.3778/j.issn.1002-8331.1905-0255. (in Chinese)

    Article  Google Scholar 

  16. [16]

    Y. Y. Wei, F. Y. Zhao. The evaluation criteria of optimal curve fitting. Science of Surveying and Mapping, vol. 35, no. 1, pp. 195–196, 185, 2010. DOI: https://doi.org/10.16251/j.cnki.1009-2307.2010.01.024. (in Chinese)

    Article  Google Scholar 

  17. [17]

    R. G. von Gioi, J. Jakubowicz, J. M. Morel, G. Randall. LSD: a fast line segment detector with a false detection control. IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 32, no. 4, pp. 722–732, 2010. DOI: https://doi.org/10.1109/TPAMI.2008.300.

    Article  Google Scholar 

  18. [18]

    B. Guo, Y. Dong. Railway track detection algorithm based on piecewise curve model. Journal of Railway Science and Engineering, vol. 14, no. 2, pp. 355–363, 2017. DOI: https://doi.org/10.3969/j.issn.1672-7029.2017.02.022. (in Chinese)

    Article  Google Scholar 

  19. [19]

    C. K. Chui, G. R. Chen. Kalman Filtering with Real-time Applications, 5th ed., H. D. Dai, J. Li, S. L. Zhou, Trans., Beijing, China: Tsinghua University Press, pp. 16–23, 2018. (in Chinese)

    Google Scholar 

  20. [20]

    H. M. Shi, M. Xu, Z. J. Yu. Track gauge measurement method based on least-square curve fitting theory. Journal of the China Railway Society, vol. 41, no. 12, pp. 81–88, 2019. (in Chinese)

    Google Scholar 

  21. [21]

    B. C. Xu, X. L. Liu. Identification algorithm based on the approximate least absolute deviation criteria. International Journal of Automation and Computing, vol. 9, no. 5, pp. 501–505, 2012. DOI: https://doi.org/10.1007/s11633-012-0673-x.

    Article  Google Scholar 

Download references


This work was supported by National Natural Science Foundation of China (No. 61 763 023).

Author information



Corresponding author

Correspondence to Yun-Shui Zheng.

Additional information

Yun-Shui Zheng received the B. Sc. and M. Sc. degrees in traffic information engineering & control from Lanzhou Jiaotong University, China in 1994 and 2008, respectively. In 2008, he was a faculty member at Lanzhou Jiaotong University. Currently, he is a professor of Automatic Control Department, Lanzhou Jiaotong University, and a researcher of Automation Research Institute, Lanzhou Jiaotong University. He has won a first prize and two third prizes in the national multimedia software competition. He participated in the compilation of one textbook and published many papers. Now, he is in charge of a science and technology support project of Gansu Provincial Science and Technology.

His research interests include the application of modern traffic information technology, the research of new generation centralized control system, the reliability research of high-speed railway signal equipment, the research and application of multimedia and virtual reality technology.

Yan-Wei Jin received the B. Sc. degree in traffic information engineering & control from Lanzhou Jiaotong University, China in 2018. Currently, he is a master student in traffic information engineering & control of Lanzhou Jiaotong University.

His research interests include railway safety, sensor application and image processing.

Yu Dong received the B. Sc. degree in traffic signal & control from Lanzhou Jiaotong University, China in 1985. In 1985, he was a faculty member at Lanzhou Jiaotong University. Currently, he is a professor of Automatic Control Department, Lanzhou Jiaotong University. He participated in the research project and won a second prize, a third prize and one second prize of teaching achievements in Gansu Province. He edited two textbooks, participated in writing two textbooks, published more than twenty academic papers. He presided over a scientific and technological research project of Gansu Province, and now undertakes a project of National Nature Science Foundation of China (NSFC).

His research interest is rail transit transportation automation.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Zheng, YS., Jin, YW. & Dong, Y. Rail Detection Based on LSD and the Least Square Curve Fitting. Int. J. Autom. Comput. 18, 85–95 (2021). https://doi.org/10.1007/s11633-020-1241-4

Download citation


  • Rail inspection
  • line segment detector (LSD) algorithm
  • the least square
  • curve fitting
  • foreign object detection