Borehole lithology histogram is one of the main achievements of geological exploration and resource development. In the past, drilling lithology histograms were mainly drawn by hand, which had the problems of high labor intensity and low efficiency. With the rapid development of intelligent recognition technology, it is possible to automatically stratify the lithology of drilling and logging results. Based on this, this study realizes the automatic stratification algorithm of drilling lithology based on computer vision: firstly, the natural gamma logging data obtained from the logging of YCJ90/360(A) drilling logging analyzer, which is specially used for the comprehensive logging technology of coal mine downhole, are preprocessed and analyzed by clustering, so as to realize the automatic stratification of logging curves; and then for the intelligent recognition technology of YOLOv5 on the synchronous video, the recognition accuracy is low and the effect is not good. Then, the network structure of YOLOv5 is improved in view of the problems of low accuracy and poor effect of YOLOv5 recognition; finally, the automatic stratification algorithm is designed in coordination with the automatic stratification and synchronous video intelligent recognition algorithm, and the accuracy of automatic stratification of borehole lithology is evaluated by using the two indexes of average stratification composite matching degree and average lithology composite matching degree. The results of the study show that: ①the average precision mean, accuracy and recall of the improved YOLOv5 algorithm have been improved by 9.86%, 5.38% and 4.96%, respectively, compared with the YOLOv5 algorithm; 2the average layered composite matching degree of the drilled hole lithology automatic layering is 85.05%, and the average lithology matching degree is as high as 94.02%, which verifies the accuracy of the drilled hole lithology automatic layering algorithm.