Gas explosions threaten the safety of underground coal mining. Mining companies use drilling rigs to extract the gas to reduce its concentration. Drainage depth is a key indicator of gas drainage; accidents will be caused by going too deep. Since each drill pipe has the same length, the actual extraction depth is equivalent to the number of drill pipes multiplied by the length of a single drill pipe. Unnecessary labor is consumed and low precision is achieved by manual counting. Therefore, the drill pipe counting method of YOLOv7-GFCA target detection is proposed, and the counting is realized by detecting the movement trajectory of the drilling machine in the video. First, Lightweight GhostNetV2 is used as the feature extraction network of the model to improve the detection speed. Second, the (Fasternet-Coordinate-Attention) FCA network is fused into a feature fusion network, which improves the expression ability of the rig in complex backgrounds such as coal dust and strong light. Finally, Normalized Gaussian Wasserstein Distance (NWD) loss function is used to improve rig positioning accuracy. The experimental results show that the improved algorithm reaches 99.5%, the model parameters are reduced by 2.325 × 106, the weight file size is reduced by 17.8 M, and the detection speed reaches 80 frames per second. The movement trajectory of the drilling rig target can be accurately obtained by YOLOv7-GFCA, and the number of drill pipes can be obtained through coordinate signal filtering. The accuracy of drill pipe counting reaches 99.8%, thus verifying the feasibility and practicability of the method.