## 3 Drill Pipe Counting Method Based on YOLOV7-GFCA Network
### More Precise Loss Function  
The position loss function is represented the ratio between the predicted box \(A\) of the rig chuck and the manually marked real box \(B\) by Equation (11).  
\[IOULoss=1-\frac{\left|A\cap B\right|}{A\cup B} \tag{11}\]  
The smaller the ratio of the two, the more accurate the position prediction of the drill chuck. However, the \(IOU\) is sensitive to the configuration deviation of the detection frame with a small object, and the anchor frame may be flipped, which leads to difficulty in network convergence and reduces the detection performance.  
A new metric, NWD [23] (Normalized Wasserstein Distance), is introduced to replace the \(IOU\) metric for measuring the similarity between two bounding boxes. First, denote the bounding box \(R=(C_{x},C_{y},W,H)\),\((C_{x},C_{y})\) is the center coordinates, \(W,H\) are width and height, respectively. Then, calculate the ellipse equation inscribed in the bounding box of the drilling rig, which can be expressed as Equation (12).  
\[\frac{(x-\mu_{x})^{2}}{\xi^{2}{}_{x}}+\frac{(y-\mu_{y})^{2}}{\xi^{2}{}_{y}}=1 \tag{12}\]  
where \((\mu_{x},\mu_{y})\) is the coordinates of the center point of the ellipse; and \((\xi_{x},\xi_{y})\) is the length of the semi-axis of the ellipse. Equation (13) is the probability density function of the two-dimensional Gaussian distribution.  
\[f(\mathrm{x}|\mu,\sum)=\frac{\exp(-\frac{1}{2}(\mathrm{x}-\mu)^{\mathrm{T}} \sum^{-1}(\mathrm{x}-\mu))}{2\pi|\sum^{\frac{1}{2}}} \tag{13}\]  
where x is coordinate \((x,y)\)--it is a two-dimensional vector; \(\mu\) is the mean vector; and \(\sum\) is the covariance matrix of Gaussian distribution  
\[(\mathrm{x}-\mu)^{\mathrm{T}}\sum^{-1}(\mathrm{x}-\mu)=1 \tag{14}\]  
When the conditions of Equation (14) are satisfied, the ellipse in Equation (12) will be the density profile of the two-dimensional Gaussian distribution with  
\[\mu=\left[\begin{array}{c}C_{x}\\ C_{y}\end{array}\right],\sum=\left[\begin{array}{cc}\frac{W^{2}}{4}&0\\ 0&\frac{H^{2}}{4}\end{array}\right]\]Therefore, we can convert the target box and detection box into the similarity between two Gaussian distributions, and Wasserstein distance between target box \(A\) and detection box \(B\) is calculated by Equation (15).  
\[W_{2}^{2}(N_{A},N_{B})=\left\|\mu_{a}-\mu_{b}\right\|_{2}^{2}+\left\|\sum_{a}^{1 /2}-\sum_{b}^{1/2}\right\|_{F}^{2} \tag{15}\]  
where \(\left\|\cdot\right\|_{F}\) is Frobenius norm; \(\mu\) is the mean vector; and \(\sum\) is the covariance matrix. \(W_{2}^{2}\) is the degree of similarity between two distributions.  
But \(W_{2}^{2}\) is a distance measure, which cannot directly measure the similarity between the target frame and the candidate frame, and is further converted into the normalized _NWD_ distance in Equation (16).  
\[NWD(N_{A},N_{B})=\exp(-\frac{\sqrt{W_{2}^{2}(N_{A},N_{B})}}{C}) \tag{16}\]  
Aiming at the target of underground drilling rigs in coal mines, in order to reduce the loss of coordinates caused by the vibration of drilling rigs, the _NWD_ measurement method is used to effectively replace the _IOU_ measurement method.  
The similarity between the target frame and the detection frame is effectively measured by this measurement method, contributing to the enhancement of the positioning accuracy of the drilling rig.