Aiming at the existing problems in the line detection for standard Hough transform, a line detection algorithm based on improved random Hough transform is proposed. The pixels of edge images are clustered and grouped by 8-neighborhood search. The concept of the pixel gradient direction difference is proposed, and the gradient direction difference between adjacent pixel is calculated in each edge group, thus the line pre-detection is carried out to exclude the edge groups without line features. Based on the theory of the random sample consensus algorithm, the improved random Hough transformation algorithm with a linear parameter pre-test model is proposed. The research results show that the proposed algorithm effectively solves the problem in standard Hough transform and improves the error detection rate in the process of line detection. The proposed algorithm has the advantages of fast detection and high detection accuracy.