# An Accurate, Efficient, and Stable Perspective-n-Point Algorithm in 3D Space
## 3 Experiments and Analysis  
### Testbed and Test Synthesis Data Generation  
This section describes the Matlab simulation experiments conducted on Hidden PnP and the existing classical PnP algorithm, based on synthetic data, in terms of solving accuracy, anti-noise ability, and operational efficiency. The experimental results are compared and analyzed. The PnP algorithms involved in the comparison were LHM, EPnP+GN, RPnP, DLS, OPnP, SRPnP, RDLT, and ASPnP, etc. The simulation experiment was completed on a 4-core CPU model i5-4200H notebook with the main frequency of 2.80 GHz and a running memory of 8 G.  
A virtual camera, with an image size of 640 \(\times\) 480 pixels and a focal length of 800 pixels, was constructed on the Matlab platform. When generating random 3D reference points, the matrix composed of 3D reference points was set as \(Q=[q_{1}^{w},q_{2}^{w},q_{3}^{w},\cdots,q_{n}^{w},]^{T}\), as the solving accuracy of PnP algorithm was affected by the distribution of 3D spatial points, so as to reasonably test the solving accuracy of each PnP algorithm. According to the different rank of the matrix \(Q^{T}Q\), the following three situations could be selected to randomly generate 3D reference points:  
(1) Ordinary 3D: rank(\(Q^{T}Q\)) = 3, in which 3D reference points were randomly generated within the range of [\(-\)2,2] \(\times\) [\(-\)2,2] \(\times\) [4,8]. In this case, the minimum eigenvalue was almost close to 0. (2) Planar Case: rank(\(Q^{T}Q\)) = 2 in which 3D reference points were randomly generated within the range of [\(-\)2,2] \(\times\) [\(-\)2,2] \(\times\) [0,0]. In this case, all reference points were on the same plane. (3) Quasi-Singular: rank(\(Q^{T}Q\)) = 3, in which 3D reference points were randomly generated within the range of [1,2] \(\times\) [1,2] \(\times\) [4,8], and the ratio of the minimum eigenvalue to the maximum eigenvalue was less than 0.05. After generating the above initial 3D spatial reference points, a rotation matrix and a translation vector were first generated randomly as the truth values of the simulation experiment, which were respectively \(R_{ture}\) and \(T_{ture}\). Secondly, the generated 3D spatial reference points were converted from the camera coordinate system to the world coordinate system. Finally, different PnP algorithms were adopted to convert the reference points in the world coordinate system, obtained in the previous step, to the image plane, and, thus, obtaining the estimated rotation matrix \(R_{est}\) and translation vector \(T_{est}\). In order to be consistent with the definition of evaluation error in existing literature, this paper adopted the definition of error in [17]:  
\[e_{rot}(degree)=\max_{k\in{1,2,3}}cos^{-1}(r_{k,true}^{T}r_{kest}^{T})\times 180 /\pi \tag{25}\]  
\[e_{rot}(\%)=\frac{\parallel t_{est}-t_{true}\parallel}{\parallel t_{true} \parallel}\times 100 \tag{26}\]  
The performance of PnP algorithm was certainly immune from the definitions adopted. Comparative Simulation Test of the Calculation Accuracy of PnP Methods under Different Circumstances  
In this section, the method described in the previous section was adopted to generate 4 to 20 3D spatial reference points under the cases of Ordinary 3D, Planar Case, and Quasi-Singular, respectively, which served as the experimental input data of the PnP algorithm to be tested. At the same time, zero-mean Gauss noise, with a size of \(\delta\) = 2 pixels, was added to the test image. In the test, each PnP algorithm was independently tested 500 times under a fixed number of 3D reference points. Due to the large number of algorithms and the data, the following graph could only be used for macroscopic performance comparison, and readers can refer to Appendix A (Tables A1-A3) for the specific test data. Figures 3-5 show the comparison of the mean errors (a,c) and median errors (b,d) of the rotation matrix and the translation vector in the Ordinary 3D, Planar, and Quasi-Singular cases, respectively, with spatial reference points \(n\) ranging from 4 to 20, and \(\delta\) = 2.