# Visual Ranging Based on Object Detection Bounding Box Optimization
## 3 Methods
### Similar Triangle Ranging Method Based on Height Difference  
The monocular visual ranging method, PNP ranging method, imaging model method, and data regression modeling method have limitations in practical application due to their high time and manpower costs, and inability to measure objects of unknown size. Therefore, a similar triangle distance measurement method based on height difference is proposed in this paper. The method measures the distance to an object of unknown size by adjusting the height difference of the camera. Figure 3 shows shooting scenes at different heights, and Figure 4 shows a geometric model built at one height of the camera. Figure 3 shows the shooting scene of the camera at O\({}^{\prime}\) and O\({}^{\prime\prime}\). The pitch angle is \(\alpha\), and the height difference adjusted by the camera O\({}^{\prime}\)O\({}^{\prime\prime}\) = h. Figure 4 shows the ranging model established by the camera at O\({}^{\prime}\) (or O\({}^{\prime\prime}\)). The focal length of the camera is OIO\({}^{\prime}\) = f; O\({}^{\prime}\)M is the camera optical axis; XOY is the world coordinate system; X\({}_{1}\)O\({}_{1}\)Y\({}_{1}\) is the image coordinate system, where AB is the object width and P (P\({}_{X}\), P\({}_{Y}\)) is the midpoint of AB. A\({}_{1}\), B\({}_{1}\) and P\({}_{1}\) are the corresponding points of A, B and P in the imaging plane. O\({}^{\prime}\)P(O\({}^{\prime\prime}\)P) is the distance of the camera from O\({}^{\prime}\)(O\({}^{\prime\prime}\)) to the object. The solution steps are as follows:  
Figure 3: Camera shooting scene. First, suppose the vertical height of the camera at O\({}^{\prime}\) point is h\({}_{1}\), and the vertical height at O\({}^{\prime\prime}\) point is h\({}_{2}\), then h = h\({}_{2}-\) h\({}_{1}\). We then suppose that the actual width of the object is AB = W, the width of the pixel shot at O\({}^{\prime}\) point is w\({}_{1}\), and the width of the pixel shot at O\({}^{\prime\prime}\) point is w\({}_{2}\). The ranging model established by the camera at O\({}^{\prime}\) point is as follows:  
\[\gamma_{1}=\arctan\frac{\mathrm{O}_{1}\mathrm{P}_{1Y}}{\mathrm{f}}, \tag{6}\]  
\[\beta=\left\{ \begin{array}{c}\alpha+\gamma,\;\mathrm{P}_{1Y}<0\\ \alpha,\;\mathrm{P}_{1Y}=0\\ \alpha-\gamma,\;\mathrm{P}_{1Y}>0\end{array} \right\}, \tag{7}\]  
\[\mathrm{O}^{\prime}\mathrm{P}_{Y}=\frac{\mathrm{h}_{1}}{\sin\beta}, \tag{8}\]  
\[\mathrm{O}^{\prime}\mathrm{P}_{1Y}=\sqrt{\mathrm{O}_{1}\mathrm{P}_{1Y}{}^{2}+ \hat{F}^{2}}, \tag{9}\]  
\[\mathrm{O}^{\prime}\mathrm{P}_{1}=\sqrt{\mathrm{O}_{1}\mathrm{P}_{1}{}^{2}+ \hat{F}^{2}}, \tag{10}\]  
From triangle O\({}^{\prime}\)P\({}_{1}\)P\({}_{1Y}\) similar to triangle O\({}^{\prime}\)PP\({}_{Y}\), we obtain:  
\[\frac{\mathrm{O}^{\prime}\mathrm{P}_{1}}{\mathrm{O}^{\prime}\mathrm{P}}=\frac {\mathrm{O}^{\prime}\mathrm{P}_{1Y}}{\mathrm{O}^{\prime}\mathrm{P}_{Y}}=\frac {\sqrt{\mathrm{O}_{1}\mathrm{P}_{1Y}{}^{2}+\hat{F}^{2}}}{\mathrm{h}_{1}} \times\sin\beta_{1}, \tag{11}\]  
From triangle O\({}^{\prime}\)AB similar to triangle O\({}^{\prime}\)A\({}_{1}\)B\({}_{1}\), we obtain:  
\[\frac{\mathrm{O}^{\prime}\mathrm{P}_{1}}{\mathrm{O}^{\prime}\mathrm{P}}=\frac {\mathrm{A}_{1}\mathrm{B}_{1}}{\mathrm{AB}}=\frac{\mathrm{w}_{1}}{\mathrm{W}}, \tag{12}\]  
According to Formulas (11) and (12), we can obtain:  
\[\frac{\mathrm{w}_{1}}{\mathrm{W}}=\frac{\sqrt{\mathrm{O}_{1}\mathrm{P}_{1Y}{} ^{2}+\hat{F}^{2}}}{\mathrm{h}_{1}}\times\sin\beta_{1}. \tag{13}\]  
Figure 4: Visual ranging model. Similarly, when the camera is at O\({}^{\prime\prime}\) point, we obtain:  
\[\frac{\mathrm{w}_{2}}{\mathrm{W}}=\frac{\sqrt{\mathrm{O}_{2}\mathrm{P}_{2}\mathrm{ r}^{2}+\hat{\mathrm{f}}^{2}}}{\mathrm{h}_{2}}\times\sin\beta_{2}. \tag{14}\]  
With the known condition \(\mathrm{h}_{2}-\mathrm{h}_{1}=\mathrm{h}\), the parallel vertical Formulas (13) and (14) can be used to find the three unknown variables \(\mathrm{h}_{1}\), \(\mathrm{h}_{2}\) and \(\mathrm{W}\):  
\[\left\{