## 3 Methodology
### Self-Checking for Perspective-\(n\)-Point  
Resulting from a maximum likelihood estimation of \(C_{\rm s}\), the residual \(\varepsilon_{i,j}\) can be used to evaluate the quality of model fit. Let \({}^{\prime}\!E\) be similar to the root-mean-square error (RMSE), and expressed as  
\[lo=\frac{1}{2r+1}\sqrt{\sum_{i=-r}^{+r}\sum_{j=-r}^{+r}\left(\varepsilon_{i,j} \right)^{2}}. \tag{11}\]  
Figure 3: Function curve plots of (**a**): \(y=\mathrm{erf}(x)\) (dashed), \(y=\tanh(\varrho x)\) (solid), and (**b**): \(y=\tanh(\varrho x)-\mathrm{erf}(x)\). The coefficient \(\rho\) is set to 1.0 (red), 1.1 (purple), and 1.2 (green). Figure 2: Gray images simulated by the ideal model, approximated model, and \(\Delta(u,v)\), with different values of \(\theta_{1}\) and \(\theta_{2}\). The image size is \(41\times 41\) pixels, \(\sigma=4\). The factor \(\dot{{}^{\prime}E}\) is slightly and unavoidably affected by the lens distortions and image noise, but remarkable when there is a great deal of light pollution (or imbalanced illumination) brought into a chessboard image, which often happens in on-site applications. Thus, it can also be considered as a metric to reflect the reliability of sub-pixel localization. In order to achieve a self-checking technique for perspective-n-point, boxplot analysis is more appropriate than conventional means, e.g., 3-sigma rule [29]. The boxplot distinguishes outliers using quantiles (Figure 4), rather than depending on a prior knowledge about the distribution of actual dataset and, therefore, it has a higher flexibility. It is assumed that a chessboard image is detected with an array of sub-pixel corners (the array size is \(M\times N\)). Using Equation (11) gives a corresponding metric \(\dot{{}^{\prime}E}_{m,n}\) for the corner \(c_{m,n}=[u_{m,n}\ v_{m,n}]\), \(m\in\{1,\ldots,M\}\), \(n\in\{1,\ldots,N\}\). As illustrated in Figure 4, since the quantiles \(\mathrm{Q}_{1}\) and \(\mathrm{Q}_{3}\) are obtained by investigating all the metrics, the factor \(w_{m,n}\), standing for the reliability of \(\mathbf{c}_{m,n}\), is then determined:  
\[w_{m,n}=\left\{ \begin{array}{rl}1&\text{if }Io_{m,n}\in\left[\ \ 2.5\mathrm{Q}_{1}- 1.5\mathrm{Q}_{3}\ \ \ 2.5\mathrm{Q}_{3}-1.5\mathrm{Q}_{1}\ \right]\\ 0&\text{otherwise}\end{array} \right.. \tag{12}\]  
Perspective-n-point is the problem of estimating a 3-D rotation \(\mathbf{r}\) and a translation \(\mathbf{t}\) of a calibrated camera, with respect to the world frame. Since the chessboard mentioned above is defined in the world frame accurately, 3-D points in it and their corresponding image points follow a pin-hole model for the camera [2]:  
\[s_{m,n}\mathbf{u}_{m,n}=\mathbf{rq}_{m,n}+\mathbf{t},\text{ with }\mathbf{n}_{m,n}=\left[ \begin{array}{ c c c}\frac{u_{m,n}-u_{0}}{f_{\mathrm{x}}}&\frac{v_{m,n}-v_{0}}{f_{\mathrm{y}}} &1\end{array} \right]^{\mathrm{T}}, \tag{13}\]  
where \(\mathbf{q}_{m,n}\) is the (\(m\), \(n\))th 3-D point and \(s_{m,n}\) the corresponding scale factor. \(f_{\mathrm{x}}\) and \(f_{\mathrm{y}}\) are the scaled focal lengths, \([u_{0}\ v_{0}]\) is the principal point. An optimal solution of \(s_{m,n}\) is related to the given \(\mathbf{r}\) and \(\mathbf{t}\) via  
\[s_{m,n}=\left(\mathbf{u}_{m,n}{}^{\mathrm{T}}\mathbf{u}_{m,n}\right)^{-1}\mathbf{u}_{m,n} {}^{\mathrm{T}}\big{(}\mathbf{rq}_{m,n}+\mathbf{t}\big{)}. \tag{14}\]  
Figure 4: Boxplot with respect to a probability density function of \(N(0,\sigma^{2})\). Considering \(w_{m,n}\) as the penalty factor in association with the above estimator yields  
\[\underset{\mathbf{r,t}}{\text{argmin}}\Bigg{\{}\sum_{m=1}^{M}\sum_{n=1}^{N}\left\|w_{ m,n}\right[\left(n_{m,n}{}^{\text{T}}n_{m,n}\right)^{-1}n_{m,n}n_{m,n}{}^{\text{T}}-I \left](rq_{m,n}+t)\right\|^{2}\Bigg{\}}. \tag{15}\]  
Rodrigues parameters, instead of Euler rotations, are recommended for simplifying the above optimization [30].