The rail transportation industry is moving towards heavy loads, high speeds as well as high density operation, which places higher demands on the quality of heavy rail. The quality inspection of rail defects using machine vision first requires obtaining clear surface/planar images of multiple surfaces of the hot heavy rail. Therefore, a vision inspection solution is proposed, which uses a 6-lane linear CCD to photograph the tread surface, bottom surface, and upper and lower waist surfaces of the heavy rail. A comprehensive comparison of various types of light sources was conducted through experiments on chromaticity, brightness, and spectral power. To solve the problem of image overexposure due to infrared radiation of the hot heavy rail, the spectral radiation characteristics of the hot heavy rail were analyzed, and the imaging effects of adding different filters were compared and analyzed. Finally, to solve the problem of out-of-focus due to oscillation of the heavy rail during rolling, the image is analyzed by an automatic focus search strategy, and the results are fed back to the camera to achieve automatic focus, thus adaptively obtaining good image quality and laying a good foundation for further defects detection.