In order to improve the safety needs of personnel in the dark environment under the well, this article adopts the improved YOLOV8 algorithm combined with the ray method to determine whether underground personnel are entering dangerous areas and to provide early warning. First of all, this article introduces the coordinate attention mechanism on the basis of YOLOV8 target detection so that the model pays attention to the location information of the target area so as to improve the detection accuracy of obstruction and small target areas. In addition, the Soft-Non-Maximum Suppression (SNMS) module is introduced to further improve accuracy. The improved model is then combined with the ray method to be deployed and applied under a variety of angles and different scenic information cameras. The experimental results show that the proposed method obtains 99.5% of the identification accuracy and a frame speed of 45 Frames Per Second (FPS) on the self-built dataset. Compared with the YOLOV8 model, it has a higher accuracy and can effectively cope with the changes and interference factors in the underground environment. Further, it meets the requirements for real-time testing in dangerous underground areas.