Measurement technology based on structured light is a current research focus in the field of visual measurement and is widely applicable to various fields of industrial measurement. How to quickly and accurately locate and continuously track the rail head and rail waist region from dynamically changing laser fringe images remains a key issue to be solved in rail profile detection and analysis. An algorithm based on deep learning is proposed in this paper to realize the recognition of different types of rail profiles. A template-matching driven temporal and spatial contextual tracking algorithm is then employed to achieve rapid tracking of the railhead laser stripe. This method effectively solves the problem of profile measurement for passing trains at crossings and realizes accurate positioning and fast tracking of various types of laser stripes.